Skip to content

Commit ca80f3e

Browse files
authored
Merge pull request #19 from mlabs-haskell/szg251/rust-extra-sources
Rust extraSources simplification
2 parents 27185eb + f1d8409 commit ca80f3e

File tree

11 files changed

+65
-5
lines changed

11 files changed

+65
-5
lines changed

examples/build.nix

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ _:
77
[
88
./haskell-flake-project/build.nix
99
./rust-flake-project/build.nix
10+
./rust-flake-project-with-extra-dependency/build.nix
1011
./typescript-flake-project/build.nix
1112
./typescript-flake-project-with-extra-dependency/build.nix
1213
./typescript-flake-project-with-transitive-extra-dependency/build.nix
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
use flake ../../#dev-rust-flake-project-with-extra-dependency-rust
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
/target
2+
/.direnv
3+
.extras

examples/rust-flake-project-with-extra-dependency/Cargo.lock

+14
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
[package]
2+
name = "rust-flake-project-with-extra-dependency"
3+
version = "0.1.0"
4+
edition = "2021"
5+
6+
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
7+
8+
[dependencies]
9+
rust-flake-project = { path = ".extras/rust-flake-project-0.1.0" }
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
{ inputs, ... }: {
2+
perSystem = { config, ... }:
3+
4+
let
5+
rustFlake = config.lib.rustFlake
6+
{
7+
src = ./.;
8+
inherit (inputs) crane;
9+
crateName = "rust-flake-project-with-extra-dependency";
10+
11+
extraSources = [
12+
config.packages.rust-flake-project-rust-src
13+
];
14+
15+
devShellHook = config.settings.shell.hook;
16+
17+
};
18+
in
19+
{
20+
21+
inherit (rustFlake) packages checks devShells;
22+
23+
};
24+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
fn main() {
2+
let planet = rust_flake_project::get_planet();
3+
println!("Hello, {}!", planet);
4+
}

examples/rust-flake-project/.envrc

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
use flake ../../#dev-rust-flake-test-rust
1+
use flake ../../#dev-rust-flake-project-rust

examples/rust-flake-project/build.nix

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
{
77
src = ./.;
88
inherit (inputs) crane;
9-
crateName = "rust-flake-test";
9+
crateName = "rust-flake-project";
1010

1111
devShellHook = config.settings.shell.hook;
1212

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
pub fn get_planet() -> String {
2+
String::from("Earth")
3+
}

flake-lang/flake-rust.nix

+4-3
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ pkgs:
33
{ crane
44
, src
55
, crateName
6+
, version ? "0.1.0"
67
, rustVersion ? "latest"
78
, nativeBuildInputs ? [ ]
89
, buildInputs ? [ ]
@@ -38,14 +39,14 @@ let
3839
'';
3940
};
4041

41-
# Library source code, intended to be in extraSourcesDir
42+
# Library source code, intended to be used in extraSources
4243
# Dependencies of this crate are not copied, to the extra sources directory
4344
# but they are referenced from the parent directory (parent crate's extra sources).
4445
vendoredSrc =
4546
pkgs.stdenv.mkDerivation
4647
{
4748
src = cleanSrc;
48-
name = "${crateName}-vendored-src";
49+
name = "${crateName}-${version}";
4950
unpackPhase = ''
5051
mkdir $out
5152
cp -r $src/* $out
@@ -63,7 +64,7 @@ let
6364
cargoArtifacts = craneLib.buildDepsOnly commonArgs;
6465

6566
# Extra sources
66-
extra-sources = pkgs.linkFarm "extra-sources" extraSources;
67+
extra-sources = pkgs.linkFarm "extra-sources" (builtins.map (drv: { name = drv.name; path = drv; }) extraSources);
6768

6869
hasExtraSources = builtins.length extraSources > 0;
6970
linkExtraSources = pkgs.lib.optionalString hasExtraSources ''

0 commit comments

Comments
 (0)