Skip to content

Commit

Permalink
re-organize binary related modules
Browse files Browse the repository at this point in the history
Signed-off-by: onur-ozkan <work@onurozkan.dev>
  • Loading branch information
onur-ozkan committed Oct 7, 2023
1 parent 4166849 commit fc4fb8c
Show file tree
Hide file tree
Showing 9 changed files with 37 additions and 26 deletions.
8 changes: 4 additions & 4 deletions src/bootstrap/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,22 @@ doctest = false

[[bin]]
name = "bootstrap"
path = "src/bins/main.rs"
path = "src/bin/main.rs"
test = false

[[bin]]
name = "rustc"
path = "src/bins/rustc.rs"
path = "src/bin/rustc.rs"
test = false

[[bin]]
name = "rustdoc"
path = "src/bins/rustdoc.rs"
path = "src/bin/rustdoc.rs"
test = false

[[bin]]
name = "sccache-plus-cl"
path = "src/bins/sccache-plus-cl.rs"
path = "src/bin/sccache-plus-cl.rs"
test = false

[dependencies]
Expand Down
File renamed without changes.
17 changes: 11 additions & 6 deletions src/bootstrap/src/bins/rustc.rs → src/bootstrap/src/bin/rustc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,25 @@
//! switching compilers for the bootstrap and for build scripts will probably
//! never get replaced.

include!("../utils/dylib_util.rs");
include!("./_helper.rs");

use std::env;
use std::path::PathBuf;
use std::process::{exit, Child, Command};
use std::process::{Child, Command};
use std::time::Instant;

use dylib_util::{dylib_path, dylib_path_var};

#[path = "../utils/bin_helpers.rs"]
mod bin_helpers;

#[path = "../utils/dylib_util.rs"]
mod dylib_util;

fn main() {
let args = env::args_os().skip(1).collect::<Vec<_>>();
let arg = |name| args.windows(2).find(|args| args[0] == name).and_then(|args| args[1].to_str());

let stage = parse_rustc_stage();
let verbose = parse_rustc_verbose();
let stage = bin_helpers::parse_rustc_stage();
let verbose = bin_helpers::parse_rustc_verbose();

// Detect whether or not we're a build script depending on whether --target
// is passed (a bit janky...)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,21 @@
use std::env;
use std::ffi::OsString;
use std::path::PathBuf;
use std::process::{exit, Command};
use std::process::Command;

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

include!("./_helper.rs");
#[path = "../utils/bin_helpers.rs"]
mod bin_helpers;

#[path = "../utils/dylib_util.rs"]
mod dylib_util;

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

let stage = parse_rustc_stage();
let verbose = parse_rustc_verbose();
let stage = bin_helpers::parse_rustc_stage();
let verbose = bin_helpers::parse_rustc_verbose();

let rustdoc = env::var_os("RUSTDOC_REAL").expect("RUSTDOC_REAL was not set");
let libdir = env::var_os("RUSTDOC_LIBDIR").expect("RUSTDOC_LIBDIR was not set");
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
//! This file is meant to be included directly from bootstrap shims to avoid a
//! dependency on the bootstrap library. This reduces the binary size and
//! improves compilation time by reducing the linking time.

/// Parses the value of the "RUSTC_VERBOSE" environment variable and returns it as a `usize`.
/// If it was not defined, returns 0 by default.
///
/// Panics if "RUSTC_VERBOSE" is defined with the value that is not an unsigned integer.
fn parse_rustc_verbose() -> usize {
pub(crate) fn parse_rustc_verbose() -> usize {
use std::str::FromStr;

match std::env::var("RUSTC_VERBOSE") {
Expand All @@ -14,11 +18,11 @@ fn parse_rustc_verbose() -> usize {
/// Parses the value of the "RUSTC_STAGE" environment variable and returns it as a `String`.
///
/// If "RUSTC_STAGE" was not set, the program will be terminated with 101.
fn parse_rustc_stage() -> String {
pub(crate) fn parse_rustc_stage() -> String {
std::env::var("RUSTC_STAGE").unwrap_or_else(|_| {
// Don't panic here; it's reasonable to try and run these shims directly. Give a helpful error instead.
eprintln!("rustc shim: fatal: RUSTC_STAGE was not set");
eprintln!("rustc shim: note: use `x.py build -vvv` to see all environment variables set by bootstrap");
exit(101);
std::process::exit(101);
})
}
11 changes: 4 additions & 7 deletions src/bootstrap/src/utils/dylib_util.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
// Various utilities for working with dylib paths.
//
// This file is meant to be included directly to avoid a dependency on the bootstrap library from
// the rustc and rustdoc wrappers. This improves compilation time by reducing the linking time.
//! Various utilities for working with dylib paths.

/// Returns the environment variable which the dynamic library lookup path
/// resides in for this platform.
Expand All @@ -21,10 +18,10 @@ pub fn dylib_path_var() -> &'static str {

/// Parses the `dylib_path_var()` environment variable, returning a list of
/// paths that are members of this lookup path.
pub fn dylib_path() -> Vec<PathBuf> {
let var = match env::var_os(dylib_path_var()) {
pub fn dylib_path() -> Vec<std::path::PathBuf> {
let var = match std::env::var_os(dylib_path_var()) {
Some(v) => v,
None => return vec![],
};
env::split_paths(&var).collect()
std::env::split_paths(&var).collect()
}
2 changes: 1 addition & 1 deletion src/bootstrap/src/utils/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use crate::core::builder::Builder;
use crate::core::config::{Config, TargetSelection};
use crate::OnceCell;

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

/// A helper macro to `unwrap` a result except also print out details like:
///
Expand Down
1 change: 1 addition & 0 deletions src/bootstrap/src/utils/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
pub(crate) mod cache;
pub(crate) mod cc_detect;
pub(crate) mod channel;
pub(crate) mod dylib_util;
pub(crate) mod helpers;
pub(crate) mod job;
#[cfg(feature = "build-metrics")]
Expand Down

0 comments on commit fc4fb8c

Please sign in to comment.