Skip to content

Commit

Permalink
Merge pull request NixOS#78188 from andir/buildRustCrate-support-rlib
Browse files Browse the repository at this point in the history
buildRustCrate: support `rlib` dependency type
  • Loading branch information
andir committed Jan 28, 2020
2 parents 610a8fd + 78faab1 commit cd27940
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 13 deletions.
2 changes: 1 addition & 1 deletion pkgs/build-support/rust/build-rust-crate/default.nix
Expand Up @@ -23,7 +23,7 @@ let
lib.strings.replaceStrings ["-"] ["_"] crateRenames.${dep.crateName}
else
extern;
in (if lib.any (x: x == "lib") dep.crateType then
in (if lib.any (x: x == "lib" || x == "rlib") dep.crateType then
" --extern ${name}=${dep.lib}/lib/lib${extern}-${dep.metadata}.rlib"
else
" --extern ${name}=${dep.lib}/lib/lib${extern}-${dep.metadata}${stdenv.hostPlatform.extensions.sharedLibrary}")
Expand Down
37 changes: 25 additions & 12 deletions pkgs/build-support/rust/build-rust-crate/test/default.nix
@@ -1,17 +1,17 @@
{ lib, buildRustCrate, runCommand, writeTextFile, symlinkJoin, callPackage, releaseTools }:
let
mkCrate = args: let
p = {
crateName = "nixtestcrate";
version = "0.1.0";
authors = [ "Test <test@example.com>" ];
} // args;
in buildRustCrate p;

mkFile = destination: text: writeTextFile {
name = "src";
destination = "/${destination}";
inherit text;
p = {
crateName = "nixtestcrate";
version = "0.1.0";
authors = [ "Test <test@example.com>" ];
} // args;
in buildRustCrate p;

mkFile = destination: text: writeTextFile {
name = "src";
destination = "/${destination}";
inherit text;
};

mkBin = name: mkFile name ''
Expand Down Expand Up @@ -185,7 +185,20 @@ let
"test tests_bar ... ok"
];
};

linkAgainstRlibCrate = {
crateName = "foo";
src = mkFile "src/main.rs" ''
extern crate somerlib;
fn main() {}
'';
dependencies = [
(mkCrate {
crateName = "somerlib";
type = [ "rlib" ];
src = mkLib "src/lib.rs";
})
];
};
};
brotliCrates = (callPackage ./brotli-crates.nix {});
in lib.mapAttrs (key: value: mkTest (value // lib.optionalAttrs (!value?crateName) { crateName = key; })) cases // {
Expand Down

0 comments on commit cd27940

Please sign in to comment.