diff options
author | Georges Dubus <georges.dubus@numergy.com> | 2014-10-10 16:59:37 +0200 |
---|---|---|
committer | Ricardo M. Correia <rcorreia@wizy.org> | 2015-04-21 19:46:29 +0200 |
commit | 7d67efa3f23f7d5c494c90b79a63756a3917be6e (patch) | |
tree | fc8e6121cc18c9d26bba5107a903a8a499501e2a /pkgs/build-support/rust/default.nix | |
parent | c55c7e1c1e09dfa57e1a44d08c777f995493d2c9 (diff) | |
download | nixpkgs-7d67efa3f23f7d5c494c90b79a63756a3917be6e.tar nixpkgs-7d67efa3f23f7d5c494c90b79a63756a3917be6e.tar.gz nixpkgs-7d67efa3f23f7d5c494c90b79a63756a3917be6e.tar.bz2 nixpkgs-7d67efa3f23f7d5c494c90b79a63756a3917be6e.tar.lz nixpkgs-7d67efa3f23f7d5c494c90b79a63756a3917be6e.tar.xz nixpkgs-7d67efa3f23f7d5c494c90b79a63756a3917be6e.tar.zst nixpkgs-7d67efa3f23f7d5c494c90b79a63756a3917be6e.zip |
Add support for building cargo'ed Rust programs
Diffstat (limited to 'pkgs/build-support/rust/default.nix')
-rw-r--r-- | pkgs/build-support/rust/default.nix | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/pkgs/build-support/rust/default.nix b/pkgs/build-support/rust/default.nix new file mode 100644 index 00000000000..a02163f73fa --- /dev/null +++ b/pkgs/build-support/rust/default.nix @@ -0,0 +1,52 @@ +{ stdenv, cacert, git, rustc, cargo, rustRegistry }: +{ name, src, depsSha256, buildInputs ? [], ... } @ args: + +let + fetchDeps = import ./fetchcargo.nix { + inherit stdenv cacert git rustc cargo rustRegistry; + }; + + cargoDeps = fetchDeps { + inherit name src; + sha256 = depsSha256; + }; + +in stdenv.mkDerivation (args // { + inherit cargoDeps rustRegistry; + + buildInputs = [ git cargo rustc ] ++ buildInputs; + + configurePhase = args.configurePhase or "true"; + + postUnpack = '' + echo "Using rust registry from $rustRegistry" + ( + cd $sourceRoot + ln -s $rustRegistry ./cargo-rust-registry + cargo clean + cargo fetch + ) + '' + (args.postUnpack or ""); + + # TODO: Probably not the best way to do this, but it should work for now + prePatch = '' + for dir in ../deps/registry/src/*/pkg-config-*; do + [ -d "$dir" ] || continue + + substituteInPlace "$dir/src/lib.rs" \ + --replace '"/usr"' '"/nix/store/"' + done + '' + (args.prePatch or ""); + + buildPhase = args.buildPhase or '' + echo "Running cargo build" + cargo build --release + ''; + + installPhase = args.installPhase or '' + mkdir -p $out/bin + for f in $(find target/release -maxdepth 1 -type f); do + cp $f $out/bin + done; + ''; +}) |