From f06e904c333d136d8eead1587734a7cb72b230dd Mon Sep 17 00:00:00 2001 From: Patryk Wychowaniec Date: Thu, 17 Aug 2023 12:39:58 +0200 Subject: [PATCH] Fix support for `.cargo/config` Before https://github.com/nix-community/naersk/pull/300, our `builtinz.toTOML` used to return a string representing the serialized document which was later redirected into a file: https://github.com/nix-community/naersk/pull/300/files#diff-b6b537316f2d29c8faf178a110366796811d1bc72f694262c7d2efad79aa984bL238 Over that merge request, this was changed to return a path, to make it consistent with how nixpkgs' formatters works, but I haven't noticed one place that still _read_ the file instead of returning a path (which was fine before, since the code did `echo ... > ...`, but currently the code does `cp`). Closes https://github.com/nix-community/naersk/issues/305. --- default.nix | 2 +- test/fast/cargo-config/default.nix | 6 ++++++ test/fast/cargo-config/fixtures/.cargo/config | 2 ++ test/fast/cargo-config/fixtures/Cargo.lock | 7 +++++++ test/fast/cargo-config/fixtures/Cargo.toml | 4 ++++ test/fast/cargo-config/fixtures/src/main.rs | 11 +++++++++++ test/fast/default.nix | 1 + 7 files changed, 32 insertions(+), 1 deletion(-) create mode 100644 test/fast/cargo-config/default.nix create mode 100644 test/fast/cargo-config/fixtures/.cargo/config create mode 100644 test/fast/cargo-config/fixtures/Cargo.lock create mode 100644 test/fast/cargo-config/fixtures/Cargo.toml create mode 100644 test/fast/cargo-config/fixtures/src/main.rs diff --git a/default.nix b/default.nix index 61b44ec..a377938 100644 --- a/default.nix +++ b/default.nix @@ -31,7 +31,7 @@ let libb.findGitDependencies { inherit (config) cargolock gitAllRefs gitSubmodules; }; cargoconfig = if builtinz.pathExists (toString config.root + "/.cargo/config") - then builtins.readFile (config.root + "/.cargo/config") + then (config.root + "/.cargo/config") else null; build = args: import ./build.nix ( { diff --git a/test/fast/cargo-config/default.nix b/test/fast/cargo-config/default.nix new file mode 100644 index 0000000..d34c380 --- /dev/null +++ b/test/fast/cargo-config/default.nix @@ -0,0 +1,6 @@ +{ naersk, ... }: + +naersk.buildPackage { + src = ./fixtures; + doCheck = true; +} diff --git a/test/fast/cargo-config/fixtures/.cargo/config b/test/fast/cargo-config/fixtures/.cargo/config new file mode 100644 index 0000000..ac0cce0 --- /dev/null +++ b/test/fast/cargo-config/fixtures/.cargo/config @@ -0,0 +1,2 @@ +[env] +ENV_HELLO_WORLD="Hello, World!" diff --git a/test/fast/cargo-config/fixtures/Cargo.lock b/test/fast/cargo-config/fixtures/Cargo.lock new file mode 100644 index 0000000..c469709 --- /dev/null +++ b/test/fast/cargo-config/fixtures/Cargo.lock @@ -0,0 +1,7 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "cargo-config" +version = "0.1.0" diff --git a/test/fast/cargo-config/fixtures/Cargo.toml b/test/fast/cargo-config/fixtures/Cargo.toml new file mode 100644 index 0000000..da3a97d --- /dev/null +++ b/test/fast/cargo-config/fixtures/Cargo.toml @@ -0,0 +1,4 @@ +[package] +name = "cargo-config" +version = "0.1.0" +edition = "2021" diff --git a/test/fast/cargo-config/fixtures/src/main.rs b/test/fast/cargo-config/fixtures/src/main.rs new file mode 100644 index 0000000..c11d46f --- /dev/null +++ b/test/fast/cargo-config/fixtures/src/main.rs @@ -0,0 +1,11 @@ +fn main() { + println!("{}", env!("ENV_HELLO_WORLD")); +} + +#[cfg(test)] +mod tests { + #[test] + fn test() { + assert_eq!("Hello, World!", env!("ENV_HELLO_WORLD")); + } +} diff --git a/test/fast/default.nix b/test/fast/default.nix index 18582e4..ee063b2 100644 --- a/test/fast/default.nix +++ b/test/fast/default.nix @@ -1,4 +1,5 @@ args: { + cargo-config = import ./cargo-config args; cargo-wildcard = import ./cargo-wildcard args; default-run = import ./default-run args; dummyfication = import ./dummyfication args;