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

Fix cross compilation on macOS #17

Merged
merged 7 commits into from
Sep 25, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion default.nix
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
nixpkgsPath ? <nixpkgs>,
nixpkgsPath ? ./nixpkgs.nix,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, let's pin the default nixpkgs.

system ? builtins.currentSystem,
overlays ? [],
crossSystem ? (import <nixpkgs/lib>).systems.examples.musl64,
Expand Down
24 changes: 24 additions & 0 deletions nixpkgs.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{ ... }@args:
import
(fetchGit {
url = https://github.com/NixOS/nixpkgs;
rev = "47b551c6a854a049045455f8ab1b8750e7b00625";
})
(args // {
config.packageOverrides = pkgs: {
openssl = (pkgs.openssl.override {
# `perl` is only used at build time, but the derivation incorrectly uses host `perl`
# as an input.
perl = pkgs.buildPackages.buildPackages.perl;
}).overrideAttrs (_: {
# `man` output is troublesome, disable it.
installTargets = "install_sw";
outputs = [ "bin" "dev" "out" ];
});

# These packages need rebuilding because of the harmless `openssl` change above.
# The test suites for them fails (for some reason) so just disable them.
libuv = pkgs.libuv.overrideAttrs (_: { doCheck = false; });
e2fsprogs = pkgs.e2fsprogs.overrideAttrs (_: { doCheck = false; });
};
})
4 changes: 2 additions & 2 deletions overlay/json2toml.nix
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{ remarshal, runCommand }:
json:
{ name, json }:
runCommand
"to.toml"
"${name}-to.toml"
{
nativeBuildInputs = [remarshal];
passAsFile = [ "json" ];
Expand Down
7 changes: 4 additions & 3 deletions overlay/mkcrate.nix
Original file line number Diff line number Diff line change
Expand Up @@ -522,10 +522,11 @@ let
nativeBuildInputs =
sort
(a: b: "${a}" < "${b}")
([ buildPackages.jq cargo buildPackages.pkg-config ] ++
([ cargo buildPackages.pkg-config ] ++
map accessPackage nativeBuildInputs ++
accessConfig "nativeBuildInputs" [] package-id ++
optional (!isNull target.nativeBuildInputs or null) target.nativeBuildInputs or []);
depsBuildBuild = [ buildPackages.buildPackages.stdenv.cc buildPackages.buildPackages.jq ];

# Running the default `strip -S` command on Darwin corrupts the
# .rlib files in "lib/".
Expand Down Expand Up @@ -566,7 +567,7 @@ let
cat > .cargo/config <<'EOF'
[target."${realHostTriple stdenv.buildPlatform}"]
linker = "${ccForBuild}"
'' + optionalString (stdenv.buildPlatform != stdenv.hostPlatform && !stdenv.hostPlatform.isWasi && isNull target) ''
'' + optionalString (stdenv.buildPlatform != stdenv.hostPlatform && !(stdenv.hostPlatform.isWasi or false) && isNull target) ''
[target."${host-triple}"]
linker = "${ccForHost}"
'' + ''
Expand All @@ -578,7 +579,7 @@ let
echo name = \"${name}\" >> Cargo.lock
echo version = \"${version}\" >> Cargo.lock
echo source = \"registry+${registry}\" >> Cargo.lock
cp ${rustLib.json2toml patched-manifest} Cargo.toml
cp ${rustLib.json2toml { inherit name; json = patched-manifest; }} Cargo.toml
'';

configurePhase =
Expand Down
2 changes: 1 addition & 1 deletion overlay/real-host-triple.nix
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ let
kernel = platform.parsed.kernel.name;
abi = platform.parsed.abi.name;
in
if platform.isWasi then
if platform.isWasi or false then
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice catch!
As a note, the isWasi symbol is available in upstream nixpkgs since June.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a huge help! I've been having issues building cargo2nix projects in NixOS environments using very old Nixpkgs (e.g. nix-docker) specifically because of this attribute not being present.

"${platform.parsed.cpu.name}-wasi"
else {
"i686-linux" = "i686-unknown-linux-${abi}";
Expand Down
4 changes: 2 additions & 2 deletions overlay/toml2json.nix
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{ lib, remarshal, runCommand }:
toml:
{ name, toml }:
let
json = runCommand
"to.json"
"${name}-to.json"
{
nativeBuildInputs = [remarshal];
passAsFile = [ "toml" ];
Expand Down