Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit b7f7205

Browse files
committed
run_make_support: move build_native_static_lib under external_deps
And fix some `ar`-related rebase mishaps.
1 parent aadd085 commit b7f7205

File tree

4 files changed

+30
-50
lines changed

4 files changed

+30
-50
lines changed

src/tools/run-make-support/src/ar.rs

Lines changed: 0 additions & 22 deletions
This file was deleted.
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
use std::path::PathBuf;
2+
3+
use crate::artifact_names::static_lib_name;
4+
use crate::external_deps::cc::cc;
5+
use crate::external_deps::llvm::llvm_ar;
6+
use crate::path_helpers::path;
7+
use crate::targets::is_msvc;
8+
9+
/// Builds a static lib (`.lib` on Windows MSVC and `.a` for the rest) with the given name.
10+
#[track_caller]
11+
pub fn build_native_static_lib(lib_name: &str) -> PathBuf {
12+
let obj_file = if is_msvc() { format!("{lib_name}") } else { format!("{lib_name}.o") };
13+
let src = format!("{lib_name}.c");
14+
let lib_path = static_lib_name(lib_name);
15+
if is_msvc() {
16+
cc().arg("-c").out_exe(&obj_file).input(src).run();
17+
} else {
18+
cc().arg("-v").arg("-c").out_exe(&obj_file).input(src).run();
19+
};
20+
let obj_file = if is_msvc() {
21+
PathBuf::from(format!("{lib_name}.obj"))
22+
} else {
23+
PathBuf::from(format!("{lib_name}.o"))
24+
};
25+
llvm_ar().obj_to_ar().output_input(&lib_path, &obj_file).run();
26+
path(lib_path)
27+
}

src/tools/run-make-support/src/external_deps/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
//! - This is not the *only* place where external dependencies are assumed or referenced. For
77
//! example, see [`cygpath_windows`][crate::path_helpers::cygpath_windows].
88
9+
pub mod c_build;
910
pub mod cc;
1011
pub mod clang;
1112
pub mod htmldocck;

src/tools/run-make-support/src/lib.rs

Lines changed: 2 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ mod command;
77
mod macros;
88
mod util;
99

10-
pub mod ar;
1110
pub mod artifact_names;
1211
pub mod assertion_helpers;
1312
pub mod diff;
@@ -28,9 +27,10 @@ pub use regex;
2827
pub use wasmparser;
2928

3029
// Re-exports of external dependencies.
31-
pub use external_deps::{cc, clang, htmldocck, llvm, python, rustc, rustdoc};
30+
pub use external_deps::{c_build, cc, clang, htmldocck, llvm, python, rustc, rustdoc};
3231

3332
// These rely on external dependencies.
33+
pub use c_build::build_native_static_lib;
3434
pub use cc::{cc, extra_c_flags, extra_cxx_flags, Cc};
3535
pub use clang::{clang, Clang};
3636
pub use htmldocck::htmldocck;
@@ -42,12 +42,6 @@ pub use python::python_command;
4242
pub use rustc::{aux_build, bare_rustc, rustc, Rustc};
4343
pub use rustdoc::{bare_rustdoc, rustdoc, Rustdoc};
4444

45-
/// [`ar`][mod@ar] currently uses the [ar][rust-ar] rust library, but that is subject to changes, we
46-
/// may switch to `llvm-ar` subject to experimentation.
47-
///
48-
/// [rust-ar]: https://github.com/mdsteele/rust-ar
49-
pub use ar::ar;
50-
5145
/// [`diff`][mod@diff] is implemented in terms of the [similar] library.
5246
///
5347
/// [similar]: https://github.com/mitsuhiko/similar
@@ -82,23 +76,3 @@ pub use assertion_helpers::{
8276
has_prefix, has_suffix, invalid_utf8_contains, invalid_utf8_not_contains, not_contains,
8377
shallow_find_files,
8478
};
85-
86-
/// Builds a static lib (`.lib` on Windows MSVC and `.a` for the rest) with the given name.
87-
#[track_caller]
88-
pub fn build_native_static_lib(lib_name: &str) -> PathBuf {
89-
let obj_file = if is_msvc() { format!("{lib_name}") } else { format!("{lib_name}.o") };
90-
let src = format!("{lib_name}.c");
91-
let lib_path = static_lib_name(lib_name);
92-
if is_msvc() {
93-
cc().arg("-c").out_exe(&obj_file).input(src).run();
94-
} else {
95-
cc().arg("-v").arg("-c").out_exe(&obj_file).input(src).run();
96-
};
97-
let obj_file = if is_msvc() {
98-
PathBuf::from(format!("{lib_name}.obj"))
99-
} else {
100-
PathBuf::from(format!("{lib_name}.o"))
101-
};
102-
llvm_ar().obj_to_ar().output_input(&lib_path, &obj_file).run();
103-
path(lib_path)
104-
}

0 commit comments

Comments
 (0)