Skip to content

Commit fc4fb8c

Browse files
committed
re-organize binary related modules
Signed-off-by: onur-ozkan <[email protected]>
1 parent 4166849 commit fc4fb8c

File tree

9 files changed

+37
-26
lines changed

9 files changed

+37
-26
lines changed

src/bootstrap/Cargo.toml

+4-4
Original file line numberDiff line numberDiff line change
@@ -11,22 +11,22 @@ doctest = false
1111

1212
[[bin]]
1313
name = "bootstrap"
14-
path = "src/bins/main.rs"
14+
path = "src/bin/main.rs"
1515
test = false
1616

1717
[[bin]]
1818
name = "rustc"
19-
path = "src/bins/rustc.rs"
19+
path = "src/bin/rustc.rs"
2020
test = false
2121

2222
[[bin]]
2323
name = "rustdoc"
24-
path = "src/bins/rustdoc.rs"
24+
path = "src/bin/rustdoc.rs"
2525
test = false
2626

2727
[[bin]]
2828
name = "sccache-plus-cl"
29-
path = "src/bins/sccache-plus-cl.rs"
29+
path = "src/bin/sccache-plus-cl.rs"
3030
test = false
3131

3232
[dependencies]
File renamed without changes.

src/bootstrap/src/bins/rustc.rs renamed to src/bootstrap/src/bin/rustc.rs

+11-6
Original file line numberDiff line numberDiff line change
@@ -15,20 +15,25 @@
1515
//! switching compilers for the bootstrap and for build scripts will probably
1616
//! never get replaced.
1717
18-
include!("../utils/dylib_util.rs");
19-
include!("./_helper.rs");
20-
2118
use std::env;
2219
use std::path::PathBuf;
23-
use std::process::{exit, Child, Command};
20+
use std::process::{Child, Command};
2421
use std::time::Instant;
2522

23+
use dylib_util::{dylib_path, dylib_path_var};
24+
25+
#[path = "../utils/bin_helpers.rs"]
26+
mod bin_helpers;
27+
28+
#[path = "../utils/dylib_util.rs"]
29+
mod dylib_util;
30+
2631
fn main() {
2732
let args = env::args_os().skip(1).collect::<Vec<_>>();
2833
let arg = |name| args.windows(2).find(|args| args[0] == name).and_then(|args| args[1].to_str());
2934

30-
let stage = parse_rustc_stage();
31-
let verbose = parse_rustc_verbose();
35+
let stage = bin_helpers::parse_rustc_stage();
36+
let verbose = bin_helpers::parse_rustc_verbose();
3237

3338
// Detect whether or not we're a build script depending on whether --target
3439
// is passed (a bit janky...)

src/bootstrap/src/bins/rustdoc.rs renamed to src/bootstrap/src/bin/rustdoc.rs

+9-5
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,21 @@
55
use std::env;
66
use std::ffi::OsString;
77
use std::path::PathBuf;
8-
use std::process::{exit, Command};
8+
use std::process::Command;
99

10-
include!("../utils/dylib_util.rs");
10+
use dylib_util::{dylib_path, dylib_path_var};
1111

12-
include!("./_helper.rs");
12+
#[path = "../utils/bin_helpers.rs"]
13+
mod bin_helpers;
14+
15+
#[path = "../utils/dylib_util.rs"]
16+
mod dylib_util;
1317

1418
fn main() {
1519
let args = env::args_os().skip(1).collect::<Vec<_>>();
1620

17-
let stage = parse_rustc_stage();
18-
let verbose = parse_rustc_verbose();
21+
let stage = bin_helpers::parse_rustc_stage();
22+
let verbose = bin_helpers::parse_rustc_verbose();
1923

2024
let rustdoc = env::var_os("RUSTDOC_REAL").expect("RUSTDOC_REAL was not set");
2125
let libdir = env::var_os("RUSTDOC_LIBDIR").expect("RUSTDOC_LIBDIR was not set");

src/bootstrap/src/bins/_helper.rs renamed to src/bootstrap/src/utils/bin_helpers.rs

+7-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
1+
//! This file is meant to be included directly from bootstrap shims to avoid a
2+
//! dependency on the bootstrap library. This reduces the binary size and
3+
//! improves compilation time by reducing the linking time.
4+
15
/// Parses the value of the "RUSTC_VERBOSE" environment variable and returns it as a `usize`.
26
/// If it was not defined, returns 0 by default.
37
///
48
/// Panics if "RUSTC_VERBOSE" is defined with the value that is not an unsigned integer.
5-
fn parse_rustc_verbose() -> usize {
9+
pub(crate) fn parse_rustc_verbose() -> usize {
610
use std::str::FromStr;
711

812
match std::env::var("RUSTC_VERBOSE") {
@@ -14,11 +18,11 @@ fn parse_rustc_verbose() -> usize {
1418
/// Parses the value of the "RUSTC_STAGE" environment variable and returns it as a `String`.
1519
///
1620
/// If "RUSTC_STAGE" was not set, the program will be terminated with 101.
17-
fn parse_rustc_stage() -> String {
21+
pub(crate) fn parse_rustc_stage() -> String {
1822
std::env::var("RUSTC_STAGE").unwrap_or_else(|_| {
1923
// Don't panic here; it's reasonable to try and run these shims directly. Give a helpful error instead.
2024
eprintln!("rustc shim: fatal: RUSTC_STAGE was not set");
2125
eprintln!("rustc shim: note: use `x.py build -vvv` to see all environment variables set by bootstrap");
22-
exit(101);
26+
std::process::exit(101);
2327
})
2428
}

src/bootstrap/src/utils/dylib_util.rs

+4-7
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
1-
// Various utilities for working with dylib paths.
2-
//
3-
// This file is meant to be included directly to avoid a dependency on the bootstrap library from
4-
// the rustc and rustdoc wrappers. This improves compilation time by reducing the linking time.
1+
//! Various utilities for working with dylib paths.
52
63
/// Returns the environment variable which the dynamic library lookup path
74
/// resides in for this platform.
@@ -21,10 +18,10 @@ pub fn dylib_path_var() -> &'static str {
2118

2219
/// Parses the `dylib_path_var()` environment variable, returning a list of
2320
/// paths that are members of this lookup path.
24-
pub fn dylib_path() -> Vec<PathBuf> {
25-
let var = match env::var_os(dylib_path_var()) {
21+
pub fn dylib_path() -> Vec<std::path::PathBuf> {
22+
let var = match std::env::var_os(dylib_path_var()) {
2623
Some(v) => v,
2724
None => return vec![],
2825
};
29-
env::split_paths(&var).collect()
26+
std::env::split_paths(&var).collect()
3027
}

src/bootstrap/src/utils/helpers.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use crate::core::builder::Builder;
1616
use crate::core::config::{Config, TargetSelection};
1717
use crate::OnceCell;
1818

19-
include!("dylib_util.rs");
19+
pub use crate::utils::dylib_util::{dylib_path, dylib_path_var};
2020

2121
/// A helper macro to `unwrap` a result except also print out details like:
2222
///

src/bootstrap/src/utils/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
pub(crate) mod cache;
66
pub(crate) mod cc_detect;
77
pub(crate) mod channel;
8+
pub(crate) mod dylib_util;
89
pub(crate) mod helpers;
910
pub(crate) mod job;
1011
#[cfg(feature = "build-metrics")]

0 commit comments

Comments
 (0)