Skip to content

Commit 83a11c9

Browse files
committed
stdbuf: fix build.rs to propagate custom profiles to libstdbuf nested build
The PROFILE env var only returns the base profile name ('release' or 'debug'), not the actual profile. For example, when building with --profile=release-small, PROFILE=release, so the old code would pass --release to the nested libstdbuf build, causing it to be compiled with release settings instead of release-small settings (opt-level=z, strip=true, etc.). Fix this by extracting the actual profile name from OUT_DIR, which always contains the real profile name in its path (.../target/{profile}/build/...). This correctly handles all custom profiles like release-small, profiling, etc. Fixes: #12434 Signed-off-by: Etienne Cordonnier <ecordonnier@snap.com>
1 parent d41c56b commit 83a11c9

1 file changed

Lines changed: 22 additions & 9 deletions

File tree

src/uu/stdbuf/build.rs

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -84,12 +84,25 @@ fn main() {
8484
cmd.current_dir(libstdbuf_src)
8585
.args(["build", "--target-dir", build_dir.to_str().unwrap()]);
8686

87-
// Get the current profile
88-
let profile = env::var("PROFILE").unwrap_or_else(|_| "debug".to_string());
87+
// Determine the actual profile from OUT_DIR since PROFILE env var only gives the base profile
88+
// for inherited profiles (e.g., PROFILE=release for both release and release-small)
89+
// OUT_DIR format: .../target/{profile}/build/...
90+
let profile = Path::new(&out_dir)
91+
.components()
92+
.collect::<Vec<_>>()
93+
.windows(2)
94+
.find_map(|pair| {
95+
if pair[0].as_os_str() == "target" {
96+
pair[1].as_os_str().to_str()
97+
} else {
98+
None
99+
}
100+
})
101+
.unwrap_or("debug");
89102

90-
// Pass the release flag if we're in release mode
91-
if profile == "release" || profile == "bench" {
92-
cmd.arg("--release");
103+
// Pass the profile to the nested build (for release, release-small, profiling, bench, etc.)
104+
if profile != "debug" {
105+
cmd.arg("--profile").arg(profile);
93106
}
94107

95108
// Pass the target architecture if we're cross-compiling
@@ -111,17 +124,17 @@ fn main() {
111124
// Check multiple possible locations for the built library
112125
let possible_paths = if !target.is_empty() && target != "unknown" {
113126
vec![
114-
build_dir.join(&target).join(&profile).join(&lib_name),
127+
build_dir.join(&target).join(profile).join(&lib_name),
115128
build_dir
116129
.join(&target)
117-
.join(&profile)
130+
.join(profile)
118131
.join("deps")
119132
.join(&lib_name),
120133
]
121134
} else {
122135
vec![
123-
build_dir.join(&profile).join(&lib_name),
124-
build_dir.join(&profile).join("deps").join(&lib_name),
136+
build_dir.join(profile).join(&lib_name),
137+
build_dir.join(profile).join("deps").join(&lib_name),
125138
]
126139
};
127140

0 commit comments

Comments
 (0)