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 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 https://github.com/nix-community/naersk/issues/305.
This commit is contained in:
Patryk Wychowaniec 2023-08-17 12:39:58 +02:00
parent 275010712c
commit 78789c30d6
7 changed files with 46 additions and 1 deletions

View file

@ -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 (
{

View file

@ -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;
}

View file

@ -0,0 +1,2 @@
[env]
ENV_HELLO_WORLD="Hello, World!"

View file

@ -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"

View file

@ -0,0 +1,4 @@
[package]
name = "cargo-config"
version = "0.1.0"
edition = "2018"

View file

@ -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"));
}
}

View file

@ -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;