@@ -24,6 +24,72 @@ use crate::util::{self, exe};
24
24
use crate :: GitRepo ;
25
25
use build_helper:: up_to_date;
26
26
27
+ pub struct Meta {
28
+ stamp : HashStamp ,
29
+ build_llvm_config : PathBuf ,
30
+ out_dir : PathBuf ,
31
+ root : String ,
32
+ }
33
+
34
+ // This returns whether we've already previously built LLVM.
35
+ //
36
+ // It's used to avoid busting caches during x.py check -- if we've already built
37
+ // LLVM, it's fine for us to not try to avoid doing so.
38
+ //
39
+ // This will return the llvm-config if it can get it (but it will not build it
40
+ // if not).
41
+ pub fn prebuilt_llvm_config (
42
+ builder : & Builder < ' _ > ,
43
+ target : Interned < String > ,
44
+ ) -> Result < PathBuf , Meta > {
45
+ // If we're using a custom LLVM bail out here, but we can only use a
46
+ // custom LLVM for the build triple.
47
+ if let Some ( config) = builder. config . target_config . get ( & target) {
48
+ if let Some ( ref s) = config. llvm_config {
49
+ check_llvm_version ( builder, s) ;
50
+ return Ok ( s. to_path_buf ( ) ) ;
51
+ }
52
+ }
53
+
54
+ let root = "src/llvm-project/llvm" ;
55
+ let out_dir = builder. llvm_out ( target) ;
56
+ let mut llvm_config_ret_dir = builder. llvm_out ( builder. config . build ) ;
57
+ if !builder. config . build . contains ( "msvc" ) || builder. config . ninja {
58
+ llvm_config_ret_dir. push ( "build" ) ;
59
+ }
60
+ llvm_config_ret_dir. push ( "bin" ) ;
61
+
62
+ let build_llvm_config = llvm_config_ret_dir. join ( exe ( "llvm-config" , & * builder. config . build ) ) ;
63
+
64
+ let stamp = out_dir. join ( "llvm-finished-building" ) ;
65
+ let stamp = HashStamp :: new ( stamp, builder. in_tree_llvm_info . sha ( ) ) ;
66
+
67
+ if builder. config . llvm_skip_rebuild && stamp. path . exists ( ) {
68
+ builder. info (
69
+ "Warning: \
70
+ Using a potentially stale build of LLVM; \
71
+ This may not behave well.",
72
+ ) ;
73
+ return Ok ( build_llvm_config) ;
74
+ }
75
+
76
+ if stamp. is_done ( ) {
77
+ if stamp. hash . is_none ( ) {
78
+ builder. info (
79
+ "Could not determine the LLVM submodule commit hash. \
80
+ Assuming that an LLVM rebuild is not necessary.",
81
+ ) ;
82
+ builder. info ( & format ! (
83
+ "To force LLVM to rebuild, remove the file `{}`" ,
84
+ stamp. path. display( )
85
+ ) ) ;
86
+ }
87
+ return Ok ( build_llvm_config) ;
88
+ }
89
+
90
+ Err ( Meta { stamp, build_llvm_config, out_dir, root : root. into ( ) } )
91
+ }
92
+
27
93
#[ derive( Debug , Copy , Clone , Hash , PartialEq , Eq ) ]
28
94
pub struct Llvm {
29
95
pub target : Interned < String > ,
@@ -46,51 +112,11 @@ impl Step for Llvm {
46
112
fn run ( self , builder : & Builder < ' _ > ) -> PathBuf {
47
113
let target = self . target ;
48
114
49
- // If we're using a custom LLVM bail out here, but we can only use a
50
- // custom LLVM for the build triple.
51
- if let Some ( config) = builder. config . target_config . get ( & target) {
52
- if let Some ( ref s) = config. llvm_config {
53
- check_llvm_version ( builder, s) ;
54
- return s. to_path_buf ( ) ;
55
- }
56
- }
57
-
58
- let root = "src/llvm-project/llvm" ;
59
- let out_dir = builder. llvm_out ( target) ;
60
- let mut llvm_config_ret_dir = builder. llvm_out ( builder. config . build ) ;
61
- if !builder. config . build . contains ( "msvc" ) || builder. config . ninja {
62
- llvm_config_ret_dir. push ( "build" ) ;
63
- }
64
- llvm_config_ret_dir. push ( "bin" ) ;
65
-
66
- let build_llvm_config =
67
- llvm_config_ret_dir. join ( exe ( "llvm-config" , & * builder. config . build ) ) ;
68
-
69
- let stamp = out_dir. join ( "llvm-finished-building" ) ;
70
- let stamp = HashStamp :: new ( stamp, builder. in_tree_llvm_info . sha ( ) ) ;
71
-
72
- if builder. config . llvm_skip_rebuild && stamp. path . exists ( ) {
73
- builder. info (
74
- "Warning: \
75
- Using a potentially stale build of LLVM; \
76
- This may not behave well.",
77
- ) ;
78
- return build_llvm_config;
79
- }
80
-
81
- if stamp. is_done ( ) {
82
- if stamp. hash . is_none ( ) {
83
- builder. info (
84
- "Could not determine the LLVM submodule commit hash. \
85
- Assuming that an LLVM rebuild is not necessary.",
86
- ) ;
87
- builder. info ( & format ! (
88
- "To force LLVM to rebuild, remove the file `{}`" ,
89
- stamp. path. display( )
90
- ) ) ;
91
- }
92
- return build_llvm_config;
93
- }
115
+ let Meta { stamp, build_llvm_config, out_dir, root } =
116
+ match prebuilt_llvm_config ( builder, target) {
117
+ Ok ( p) => return p,
118
+ Err ( m) => m,
119
+ } ;
94
120
95
121
builder. info ( & format ! ( "Building LLVM for {}" , target) ) ;
96
122
t ! ( stamp. remove( ) ) ;
0 commit comments