Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Building LLVM on mac-arm64 #1092

Merged
merged 12 commits into from
Oct 22, 2021
Merged

Building LLVM on mac-arm64 #1092

merged 12 commits into from
Oct 22, 2021

Conversation

oxisto
Copy link
Contributor

@oxisto oxisto commented Oct 16, 2021

First attempt to build LLVM on mac-arm64. Not sure, if I understood the profile system correctly.

Closes #1091

@saudet
Copy link
Member

saudet commented Oct 17, 2021

Yes, the profiles need to be updated too. It's essentially the same as I did for JavaCPP itself in commit bytedeco/javacpp@87a6194.

@oxisto
Copy link
Contributor Author

oxisto commented Oct 17, 2021

@saudet I might need your help on this one. I think I got the profiles correct now.

Do I need to change

macosx-*)
$CMAKE -S ../llvm -B $LLVM_BUILD -DLLVM_CCACHE_BUILD=ON -DCMAKE_EXE_LINKER_FLAGS='-Wl,-rpath,@loader_path/' -DCMAKE_INSTALL_PREFIX=$INSTALL_PATH -DLLVM_BUILD_LLVM_DYLIB=ON -DLLVM_LINK_LLVM_DYLIB=ON -DCMAKE_BUILD_TYPE=Release -DLLVM_TARGETS_TO_BUILD=all -DLLVM_ENABLE_LIBXML2=OFF -DLLVM_INCLUDE_TESTS=OFF -DLLVM_ENABLE_PROJECTS="$PROJECTS"
make -C $LLVM_BUILD -j $MAKEJ
make -C $LLVM_BUILD install > /dev/null
cp $INSTALL_PATH/lib/LLVMPolly.so $INSTALL_PATH/lib/libLLVMPolly.so
;;
this as well to split it up and pass -arch or is this taken care of on another level?

@oxisto
Copy link
Contributor Author

oxisto commented Oct 17, 2021

@saudet I might need your help on this one. I think I got the profiles correct now.

Do I need to change

macosx-*)
$CMAKE -S ../llvm -B $LLVM_BUILD -DLLVM_CCACHE_BUILD=ON -DCMAKE_EXE_LINKER_FLAGS='-Wl,-rpath,@loader_path/' -DCMAKE_INSTALL_PREFIX=$INSTALL_PATH -DLLVM_BUILD_LLVM_DYLIB=ON -DLLVM_LINK_LLVM_DYLIB=ON -DCMAKE_BUILD_TYPE=Release -DLLVM_TARGETS_TO_BUILD=all -DLLVM_ENABLE_LIBXML2=OFF -DLLVM_INCLUDE_TESTS=OFF -DLLVM_ENABLE_PROJECTS="$PROJECTS"
make -C $LLVM_BUILD -j $MAKEJ
make -C $LLVM_BUILD install > /dev/null
cp $INSTALL_PATH/lib/LLVMPolly.so $INSTALL_PATH/lib/libLLVMPolly.so
;;

this as well to split it up and pass -arch or is this taken care of on another level?

I think I got now. Should hopefully run now.

cppbuild.sh Show resolved Hide resolved
@saudet
Copy link
Member

saudet commented Oct 18, 2021

At first glance, that looks alright, thanks!

For consistency though, let's add the macosx-arm64 lines before the ones for macosx-x86_64.

@oxisto
Copy link
Contributor Author

oxisto commented Oct 18, 2021

At first glance, that looks alright, thanks!

For consistency though, let's add the macosx-arm64 lines before the ones for macosx-x86_64.

I can switch that, no problem.

There seems to be a build error on llvm when building for arm64 though :(

/bin/sh: ../../../../bin/clang-tblgen: Bad CPU type in executable
7079
[  8%] Building arm_cde.h...
7080
make[2]: *** [tools/clang/lib/Headers/arm_bf16.h] Error 126
7081
make[2]: *** Waiting for unfinished jobs....
7082
[INFO] ------------------------------------------------------------------------
7083
/bin/sh: ../../../../bin/clang-tblgen: Bad CPU type in executable

It looks like the target is still x86 :(

-- LLVM default target triple: x86_64-apple-darwin20.6.0
1923

@saudet
Copy link
Member

saudet commented Oct 18, 2021

Since we're cross compiling, we need to prebuild those tools for x86_64 first, as with linux-arm64:
https://github.com/bytedeco/javacpp-presets/blob/master/llvm/cppbuild.sh#L62-L75

@oxisto
Copy link
Contributor Author

oxisto commented Oct 18, 2021

Since we're cross compiling, we need to prebuild those tools for x86_64 first, as with linux-arm64:
https://github.com/bytedeco/javacpp-presets/blob/master/llvm/cppbuild.sh#L62-L75

I added that step as well now and things seem to look good now on my x86 test machine.

@oxisto
Copy link
Contributor Author

oxisto commented Oct 19, 2021

I am a bit lost why this still fails. It works fine on my Mac mini x86, it produces an arm64 binar without any errors.

@saudet
Copy link
Member

saudet commented Oct 20, 2021

Those binaries need to be built for x86_64, not arm64. Maybe your version of Mac comes with an emulator for arm64 binaries, but that's not the case of the machines running for GitHub Actions.

@oxisto
Copy link
Contributor Author

oxisto commented Oct 20, 2021

Those binaries need to be built for x86_64, not arm64. Maybe your version of Mac comes with an emulator for arm64 binaries, but that's not the case of the machines running for GitHub Actions.

What was confusing me is that for the linux-arm64 example you referred my to the target triple and target arch was set to arm64, not x86_64.

@oxisto
Copy link
Contributor Author

oxisto commented Oct 20, 2021

Looks like this finally compiled 🥳 As @saudet suggested, I will move the arm64 entries before the x86_64 ones - any other cleanup wanted? Is there any way to actually retrieve the build artefacts and check if they are in fact arm64?

@saudet
Copy link
Member

saudet commented Oct 20, 2021

After this gets merged, the snapshots will be available for download: http://bytedeco.org/builds/

Before we do that though, there are still a lot of places where arm64 is still after x86_64. Please update everything!

@oxisto
Copy link
Contributor Author

oxisto commented Oct 21, 2021

After this gets merged, the snapshots will be available for download: http://bytedeco.org/builds/

Before we do that though, there are still a lot of places where arm64 is still after x86_64. Please update everything!

I was following the style of the individual files. For example in the cppbuild.sh, x86_64 was already placed before arm64 for Linux. Should I fix these already existing inconsistencies as well?

@saudet
Copy link
Member

saudet commented Oct 21, 2021

Right, some places have been a bit off like that, but don't worry about those. Just do the mac ones "right". Thanks!

@saudet saudet merged commit 80d0be3 into bytedeco:master Oct 22, 2021
@oxisto oxisto deleted the llvm-mac-arm64 branch October 23, 2021 09:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Shipping LLVM native libraries on mac/arm64
2 participants