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

[question] How to build LLVM toolchain for the NDK locally for Windows x86_64. #1386

Closed
arpit07531 opened this issue Dec 4, 2020 · 2 comments
Labels

Comments

@arpit07531
Copy link

arpit07531 commented Dec 4, 2020

Background

We want to port the following fix from the upstream LLVM to our NDK r21, as we are getting build failures because of this bug.
https://reviews.llvm.org/D83772

We use NDK r21 release on windows 10 64 bit machines for development. I want to sync to the LLVM source code corresponding to NDK r21 release, apply the above fix, generate binaries for Windows, and replace the clang++.exe front end binary in our NDK with the locally generated one. I want to just update the clang++.exe binary instead of updating the whole NDK toolchain, because we build multiple apps using the same toolchain, and it takes a lot of effort and testing for upgrading the NDK. And also this fix is not yet ported to the LLVM-project repository of the NDK.

Current clang version in the toolchain :

>clang++.exe --version
Android (6317467 based on r365631c1) clang version 9.0.8 (https://android.googlesource.com/toolchain/llvm-project e0caee08e5f09b374a27a676d04978c81fcb1928) (based on LLVM 9.0.8svn)
Target: x86_64-w64-windows-gnu
Thread model: posix
InstalledDir: D:\bin

Steps that I am following :

  • git clone https://android.googlesource.com/toolchain/llvm-project

  • git checkout e0caee08e5f09b374a27a676d04978c81fcb1928

  • Make the source change - as per https://reviews.llvm.org/D83772

  • cmake -G "Visual Studio 15 2017" -A x64 -Thost=x64 -DLLVM_ENABLE_PROJECTS="clang" -DPYTHON_HOME=C:\python38 e:\tmp\llvm-project-ndk\llvm-project\llvm

  • Open LLVM.sln in Visual studio and build x64 release for clang.

Using the above steps I am able to generate clang++.exe binary successfully.

>clang++.exe --version
clang version 9.0.0 (https://android.googlesource.com/toolchain/llvm-project e0caee08e5f09b374a27a676d04978c81fcb1928)
Target: x86_64-pc-windows-msvc
Thread model: posix
InstalledDir: E:\tmp\llvm-project-ndk\build2\Release\bin

Problem

I am a little doubtful whether this locally generated clang++.exe binary is compatible with the rest of the toolchain, and whether it has all the fixes that are there in r21 release because I am seeing the following discrepancies in the binary.

  • clang++.exe --version shows the version of this binary as 9.0.0, while the one in r21 release shows the version as 9.0.8

  • clang++.exe --version shows the Target as x86_64-pc-windows-msvc, while the original r21 release binary shows target as x86_64-w64-windows-gnu

  • Size of the NDK r21 release clang++.exe binary is 66,419 KB, while that of my locally generated binary is 69325 KB.

  • In the r21 release clang++.exe references the default headers from directory - ../lib64/clang/9.0.8/include while the locally generated binary references headers from ../lib/clang/9.0.0/include. Even if I ignore the difference in the path of the includes, there are slight differences in the headers generated on my machine, and the ones that ship with NDK release. So I am really doubtful whether I should use the NDK shipped headers or the new ones generated in my build even if I take care of the includes path.

Questions

  • Are the Windows LLVM binaries in NDK built on Windows with msvc or on windows with mingw or cross compiled on Linux? Also how can I get the target type of the binary to match - x86_64-w64-windows-gnu. Can someone please share the exact build steps to generate LLVM toolchain for the NDK release for Windows x86-64 locally. I hope it should fix the includes path issue also.

  • How can I sync to the LLVM source code that is built into the r21 release. If I try to match the commit hash, I get the binary of version 9.0.0, while the one in NDK r21 release is 9.0.8.

  • If somehow it's not possible to generate a local build without introducing new issues, As an option of last resort is it possible for the NDK team to trigger a build in the build machines with this fix and share a drop? We are really blocked on this issue and need to somehow work around this quickly.

I will highly appreciate any help.

@pirama-arumuga-nainar
Copy link
Collaborator

We cross-compile the Windows clang from Linux. Here are the instructions that should work.

$ mkdir llvm-toolchain && cd llvm-toolchain
$ repo init -u https://android.googlesource.com/platform/manifest -b llvm-toolchain
$ cp $NDK_CLANG_PATH/manifest_6317467.xml .repo/manifests
$ repo init -u manifest_6317467.xml
$ repo sync -c

# cherry-pick necessary patch into toolchain/llvm-project

$ python toolchain/llvm_android/build.py --no-build=linux

The built clang++.exe would be in out/install/windows-x86/clang-dev/bin.

PS: These instructions are partially from here. It's just missing the part about copying the manifest. We'll get the docs updated.

@arpit07531
Copy link
Author

@pirama-arumuga-nainar Thanks a lot. I have got a perfectly working binary of exactly same size and signature using these instructions. These instructions worked like a charm. :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants