Skip to content

Commit 730f493

Browse files
committed
Do not put trace-nix.so to $OUT_DIR (in nix-build)
Otherwise, it is inconvenient to handle subtle differences between naersk and buildRustPackage: * in naersk it is `target/release/build/...` * in buildRustPackage it is `$releaseDir/build/...` which typically expanded to `target/x86_64-unknown-linux-gnu/release/build/...`
1 parent 27d1bf5 commit 730f493

File tree

2 files changed

+18
-16
lines changed

2 files changed

+18
-16
lines changed

build.rs

+16-15
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,8 @@ use std::path::Path;
33
use std::process::Command;
44

55
fn main() {
6-
let out_dir = var("OUT_DIR").unwrap();
7-
8-
let cmd = Command::new("make")
9-
.args(&[
10-
"-C",
11-
"nix-trace",
12-
&format!("DESTDIR={}", out_dir),
13-
&format!("{}/trace-nix.so", out_dir),
14-
])
15-
.status()
16-
.unwrap();
17-
assert!(cmd.success());
18-
196
if var_os("CNS_IN_NIX_SHELL").is_none() {
20-
// Use paths relative to $out (which is set by nix-build).
7+
// Release build triggered by nix-build. Use paths relative to $out.
218
let out = var("out").unwrap();
229
println!("cargo:rustc-env=CNS_TRACE_NIX_SO={}/lib/trace-nix.so", out);
2310
println!("cargo:rustc-env=CNS_VAR_EMPTY={}/var/empty", out);
@@ -30,7 +17,21 @@ fn main() {
3017
out
3118
);
3219
} else {
33-
// Use paths relative to $PWD. Suitable for developing.
20+
// Developer build triggered by `nix-shell --run 'cargo build'`.
21+
// Use paths relative to the build directory. Additionally, place
22+
// trace-nix.so and a symlink to the build directory.
23+
let out_dir = var("OUT_DIR").unwrap();
24+
let cmd = Command::new("make")
25+
.args(&[
26+
"-C",
27+
"nix-trace",
28+
&format!("DESTDIR={}", out_dir),
29+
&format!("{}/trace-nix.so", out_dir),
30+
])
31+
.status()
32+
.unwrap();
33+
assert!(cmd.success());
34+
3435
println!("cargo:rustc-env=CNS_TRACE_NIX_SO={}/trace-nix.so", out_dir);
3536
println!("cargo:rustc-env=CNS_VAR_EMPTY=/var/empty");
3637
println!(

nix/Makefile

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,12 @@ no-default-target: ; @false
33
VERSION := $(shell sed < Cargo.toml -n 's/^version *= *"\(.*\)".*/\1/p')
44

55
post-build:
6+
make -C nix-trace
67
ronn --organization="cached-nix-shell ${VERSION}" -r cached-nix-shell.1.md
78

89
post-install:
910
mkdir -p ${out}/lib
10-
cp target/release/build/cached-nix-shell-*/out/trace-nix.so ${out}/lib/
11+
cp nix-trace/build/trace-nix.so ${out}/lib
1112

1213
mkdir -p ${out}/share/cached-nix-shell
1314
cp rcfile.sh ${out}/share/cached-nix-shell/

0 commit comments

Comments
 (0)