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

Cross-compiling LLVM fails because llvm-tblgen must be run. #39170

Closed
TravisWhitaker opened this issue Apr 19, 2018 · 9 comments
Closed

Cross-compiling LLVM fails because llvm-tblgen must be run. #39170

TravisWhitaker opened this issue Apr 19, 2018 · 9 comments
Labels
6.topic: cross-compilation Building packages on a different platform than they will be used on 6.topic: llvm/clang Issues related to llvmPackages, clangStdenv and related

Comments

@TravisWhitaker
Copy link
Contributor

Issue description

Cross-compiling LLVM for aarch64 like so(with nixpkgs HEAD):

$ nix-build -E "with import ./default.nix {crossSystem = (import ./lib).systems.examples.aarch64-multiplatform;}; llvmPackages.llvm"

Eventually fails with

/nix/store/xn5gv3lpfy91yvfy9b0i7klfcxh9xskz-bash-4.4-p19/bin/bash: ../../../bin/llvm-tblgen: cannot execute binary file: Exec format error

Seems we need to use the host'sllvm-tblgen when cross compiling.

Steps to reproduce

nix-build -E "with import ./default.nix {crossSystem = (import ./lib).systems.examples.aarch64-multiplatform;}; llvmPackages.llvm"

@matthewbauer
Copy link
Member

Related: #36867

@TravisWhitaker
Copy link
Contributor Author

Also related: #33353

Got here by trying to cross-compile GHC.

@dtzWill
Copy link
Member

dtzWill commented Apr 19, 2018

Bah, yes this is a pain. cc @Ericson2314 @bgamari etc.

I'll check back later but for now consider searching the PR/issue history-- this has been discussed and a few workarounds of varying quality have been proposed along the way.

Maybe this will be the final motivation to polish one of those efforts and merge it! :)

One example, IIRC, can be found in some of the earlier "versions" of my big musl PR. LMK if you have questions or can't find what I mean. Hopefully I'm remembering correctly :D.

#34645

@dtzWill
Copy link
Member

dtzWill commented Apr 25, 2018

Sorry for the delay.

I know I've approached this a few ways-- here's one that might have useful bits (this branch was never meant to be public, but just pushed in case useful... apologies for hackery and such O:))

https://github.com/dtzWill/nixpkgs/commits/experimental/cross-llvm

Relevant to this issue in particular, it tries to avoid having to do full builds of LLVM on the buildPlatform just to get the tables generated for the LLVM you care about-- in particular, introduces special derivations that build just tablegen. I also added a dummy llvm-config-- which actually I think was explored in Nixpkgs at some point? Not sure.

Anyway hope this helps, LMK if you have any questions.

@Ericson2314
Copy link
Member

If we can do that branch simultaneous with #36867 (build == host == target) LLVM, I'll be very very happy :).

@TravisWhitaker
Copy link
Contributor Author

I ended up getting around this by just passing in the host's LLVM and depending on it when buildPlatform != targetPlatform.

@dtzWill is it really that bad to depend on the host's complete LLVM? It'll typically be in the binary cache, right?

@dtzWill
Copy link
Member

dtzWill commented May 1, 2018

It seems better than not working at all, that's for sure! :)

@TravisWhitaker
Copy link
Contributor Author

This works for me: TravisWhitaker@50a647e

Although, I'm not sure this is the "right" way to build a cross-compile-friendly package, and maybe the "right" way to do it is changing in light of the work you guys are doing right now.

@c0bw3b c0bw3b added the 6.topic: cross-compilation Building packages on a different platform than they will be used on label Nov 21, 2018
@Mic92
Copy link
Member

Mic92 commented Dec 19, 2018

This was fixed in #52031
However you will still have a problem, when your buildsystem relies on llvm-config.

@Mic92 Mic92 closed this as completed Dec 19, 2018
@rrbutani rrbutani added the 6.topic: llvm/clang Issues related to llvmPackages, clangStdenv and related label May 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
6.topic: cross-compilation Building packages on a different platform than they will be used on 6.topic: llvm/clang Issues related to llvmPackages, clangStdenv and related
Projects
None yet
Development

No branches or pull requests

7 participants