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 from MacOS #64

Open
aidangilmore opened this issue Oct 30, 2019 · 5 comments
Open

Cross-compiling from MacOS #64

aidangilmore opened this issue Oct 30, 2019 · 5 comments

Comments

@aidangilmore
Copy link

Is there a way that I could build a statically-linked Linux from Nix on MacOS?

Thanks

@nh2
Copy link
Owner

nh2 commented Oct 31, 2019

Hey,

not yet, because to my knowledge GHC and Cabal do not have the necessary cross-compiling support for that yet.

But @Ericson2314 is working on that so it may work in the not-too-far future.

@Ericson2314
Copy link

Ericson2314 commented Oct 31, 2019

Does

nix-build '<nixpkgs>' --arg crossSystem '{ config = "x86_64-unknown-linux-musl"; useLLVM = true; }' -A hello

work? I don't remember any Haskell-specific issues, but could easily be forgetting things. Maybe @angerman knows?

@aidangilmore
Copy link
Author

I can confirm that cross-compiling hello on Darwin works as expected. How would I tweak my default.nix to use cross compiling with static-stack2nix-builder?

@nh2
Copy link
Owner

nh2 commented Nov 8, 2019

I'm not sure!

If anybody knows, please chime in. I haven't tried to cross-compile static Haskell exes myself yet, so any contributions or insights would be appreciated.

I gave a super quick shot at passing config = "x86_64-unknown-linux-musl"; useLLVM = true; directly to nixpkgs imports, but that currently gets an infinite recursion problem.

@angerman
Copy link

angerman commented Nov 8, 2019

static muslc is a special case on Linux. The special part is that you can natively run the muslc executable. This makes issues like TH and others (e.g. you can have a proper stage2 compiler) go away. If you want macOS as a build host you now need some form of executing haskell Linux binaries at compile time (if you want comprehensive compilation capabilities). We can do this for windows with WINE. For macOS there are a few projects that promise a Linux execution layer (e.g. the noah project). But last I checked (for macOS -> Linux cross compilation), it needed substantial patching and even then didn’t support enough Linux to make the programs run.

Even if they run, making sure they behave sufficiently similar is another issue.

What you could do is use vbox to start up a virtual Linux machine and delegate all cl pipe time requirements to that. Or use the splice dumping/loading approach that zeroTH/evil-splicer and obsidian.systems do to get macOS -> Linux cross compilation. Is it worth it? I can’t tell. Would it be cool to have? Absolutely!

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

No branches or pull requests

4 participants