Skip to content

Commit

Permalink
Fix support for .cargo/config
Browse files Browse the repository at this point in the history
Before #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 work - 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 is not a correct
thing to do for `cp`).

Closes #305.
  • Loading branch information
Patryk27 committed Aug 18, 2023
1 parent 2750107 commit 78789c3
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 1 deletion.
2 changes: 1 addition & 1 deletion default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
{
Expand Down
20 changes: 20 additions & 0 deletions test/fast/cargo-config/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{ sources, pkgs, ... }:

let
fenix = import sources.fenix { };

# Support for custom environmental variables was introduced in Cargo 1.56 and
# our tests use nixpkgs-21.05 which contains an older version of Cargo, making
# this test fail otherwise.
toolchain = fenix.latest;

naersk = pkgs.callPackage ../../../default.nix {
cargo = toolchain.cargo;
rustc = toolchain.rustc;
};

in
naersk.buildPackage {
src = ./fixtures;
doCheck = true;
}
2 changes: 2 additions & 0 deletions test/fast/cargo-config/fixtures/.cargo/config
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[env]
ENV_HELLO_WORLD="Hello, World!"
7 changes: 7 additions & 0 deletions test/fast/cargo-config/fixtures/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions test/fast/cargo-config/fixtures/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[package]
name = "cargo-config"
version = "0.1.0"
edition = "2018"
11 changes: 11 additions & 0 deletions test/fast/cargo-config/fixtures/src/main.rs
Original file line number Diff line number Diff line change
@@ -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"));
}
}
1 change: 1 addition & 0 deletions test/fast/default.nix
Original file line number Diff line number Diff line change
@@ -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;
Expand Down

0 comments on commit 78789c3

Please sign in to comment.