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.
1
+ //! This module serves two purposes:
2
+ //! 1. It is part of the `utils` module and used in other parts of bootstrap.
3
+ //! 2. It is embedded inside bootstrap shims to avoid a dependency on the bootstrap library.
4
+ //! Therefore, this module should never use any other bootstrap module. This reduces binary
5
+ //! size and improves compilation time by minimizing linking time.
6
+
7
+ #![ allow( dead_code) ]
4
8
5
9
use std:: env;
10
+ use std:: ffi:: OsString ;
6
11
use std:: fs:: OpenOptions ;
7
12
use std:: io:: Write ;
8
13
use std:: process:: Command ;
9
14
use std:: str:: FromStr ;
10
15
16
+ #[ cfg( test) ]
17
+ mod tests;
18
+
19
+ /// Returns the environment variable which the dynamic library lookup path
20
+ /// resides in for this platform.
21
+ pub fn dylib_path_var ( ) -> & ' static str {
22
+ if cfg ! ( target_os = "windows" ) {
23
+ "PATH"
24
+ } else if cfg ! ( target_vendor = "apple" ) {
25
+ "DYLD_LIBRARY_PATH"
26
+ } else if cfg ! ( target_os = "haiku" ) {
27
+ "LIBRARY_PATH"
28
+ } else if cfg ! ( target_os = "aix" ) {
29
+ "LIBPATH"
30
+ } else {
31
+ "LD_LIBRARY_PATH"
32
+ }
33
+ }
34
+
35
+ /// Parses the `dylib_path_var()` environment variable, returning a list of
36
+ /// paths that are members of this lookup path.
37
+ pub fn dylib_path ( ) -> Vec < std:: path:: PathBuf > {
38
+ let var = match std:: env:: var_os ( dylib_path_var ( ) ) {
39
+ Some ( v) => v,
40
+ None => return vec ! [ ] ,
41
+ } ;
42
+ std:: env:: split_paths ( & var) . collect ( )
43
+ }
44
+
45
+ /// Given an executable called `name`, return the filename for the
46
+ /// executable for a particular target.
47
+ #[ allow( dead_code) ]
48
+ pub fn exe ( name : & str , target : & str ) -> String {
49
+ if target. contains ( "windows" ) {
50
+ format ! ( "{name}.exe" )
51
+ } else if target. contains ( "uefi" ) {
52
+ format ! ( "{name}.efi" )
53
+ } else {
54
+ name. to_string ( )
55
+ }
56
+ }
57
+
11
58
/// Parses the value of the "RUSTC_VERBOSE" environment variable and returns it as a `usize`.
12
59
/// If it was not defined, returns 0 by default.
13
60
///
14
61
/// Panics if "RUSTC_VERBOSE" is defined with the value that is not an unsigned integer.
15
- pub ( crate ) fn parse_rustc_verbose ( ) -> usize {
62
+ pub fn parse_rustc_verbose ( ) -> usize {
16
63
match env:: var ( "RUSTC_VERBOSE" ) {
17
64
Ok ( s) => usize:: from_str ( & s) . expect ( "RUSTC_VERBOSE should be an integer" ) ,
18
65
Err ( _) => 0 ,
@@ -22,7 +69,7 @@ pub(crate) fn parse_rustc_verbose() -> usize {
22
69
/// Parses the value of the "RUSTC_STAGE" environment variable and returns it as a `String`.
23
70
///
24
71
/// If "RUSTC_STAGE" was not set, the program will be terminated with 101.
25
- pub ( crate ) fn parse_rustc_stage ( ) -> String {
72
+ pub fn parse_rustc_stage ( ) -> String {
26
73
env:: var ( "RUSTC_STAGE" ) . unwrap_or_else ( |_| {
27
74
// Don't panic here; it's reasonable to try and run these shims directly. Give a helpful error instead.
28
75
eprintln ! ( "rustc shim: FATAL: RUSTC_STAGE was not set" ) ;
@@ -35,7 +82,7 @@ pub(crate) fn parse_rustc_stage() -> String {
35
82
///
36
83
/// Before writing it, replaces user-specific values to create generic dumps for cross-environment
37
84
/// comparisons.
38
- pub ( crate ) fn maybe_dump ( dump_name : String , cmd : & Command ) {
85
+ pub fn maybe_dump ( dump_name : String , cmd : & Command ) {
39
86
if let Ok ( dump_dir) = env:: var ( "DUMP_BOOTSTRAP_SHIMS" ) {
40
87
let dump_file = format ! ( "{dump_dir}/{dump_name}" ) ;
41
88
0 commit comments