mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-27 11:07:44 +00:00
stdbuf: updated 'build.rs' fixed issue #6981
This commit is contained in:
parent
7d46a35e02
commit
1f2bd34ef0
1 changed files with 19 additions and 46 deletions
|
@ -5,6 +5,7 @@
|
||||||
// spell-checker:ignore (ToDO) dylib libstdbuf deps liblibstdbuf
|
// spell-checker:ignore (ToDO) dylib libstdbuf deps liblibstdbuf
|
||||||
|
|
||||||
use std::env;
|
use std::env;
|
||||||
|
use std::env::current_exe;
|
||||||
use std::fs;
|
use std::fs;
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
|
|
||||||
|
@ -24,53 +25,25 @@ mod platform {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let out_dir = env::var("OUT_DIR").unwrap();
|
let current_exe = current_exe().unwrap();
|
||||||
let mut target_dir = Path::new(&out_dir);
|
|
||||||
|
|
||||||
// Depending on how this is util is built, the directory structure changes.
|
let out_dir_string = env::var("OUT_DIR").unwrap();
|
||||||
// This seems to work for now. Here are three cases to test when changing
|
let out_dir = Path::new(&out_dir_string);
|
||||||
// this:
|
|
||||||
//
|
|
||||||
// - cargo run
|
|
||||||
// - cross run
|
|
||||||
// - cargo install --git
|
|
||||||
// - cargo publish --dry-run
|
|
||||||
//
|
|
||||||
// The goal is to find the directory in which we are installing, but that
|
|
||||||
// depends on the build method, which is annoying. Additionally the env
|
|
||||||
// var for the profile can only be "debug" or "release", not a custom
|
|
||||||
// profile name, so we have to use the name of the directory within target
|
|
||||||
// as the profile name.
|
|
||||||
//
|
|
||||||
// Adapted from https://stackoverflow.com/questions/73595435/how-to-get-profile-from-cargo-toml-in-build-rs-or-at-runtime
|
|
||||||
let profile_name = out_dir
|
|
||||||
.split(std::path::MAIN_SEPARATOR)
|
|
||||||
.nth_back(3)
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
let mut name = target_dir.file_name().unwrap().to_string_lossy();
|
let deps_dir = current_exe.ancestors().nth(3).unwrap().join("deps");
|
||||||
while name != "target" && !name.starts_with("cargo-install") {
|
dbg!(&deps_dir);
|
||||||
target_dir = target_dir.parent().unwrap();
|
|
||||||
name = target_dir.file_name().unwrap().to_string_lossy();
|
|
||||||
}
|
|
||||||
let mut dir = target_dir.to_path_buf();
|
|
||||||
dir.push(profile_name);
|
|
||||||
dir.push("deps");
|
|
||||||
let mut path = None;
|
|
||||||
|
|
||||||
// When running cargo publish, cargo appends hashes to the filenames of the compiled artifacts.
|
let libstdbuf = deps_dir
|
||||||
// Therefore, it won't work to just get liblibstdbuf.so. Instead, we look for files with the
|
.read_dir()
|
||||||
// glob pattern "liblibstdbuf*.so" (i.e. starts with liblibstdbuf and ends with the extension).
|
.unwrap()
|
||||||
for entry in fs::read_dir(dir).unwrap().flatten() {
|
.flatten()
|
||||||
let name = entry.file_name();
|
.find(|entry| {
|
||||||
let name = name.to_string_lossy();
|
let n = entry.file_name();
|
||||||
if name.starts_with("liblibstdbuf") && name.ends_with(platform::DYLIB_EXT) {
|
let name = n.to_string_lossy();
|
||||||
path = Some(entry.path());
|
|
||||||
}
|
name.starts_with("liblibstdbuf") && name.ends_with(platform::DYLIB_EXT)
|
||||||
}
|
})
|
||||||
fs::copy(
|
.expect("unable to find libstdbuf");
|
||||||
path.expect("liblibstdbuf was not found"),
|
|
||||||
Path::new(&out_dir).join("libstdbuf.so"),
|
fs::copy(libstdbuf.path(), out_dir.join("libstdbuf.so")).unwrap();
|
||||||
)
|
|
||||||
.unwrap();
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue