-
Notifications
You must be signed in to change notification settings - Fork 5
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
Add support for cross-compilation with Nix #44
base: master
Are you sure you want to change the base?
Changes from 4 commits
71c6555
3820899
2c205d4
f3995bd
f32b194
08fa95c
2725c68
814b4cc
51ce5b4
fb64207
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,6 +29,15 @@ Run `./build.sh`* to build. The first time you run this, it could take a while, | |
|
||
\* On Windows, it's `.\build.ps1`. Though you may need `powershell.exe -executionpolicy bypass -file .\build.ps1` due to permissions issues. I don't personally know a thing about Windows permissions, so if anyone has a better idea please let me know. | ||
|
||
## Cross-compiling | ||
|
||
If we're on x86-64 Linux, we can use `nix develop` to enter a shell from which we can cross-compile: | ||
```sh | ||
~/.ghcup/bin/runghc Build.hs --target=x86_64-w64-mingw32 | ||
~/.ghcup/bin/runghc Build.hs --target=x86_64-unknown-linux-musl | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This works, but isn't actually useful without passing some extra flags, since Again, this is a drawback of the shell-based approach. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. On the other hand I assume the issue is getting hold of a statically-linked If this is a real sticking point, we could somehow (separate branch, or Nix-based override) compile without It's possible that my Haskell There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We have static musl builds working now, after providing a static libevdev. |
||
~/.ghcup/bin/runghc Build.hs --target=aarch64-unknown-linux-gnu | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've removed |
||
``` | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Using the system GHC here is pretty odd. Can we just use |
||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We could do with a section on deploying the resulting artefacts. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ideally we'll manage to fully statically link everything, meaning we'll just have a single executable file to deploy. If we are stuck with shared libraries, we'll need commands like:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We now have static Linux builds, but Windows needs a load of DLLs (weirdly this is an inversion of the usual non-Nix state of things). Can we compile statically with MinGW? |
||
# Run | ||
|
||
Run `./dist/monpad` to start the server (you can pass the `-h` flag to see all options). | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Weirdly, we have to remove the Windows target from
crossPlatforms
in order for plain~/.ghcup/bin/runghc Build.hs
to work, i.e. to build for the host platform. This seems like a Haskell.nix bug. It's not a huge issue though, as we don't have much reason to use Nix at all for such a build. It would be nice to get cached dependencies though.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This command actually fails quickly for TH reasons. It may be salvageable, but the fact it doesn't "just work" seems a limitation of the shell-based approach, as opposed to
nix build
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we just use
nix build .#x86_64-w64-mingw32:monpad:exe:monpad
, we would need to add some Nix config for compiling the non-Haskell parts of the project.Perhaps it could just shell out to
runghc Build.hs assets
.