@@ -8,17 +8,15 @@ use std::process::Command;
8
8
9
9
fn main ( ) {
10
10
// Read environment variables set by cargo
11
+ let out_dir_path = env:: var ( "OUT_DIR" ) . expect ( "Missing OUT_DIR environment variable" ) ;
12
+ let out_dir = Path :: new ( & out_dir_path) ;
13
+
11
14
let cargo_path = env:: var ( "CARGO" ) . expect ( "Missing CARGO environment variable" ) ;
12
15
let cargo = Path :: new ( & cargo_path) ;
13
16
14
17
let manifest_dir_path = env:: var ( "CARGO_MANIFEST_DIR" ) . expect ( "Missing CARGO_MANIFEST_DIR environment variable" ) ;
15
18
let manifest_dir = Path :: new ( & manifest_dir_path) ;
16
19
17
- // Calculate target directory
18
- let current_dir = env:: current_dir ( ) . expect ( "Couldn't get current directory" ) ;
19
- let target_dir_rel = manifest_dir. join ( "target" ) ;
20
- let target_dir = current_dir. join ( target_dir_rel) ;
21
-
22
20
// Find the objcopy binary
23
21
let llvm_tools = LlvmTools :: new ( ) . expect ( "LLVM tools not found" ) ;
24
22
let objcopy = llvm_tools
@@ -34,8 +32,8 @@ fn main() {
34
32
"no_int13h_extensions" ,
35
33
"dap_load_failed" ,
36
34
] ,
37
- "i8086-bootsector .json" ,
38
- & target_dir ,
35
+ "../ i8086-real_mode .json" ,
36
+ & out_dir ,
39
37
& objcopy,
40
38
& cargo,
41
39
) ;
@@ -46,8 +44,8 @@ fn main() {
46
44
& [
47
45
"second_stage" ,
48
46
] ,
49
- "i8086-stage_2 .json" ,
50
- & target_dir ,
47
+ "../ i8086-real_mode .json" ,
48
+ & out_dir ,
51
49
& objcopy,
52
50
& cargo,
53
51
) ;
@@ -57,12 +55,13 @@ fn build_subproject(
57
55
subproject_dir : & Path ,
58
56
global_symbols : & [ & str ] ,
59
57
target_file_path : & str ,
60
- target_dir : & Path ,
58
+ root_out_dir : & Path ,
61
59
objcopy : & Path ,
62
60
cargo : & Path ,
63
61
) {
64
62
let subproject_name = subproject_dir. file_stem ( ) . expect ( "Couldn't get subproject name" ) . to_str ( ) . expect ( "Subproject Name is not valid UTF-8" ) ;
65
63
let target_file = Path :: new ( & target_file_path) . file_stem ( ) . expect ( "Couldn't get target file stem" ) ;
64
+ let target_dir = root_out_dir. join ( "target" ) . join ( & subproject_name) ;
66
65
67
66
// We have to export at least 1 symbol
68
67
assert ! (
@@ -82,8 +81,8 @@ fn build_subproject(
82
81
// Cross-compile core (cargo-xbuild no longer needed)
83
82
build_cmd. arg ( "-Zbuild-std=core" ) ;
84
83
85
- // Use root package target directory
86
- build_cmd. arg ( format ! ( "--target-dir={}" , & target_dir. join ( & subproject_name ) . display( ) ) ) ;
84
+ // Use calculated target directory
85
+ build_cmd. arg ( format ! ( "--target-dir={}" , & target_dir. display( ) ) ) ;
87
86
88
87
// Use the passed target
89
88
build_cmd. arg ( "--target" ) . arg ( target_file_path) ;
@@ -93,7 +92,7 @@ fn build_subproject(
93
92
assert ! ( build_status. success( ) , "Subcrate build failed!" ) ;
94
93
95
94
// Compute the path to the binary
96
- let binary_dir = target_dir. join ( & subproject_name ) . join ( & target_file) . join ( "release" ) ;
95
+ let binary_dir = target_dir. join ( & target_file) . join ( "release" ) ;
97
96
let binary_path = binary_dir. join ( format ! ( "lib{}.a" , & subproject_name) ) ;
98
97
99
98
// Use passed objcopy
0 commit comments