1
1
use std:: env;
2
+ use std:: path:: PathBuf ;
2
3
use std:: process;
3
4
4
5
use self :: utils:: is_ci;
@@ -13,11 +14,31 @@ mod rustc_info;
13
14
mod tests;
14
15
mod utils;
15
16
17
+ const USAGE : & str = r#"The build system of cg_clif.
18
+
19
+ USAGE:
20
+ ./y.rs prepare [--out-dir DIR]
21
+ ./y.rs build [--debug] [--sysroot none|clif|llvm] [--out-dir DIR] [--no-unstable-features]
22
+ ./y.rs test [--debug] [--sysroot none|clif|llvm] [--out-dir DIR] [--no-unstable-features]
23
+
24
+ OPTIONS:
25
+ --sysroot none|clif|llvm
26
+ Which sysroot libraries to use:
27
+ `none` will not include any standard library in the sysroot.
28
+ `clif` will build the standard library using Cranelift.
29
+ `llvm` will use the pre-compiled standard library of rustc which is compiled with LLVM.
30
+
31
+ --out-dir DIR
32
+ Specify the directory in which the download, build and dist directories are stored.
33
+ By default this is the working directory.
34
+
35
+ --no-unstable-features
36
+ fSome features are not yet ready for production usage. This option will disable these
37
+ features. This includes the JIT mode and inline assembly support.
38
+ "# ;
39
+
16
40
fn usage ( ) {
17
- eprintln ! ( "Usage:" ) ;
18
- eprintln ! ( " ./y.rs prepare" ) ;
19
- eprintln ! ( " ./y.rs build [--debug] [--sysroot none|clif|llvm] [--no-unstable-features]" ) ;
20
- eprintln ! ( " ./y.rs test [--debug] [--sysroot none|clif|llvm] [--no-unstable-features]" ) ;
41
+ eprintln ! ( "{USAGE}" ) ;
21
42
}
22
43
23
44
macro_rules! arg_error {
@@ -30,6 +51,7 @@ macro_rules! arg_error {
30
51
31
52
#[ derive( PartialEq , Debug ) ]
32
53
enum Command {
54
+ Prepare ,
33
55
Build ,
34
56
Test ,
35
57
}
@@ -45,39 +67,14 @@ pub fn main() {
45
67
env:: set_var ( "CG_CLIF_DISPLAY_CG_TIME" , "1" ) ;
46
68
env:: set_var ( "CG_CLIF_DISABLE_INCR_CACHE" , "1" ) ;
47
69
48
- let current_dir = std:: env:: current_dir ( ) . unwrap ( ) ;
49
- let dirs = path:: Dirs {
50
- source_dir : current_dir. clone ( ) ,
51
- download_dir : current_dir. join ( "download" ) ,
52
- build_dir : current_dir. join ( "build" ) ,
53
- dist_dir : current_dir. join ( "dist" ) ,
54
- } ;
55
-
56
- path:: RelPath :: BUILD . ensure_exists ( & dirs) ;
57
-
58
- {
59
- // Make sure we always explicitly specify the target dir
60
- let target =
61
- path:: RelPath :: BUILD . join ( "target_dir_should_be_set_explicitly" ) . to_path ( & dirs) ;
62
- env:: set_var ( "CARGO_TARGET_DIR" , & target) ;
63
- let _ = std:: fs:: remove_file ( & target) ;
64
- std:: fs:: File :: create ( target) . unwrap ( ) ;
65
- }
66
-
67
70
if is_ci ( ) {
68
71
// Disabling incr comp reduces cache size and incr comp doesn't save as much on CI anyway
69
72
env:: set_var ( "CARGO_BUILD_INCREMENTAL" , "false" ) ;
70
73
}
71
74
72
75
let mut args = env:: args ( ) . skip ( 1 ) ;
73
76
let command = match args. next ( ) . as_deref ( ) {
74
- Some ( "prepare" ) => {
75
- if args. next ( ) . is_some ( ) {
76
- arg_error ! ( "./y.rs prepare doesn't expect arguments" ) ;
77
- }
78
- prepare:: prepare ( & dirs) ;
79
- process:: exit ( 0 ) ;
80
- }
77
+ Some ( "prepare" ) => Command :: Prepare ,
81
78
Some ( "build" ) => Command :: Build ,
82
79
Some ( "test" ) => Command :: Test ,
83
80
Some ( flag) if flag. starts_with ( '-' ) => arg_error ! ( "Expected command found flag {}" , flag) ,
@@ -88,11 +85,17 @@ pub fn main() {
88
85
}
89
86
} ;
90
87
88
+ let mut out_dir = PathBuf :: from ( "." ) ;
91
89
let mut channel = "release" ;
92
90
let mut sysroot_kind = SysrootKind :: Clif ;
93
91
let mut use_unstable_features = true ;
94
92
while let Some ( arg) = args. next ( ) . as_deref ( ) {
95
93
match arg {
94
+ "--out-dir" => {
95
+ out_dir = PathBuf :: from ( args. next ( ) . unwrap_or_else ( || {
96
+ arg_error ! ( "--out-dir requires argument" ) ;
97
+ } ) )
98
+ }
96
99
"--debug" => channel = "debug" ,
97
100
"--sysroot" => {
98
101
sysroot_kind = match args. next ( ) . as_deref ( ) {
@@ -128,9 +131,38 @@ pub fn main() {
128
131
host_triple. clone ( )
129
132
} ;
130
133
134
+ // FIXME allow changing the location of these dirs using cli arguments
135
+ let current_dir = std:: env:: current_dir ( ) . unwrap ( ) ;
136
+ out_dir = current_dir. join ( out_dir) ;
137
+ let dirs = path:: Dirs {
138
+ source_dir : current_dir. clone ( ) ,
139
+ download_dir : out_dir. join ( "download" ) ,
140
+ build_dir : out_dir. join ( "build" ) ,
141
+ dist_dir : out_dir. join ( "dist" ) ,
142
+ } ;
143
+
144
+ path:: RelPath :: BUILD . ensure_exists ( & dirs) ;
145
+
146
+ {
147
+ // Make sure we always explicitly specify the target dir
148
+ let target =
149
+ path:: RelPath :: BUILD . join ( "target_dir_should_be_set_explicitly" ) . to_path ( & dirs) ;
150
+ env:: set_var ( "CARGO_TARGET_DIR" , & target) ;
151
+ let _ = std:: fs:: remove_file ( & target) ;
152
+ std:: fs:: File :: create ( target) . unwrap ( ) ;
153
+ }
154
+
155
+ if command == Command :: Prepare {
156
+ prepare:: prepare ( & dirs) ;
157
+ process:: exit ( 0 ) ;
158
+ }
159
+
131
160
let cg_clif_dylib =
132
161
build_backend:: build_backend ( & dirs, channel, & host_triple, use_unstable_features) ;
133
162
match command {
163
+ Command :: Prepare => {
164
+ // Handled above
165
+ }
134
166
Command :: Test => {
135
167
tests:: run_tests (
136
168
& dirs,
0 commit comments