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

buildRustCrate: support cross compilation #99050

Merged
merged 2 commits into from
Sep 29, 2020
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
12 changes: 9 additions & 3 deletions pkgs/build-support/rust/build-rust-crate/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
# This can be useful for deploying packages with NixOps, and to share
# binary dependencies between projects.

{ lib, stdenv, defaultCrateOverrides, fetchCrate, rustc, rust, cargo, jq }:
{ lib, stdenv, defaultCrateOverrides, fetchCrate, pkgsBuildBuild, rustc, rust
, cargo, jq }:

let
# This doesn't appear to be officially documented anywhere yet.
Expand Down Expand Up @@ -83,6 +84,8 @@ in
# A list of rust/cargo features to enable while building the crate.
# Example: [ "std" "async" ]
, features
# Additional native build inputs for building this crate.
, nativeBuildInputs
# Additional build inputs for building this crate.
#
# Example: [ pkgs.openssl ]
Expand Down Expand Up @@ -188,12 +191,13 @@ let crate = crate_ // (lib.attrByPath [ crate_.crateName ] (attr: {}) crateOverr
dependencies_ = dependencies;
buildDependencies_ = buildDependencies;
processedAttrs = [
"src" "buildInputs" "crateBin" "crateLib" "libName" "libPath"
"src" "nativeBuildInputs" "buildInputs" "crateBin" "crateLib" "libName" "libPath"
"buildDependencies" "dependencies" "features" "crateRenames"
"crateName" "version" "build" "authors" "colors" "edition"
"buildTests"
];
extraDerivationAttrs = builtins.removeAttrs crate processedAttrs;
nativeBuildInputs_ = nativeBuildInputs;
buildInputs_ = buildInputs;
extraRustcOpts_ = extraRustcOpts;
buildTests_ = buildTests;
Expand Down Expand Up @@ -225,7 +229,8 @@ stdenv.mkDerivation (rec {
src = crate.src or (fetchCrate { inherit (crate) crateName version sha256; });
name = "rust_${crate.crateName}-${crate.version}${lib.optionalString buildTests_ "-test"}";
version = crate.version;
depsBuildBuild = [ rust stdenv.cc cargo jq ];
depsBuildBuild = [ pkgsBuildBuild.stdenv.cc ];
nativeBuildInputs = [ rust stdenv.cc cargo jq ] ++ (crate.nativeBuildInputs or []) ++ nativeBuildInputs_;
buildInputs = (crate.buildInputs or []) ++ buildInputs_;
dependencies = map lib.getLib dependencies_;
buildDependencies = map lib.getLib buildDependencies_;
Expand Down Expand Up @@ -301,6 +306,7 @@ stdenv.mkDerivation (rec {
verbose = crate_.verbose or true;
extraRustcOpts = [];
features = [];
nativeBuildInputs = [];
buildInputs = [];
crateOverrides = defaultCrateOverrides;
preUnpack = crate_.preUnpack or "";
Expand Down
30 changes: 20 additions & 10 deletions pkgs/build-support/rust/default-crate-overrides.nix
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,21 @@ in
};

libz-sys = attrs: {
buildInputs = [ pkgconfig zlib ];
nativeBuildInputs = [ pkgconfig ];
buildInputs = [ zlib ];
extraLinkFlags = ["-L${zlib.out}/lib"];
};

curl-sys = attrs: {
buildInputs = [ pkgconfig zlib curl ];
nativeBuildInputs = [ pkgconfig ];
buildInputs = [ zlib curl ];
propagatedBuildInputs = [ curl zlib ];
extraLinkFlags = ["-L${zlib.out}/lib"];
};

dbus = attrs: {
buildInputs = [ pkgconfig dbus ];
nativeBuildInputs = [ pkgconfig ];
buildInputs = [ dbus ];
};

foundationdb-sys = attrs: {
Expand Down Expand Up @@ -62,31 +65,37 @@ in

libgit2-sys = attrs: {
LIBGIT2_SYS_USE_PKG_CONFIG = true;
buildInputs = [ pkgconfig openssl zlib libgit2 ];
nativeBuildInputs = [ pkgconfig ];
buildInputs = [ openssl zlib libgit2 ];
};

libsqlite3-sys = attrs: {
buildInputs = [ pkgconfig sqlite ];
nativeBuildInputs = [ pkgconfig ];
buildInputs = [ sqlite ];
};

libssh2-sys = attrs: {
buildInputs = [ pkgconfig openssl zlib libssh2 ];
nativeBuildInputs = [ pkgconfig ];
buildInputs = [ openssl zlib libssh2 ];
};

libdbus-sys = attrs: {
buildInputs = [ pkgconfig dbus ];
nativeBuildInputs = [ pkgconfig ];
buildInputs = [ dbus ];
};

openssl = attrs: {
buildInputs = [ openssl ];
};

openssl-sys = attrs: {
buildInputs = [ pkgconfig openssl ];
nativeBuildInputs = [ pkgconfig ];
buildInputs = [ openssl ];
};

pq-sys = attr: {
buildInputs = [ pkgconfig postgresql ];
nativeBuildInputs = [ pkgconfig ];
buildInputs = [ postgresql ];
};

rink = attrs: {
Expand All @@ -103,7 +112,8 @@ in
};

thrussh-libsodium = attrs: {
buildInputs = [ pkgconfig libsodium ];
nativeBuildInputs = [ pkgconfig ];
buildInputs = [ libsodium ];
};

xcb = attrs: {
Expand Down