mirror of https://github.com/rust-lang/rust.git
build_native_static_lib with llvm_ar for run_make_support
This commit is contained in:
parent
3b495bb60b
commit
ea2b699b94
|
@ -228,12 +228,6 @@ dependencies = [
|
|||
"backtrace",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "ar"
|
||||
version = "0.9.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d67af77d68a931ecd5cbd8a3b5987d63a1d1d1278f7f6a60ae33db485cdebb69"
|
||||
|
||||
[[package]]
|
||||
name = "ar_archive_writer"
|
||||
version = "0.2.0"
|
||||
|
@ -3429,7 +3423,6 @@ dependencies = [
|
|||
name = "run_make_support"
|
||||
version = "0.2.0"
|
||||
dependencies = [
|
||||
"ar",
|
||||
"bstr",
|
||||
"build_helper",
|
||||
"gimli 0.31.0",
|
||||
|
|
|
@ -10,6 +10,4 @@ similar = "2.5.0"
|
|||
wasmparser = "0.118.2"
|
||||
regex = "1.8" # 1.8 to avoid memchr 2.6.0, as 2.5.0 is pinned in the workspace
|
||||
gimli = "0.31.0"
|
||||
ar = "0.9.0"
|
||||
|
||||
build_helper = { path = "../build_helper" }
|
||||
|
|
|
@ -30,8 +30,8 @@ pub use cc::{cc, extra_c_flags, extra_cxx_flags, Cc};
|
|||
pub use clang::{clang, Clang};
|
||||
pub use diff::{diff, Diff};
|
||||
pub use llvm::{
|
||||
llvm_filecheck, llvm_objdump, llvm_profdata, llvm_readobj, LlvmFilecheck, LlvmObjdump,
|
||||
LlvmProfdata, LlvmReadobj,
|
||||
llvm_ar, llvm_filecheck, llvm_objdump, llvm_profdata, llvm_readobj, LlvmAr, LlvmFilecheck,
|
||||
LlvmObjdump, LlvmProfdata, LlvmReadobj,
|
||||
};
|
||||
pub use run::{cmd, run, run_fail, run_with_args};
|
||||
pub use rustc::{aux_build, bare_rustc, rustc, Rustc};
|
||||
|
@ -61,19 +61,6 @@ pub fn target() -> String {
|
|||
env_var("TARGET")
|
||||
}
|
||||
|
||||
/// `AR`
|
||||
#[track_caller]
|
||||
pub fn ar(inputs: &[impl AsRef<Path>], output_path: impl AsRef<Path>) {
|
||||
let output = fs::File::create(&output_path).expect(&format!(
|
||||
"the file in path \"{}\" could not be created",
|
||||
output_path.as_ref().display()
|
||||
));
|
||||
let mut builder = ar::Builder::new(output);
|
||||
for input in inputs {
|
||||
builder.append_path(input).unwrap();
|
||||
}
|
||||
}
|
||||
|
||||
/// Check if target is windows-like.
|
||||
#[must_use]
|
||||
pub fn is_windows() -> bool {
|
||||
|
@ -305,12 +292,12 @@ pub fn build_native_static_lib(lib_name: &str) -> PathBuf {
|
|||
} else {
|
||||
cc().arg("-v").arg("-c").out_exe(&obj_file).input(src).run();
|
||||
};
|
||||
let mut obj_file = PathBuf::from(format!("{lib_name}.o"));
|
||||
if is_msvc() {
|
||||
obj_file.set_extension("");
|
||||
obj_file.set_extension("obj");
|
||||
}
|
||||
ar(&[obj_file], &lib_path);
|
||||
let obj_file = if is_msvc() {
|
||||
PathBuf::from(format!("{lib_name}.obj"))
|
||||
} else {
|
||||
PathBuf::from(format!("{lib_name}.o"))
|
||||
};
|
||||
llvm_ar().obj_to_ar().output_input(&lib_path, &obj_file).run();
|
||||
path(lib_path)
|
||||
}
|
||||
|
||||
|
|
|
@ -29,6 +29,12 @@ pub fn llvm_objdump() -> LlvmObjdump {
|
|||
LlvmObjdump::new()
|
||||
}
|
||||
|
||||
/// Construct a new `llvm-ar` invocation. This assumes that `llvm-ar` is available
|
||||
/// at `$LLVM_BIN_DIR/llvm-ar`.
|
||||
pub fn llvm_ar() -> LlvmAr {
|
||||
LlvmAr::new()
|
||||
}
|
||||
|
||||
/// A `llvm-readobj` invocation builder.
|
||||
#[derive(Debug)]
|
||||
#[must_use]
|
||||
|
@ -57,10 +63,18 @@ pub struct LlvmObjdump {
|
|||
cmd: Command,
|
||||
}
|
||||
|
||||
/// A `llvm-ar` invocation builder.
|
||||
#[derive(Debug)]
|
||||
#[must_use]
|
||||
pub struct LlvmAr {
|
||||
cmd: Command,
|
||||
}
|
||||
|
||||
crate::impl_common_helpers!(LlvmReadobj);
|
||||
crate::impl_common_helpers!(LlvmProfdata);
|
||||
crate::impl_common_helpers!(LlvmFilecheck);
|
||||
crate::impl_common_helpers!(LlvmObjdump);
|
||||
crate::impl_common_helpers!(LlvmAr);
|
||||
|
||||
/// Generate the path to the bin directory of LLVM.
|
||||
#[must_use]
|
||||
|
@ -204,3 +218,26 @@ impl LlvmObjdump {
|
|||
self
|
||||
}
|
||||
}
|
||||
|
||||
impl LlvmAr {
|
||||
/// Construct a new `llvm-ar` invocation. This assumes that `llvm-ar` is available
|
||||
/// at `$LLVM_BIN_DIR/llvm-ar`.
|
||||
pub fn new() -> Self {
|
||||
let llvm_ar = llvm_bin_dir().join("llvm-ar");
|
||||
let cmd = Command::new(llvm_ar);
|
||||
Self { cmd }
|
||||
}
|
||||
|
||||
pub fn obj_to_ar(&mut self) -> &mut Self {
|
||||
self.cmd.arg("rcus");
|
||||
self
|
||||
}
|
||||
|
||||
/// Provide an output, then an input file. Bundled in one function, as llvm-ar has
|
||||
/// no "--output"-style flag.
|
||||
pub fn output_input(&mut self, out: impl AsRef<Path>, input: impl AsRef<Path>) -> &mut Self {
|
||||
self.cmd.arg(out.as_ref());
|
||||
self.cmd.arg(input.as_ref());
|
||||
self
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,8 +1,14 @@
|
|||
// When the metadata format changes, old libraries used to cause librustc to abort
|
||||
// when reading their metadata. The error message for this scenario was unhelpful at best.
|
||||
// A better error message was implemented in #12645, and this test checks that it is the
|
||||
// one appearing in stderr in this scenario.
|
||||
// See https://github.com/rust-lang/rust/pull/12645
|
||||
|
||||
use run_make_support::fs_wrapper::create_file;
|
||||
use run_make_support::{ar, rustc};
|
||||
use run_make_support::{llvm_ar, rustc};
|
||||
|
||||
fn main() {
|
||||
create_file("lib.rmeta");
|
||||
ar(&["lib.rmeta"], "libfoo-ffffffff-1.0.rlib");
|
||||
llvm_ar().obj_to_ar().output_input("libfoo-ffffffff-1.0.rlib", "lib.rmeta").run();
|
||||
rustc().input("foo.rs").run_fail().assert_stderr_contains("found invalid metadata");
|
||||
}
|
||||
|
|
|
@ -6,6 +6,8 @@
|
|||
// See https://github.com/rust-lang/rust/pull/10749
|
||||
|
||||
//@ ignore-cross-compile
|
||||
//@ ignore-windows-gnu
|
||||
// Reason: The space is parsed as an empty linker argument on windows-gnu.
|
||||
|
||||
use run_make_support::rustc;
|
||||
|
||||
|
|
Loading…
Reference in New Issue