@@ -15,7 +15,9 @@ use std::sync::OnceLock;
15
15
use std:: { env, fs} ;
16
16
17
17
use build_helper:: ci:: CiEnv ;
18
- use build_helper:: git:: get_closest_merge_commit;
18
+ use build_helper:: git:: { PathFreshness , check_path_modifications} ;
19
+ #[ cfg( feature = "tracing" ) ]
20
+ use tracing:: instrument;
19
21
20
22
use crate :: core:: builder:: { Builder , RunConfig , ShouldRun , Step } ;
21
23
use crate :: core:: config:: { Config , TargetSelection } ;
@@ -24,7 +26,7 @@ use crate::utils::exec::command;
24
26
use crate :: utils:: helpers:: {
25
27
self , exe, get_clang_cl_resource_dir, t, unhashed_basename, up_to_date,
26
28
} ;
27
- use crate :: { CLang , GitRepo , Kind } ;
29
+ use crate :: { CLang , GitRepo , Kind , trace } ;
28
30
29
31
#[ derive( Clone ) ]
30
32
pub struct LlvmResult {
@@ -172,35 +174,38 @@ pub fn prebuilt_llvm_config(
172
174
LlvmBuildStatus :: ShouldBuild ( Meta { stamp, res, out_dir, root : root. into ( ) } )
173
175
}
174
176
175
- /// This retrieves the LLVM sha we *want* to use, according to git history.
176
- pub ( crate ) fn detect_llvm_sha ( config : & Config , is_git : bool ) -> String {
177
- let llvm_sha = if is_git {
178
- get_closest_merge_commit (
179
- Some ( & config. src ) ,
180
- & config. git_config ( ) ,
181
- & [
182
- config. src . join ( "src/llvm-project" ) ,
183
- config. src . join ( "src/bootstrap/download-ci-llvm-stamp" ) ,
184
- // the LLVM shared object file is named `LLVM-12-rust-{version}-nightly`
185
- config. src . join ( "src/version" ) ,
186
- ] ,
177
+ /// Detect whether LLVM sources have been modified locally or not.
178
+ pub ( crate ) fn detect_llvm_freshness ( config : & Config , is_git : bool ) -> PathFreshness {
179
+ let freshness = if is_git {
180
+ Some (
181
+ check_path_modifications (
182
+ Some ( & config. src ) ,
183
+ & config. git_config ( ) ,
184
+ & [
185
+ "src/llvm-project" ,
186
+ "src/bootstrap/download-ci-llvm-stamp" ,
187
+ // the LLVM shared object file is named `LLVM-12-rust-{version}-nightly`
188
+ "src/version" ,
189
+ ] ,
190
+ CiEnv :: current ( ) ,
191
+ )
192
+ . unwrap ( ) ,
187
193
)
188
- . unwrap ( )
189
194
} else if let Some ( info) = crate :: utils:: channel:: read_commit_info_file ( & config. src ) {
190
- info. sha . trim ( ) . to_owned ( )
195
+ Some ( PathFreshness :: LastModifiedUpstream { upstream : info. sha . trim ( ) . to_owned ( ) } )
191
196
} else {
192
- "" . to_owned ( )
197
+ None
193
198
} ;
194
199
195
- if llvm_sha . is_empty ( ) {
200
+ let Some ( freshness ) = freshness else {
196
201
eprintln ! ( "error: could not find commit hash for downloading LLVM" ) ;
197
202
eprintln ! ( "HELP: maybe your repository history is too shallow?" ) ;
198
203
eprintln ! ( "HELP: consider disabling `download-ci-llvm`" ) ;
199
204
eprintln ! ( "HELP: or fetch enough history to include one upstream commit" ) ;
200
205
panic ! ( ) ;
201
- }
206
+ } ;
202
207
203
- llvm_sha
208
+ freshness
204
209
}
205
210
206
211
/// Returns whether the CI-found LLVM is currently usable.
@@ -280,12 +285,7 @@ pub(crate) fn is_ci_llvm_modified(config: &Config) -> bool {
280
285
return false ;
281
286
}
282
287
283
- let llvm_sha = detect_llvm_sha ( config, true ) ;
284
- let head_sha = crate :: output (
285
- helpers:: git ( Some ( & config. src ) ) . arg ( "rev-parse" ) . arg ( "HEAD" ) . as_command_mut ( ) ,
286
- ) ;
287
- let head_sha = head_sha. trim ( ) ;
288
- llvm_sha == head_sha
288
+ matches ! ( detect_llvm_freshness( config, true ) , PathFreshness :: HasLocalModifications { .. } )
289
289
}
290
290
291
291
#[ derive( Debug , Clone , Hash , PartialEq , Eq ) ]
@@ -469,6 +469,10 @@ impl Step for Llvm {
469
469
cfg. define ( "LLVM_BUILD_32_BITS" , "ON" ) ;
470
470
}
471
471
472
+ if target. starts_with ( "x86_64" ) && target. contains ( "ohos" ) {
473
+ cfg. define ( "LLVM_TOOL_LLVM_RTDYLD_BUILD" , "OFF" ) ;
474
+ }
475
+
472
476
let mut enabled_llvm_projects = Vec :: new ( ) ;
473
477
474
478
if helpers:: forcing_clang_based_tests ( ) {
@@ -516,7 +520,7 @@ impl Step for Llvm {
516
520
}
517
521
518
522
// https://llvm.org/docs/HowToCrossCompileLLVM.html
519
- if !builder. is_builder_target ( & target) {
523
+ if !builder. is_builder_target ( target) {
520
524
let LlvmResult { llvm_config, .. } =
521
525
builder. ensure ( Llvm { target : builder. config . build } ) ;
522
526
if !builder. config . dry_run ( ) {
@@ -668,7 +672,7 @@ fn configure_cmake(
668
672
}
669
673
cfg. target ( & target. triple ) . host ( & builder. config . build . triple ) ;
670
674
671
- if !builder. is_builder_target ( & target) {
675
+ if !builder. is_builder_target ( target) {
672
676
cfg. define ( "CMAKE_CROSSCOMPILING" , "True" ) ;
673
677
674
678
if target. contains ( "netbsd" ) {
@@ -733,57 +737,17 @@ fn configure_cmake(
733
737
None => ( builder. cc ( target) , builder. cxx ( target) . unwrap ( ) ) ,
734
738
} ;
735
739
736
- // Handle msvc + ninja + ccache specially (this is what the bots use)
737
- if target. is_msvc ( ) && builder. ninja ( ) && builder. config . ccache . is_some ( ) {
738
- let mut wrap_cc = env:: current_exe ( ) . expect ( "failed to get cwd" ) ;
739
- wrap_cc. set_file_name ( "sccache-plus-cl.exe" ) ;
740
-
741
- cfg. define ( "CMAKE_C_COMPILER" , sanitize_cc ( & wrap_cc) )
742
- . define ( "CMAKE_CXX_COMPILER" , sanitize_cc ( & wrap_cc) ) ;
743
- cfg. env ( "SCCACHE_PATH" , builder. config . ccache . as_ref ( ) . unwrap ( ) )
744
- . env ( "SCCACHE_TARGET" , target. triple )
745
- . env ( "SCCACHE_CC" , & cc)
746
- . env ( "SCCACHE_CXX" , & cxx) ;
747
-
748
- // Building LLVM on MSVC can be a little ludicrous at times. We're so far
749
- // off the beaten path here that I'm not really sure this is even half
750
- // supported any more. Here we're trying to:
751
- //
752
- // * Build LLVM on MSVC
753
- // * Build LLVM with `clang-cl` instead of `cl.exe`
754
- // * Build a project with `sccache`
755
- // * Build for 32-bit as well
756
- // * Build with Ninja
757
- //
758
- // For `cl.exe` there are different binaries to compile 32/64 bit which
759
- // we use but for `clang-cl` there's only one which internally
760
- // multiplexes via flags. As a result it appears that CMake's detection
761
- // of a compiler's architecture and such on MSVC **doesn't** pass any
762
- // custom flags we pass in CMAKE_CXX_FLAGS below. This means that if we
763
- // use `clang-cl.exe` it's always diagnosed as a 64-bit compiler which
764
- // definitely causes problems since all the env vars are pointing to
765
- // 32-bit libraries.
766
- //
767
- // To hack around this... again... we pass an argument that's
768
- // unconditionally passed in the sccache shim. This'll get CMake to
769
- // correctly diagnose it's doing a 32-bit compilation and LLVM will
770
- // internally configure itself appropriately.
771
- if builder. config . llvm_clang_cl . is_some ( ) && target. contains ( "i686" ) {
772
- cfg. env ( "SCCACHE_EXTRA_ARGS" , "-m32" ) ;
740
+ // If ccache is configured we inform the build a little differently how
741
+ // to invoke ccache while also invoking our compilers.
742
+ if use_compiler_launcher {
743
+ if let Some ( ref ccache) = builder. config . ccache {
744
+ cfg. define ( "CMAKE_C_COMPILER_LAUNCHER" , ccache)
745
+ . define ( "CMAKE_CXX_COMPILER_LAUNCHER" , ccache) ;
773
746
}
774
- } else {
775
- // If ccache is configured we inform the build a little differently how
776
- // to invoke ccache while also invoking our compilers.
777
- if use_compiler_launcher {
778
- if let Some ( ref ccache) = builder. config . ccache {
779
- cfg. define ( "CMAKE_C_COMPILER_LAUNCHER" , ccache)
780
- . define ( "CMAKE_CXX_COMPILER_LAUNCHER" , ccache) ;
781
- }
782
- }
783
- cfg. define ( "CMAKE_C_COMPILER" , sanitize_cc ( & cc) )
784
- . define ( "CMAKE_CXX_COMPILER" , sanitize_cc ( & cxx) )
785
- . define ( "CMAKE_ASM_COMPILER" , sanitize_cc ( & cc) ) ;
786
747
}
748
+ cfg. define ( "CMAKE_C_COMPILER" , sanitize_cc ( & cc) )
749
+ . define ( "CMAKE_CXX_COMPILER" , sanitize_cc ( & cxx) )
750
+ . define ( "CMAKE_ASM_COMPILER" , sanitize_cc ( & cc) ) ;
787
751
788
752
cfg. build_arg ( "-j" ) . build_arg ( builder. jobs ( ) . to_string ( ) ) ;
789
753
// FIXME(madsmtm): Allow `cmake-rs` to select flags by itself by passing
@@ -807,7 +771,9 @@ fn configure_cmake(
807
771
cflags. push ( " " ) ;
808
772
cflags. push ( s) ;
809
773
}
810
-
774
+ if target. contains ( "ohos" ) {
775
+ cflags. push ( " -D_LINUX_SYSINFO_H" ) ;
776
+ }
811
777
if builder. config . llvm_clang_cl . is_some ( ) {
812
778
cflags. push ( format ! ( " --target={target}" ) ) ;
813
779
}
@@ -828,6 +794,9 @@ fn configure_cmake(
828
794
cxxflags. push ( " " ) ;
829
795
cxxflags. push ( s) ;
830
796
}
797
+ if target. contains ( "ohos" ) {
798
+ cxxflags. push ( " -D_LINUX_SYSINFO_H" ) ;
799
+ }
831
800
if builder. config . llvm_clang_cl . is_some ( ) {
832
801
cxxflags. push ( format ! ( " --target={target}" ) ) ;
833
802
}
@@ -934,6 +903,15 @@ impl Step for Enzyme {
934
903
}
935
904
936
905
/// Compile Enzyme for `target`.
906
+ #[ cfg_attr(
907
+ feature = "tracing" ,
908
+ instrument(
909
+ level = "debug" ,
910
+ name = "Enzyme::run" ,
911
+ skip_all,
912
+ fields( target = ?self . target) ,
913
+ ) ,
914
+ ) ]
937
915
fn run ( self , builder : & Builder < ' _ > ) -> PathBuf {
938
916
builder. require_submodule (
939
917
"src/tools/enzyme" ,
@@ -959,7 +937,9 @@ impl Step for Enzyme {
959
937
let out_dir = builder. enzyme_out ( target) ;
960
938
let stamp = BuildStamp :: new ( & out_dir) . with_prefix ( "enzyme" ) . add_stamp ( smart_stamp_hash) ;
961
939
940
+ trace ! ( "checking build stamp to see if we need to rebuild enzyme artifacts" ) ;
962
941
if stamp. is_up_to_date ( ) {
942
+ trace ! ( ?out_dir, "enzyme build artifacts are up to date" ) ;
963
943
if stamp. stamp ( ) . is_empty ( ) {
964
944
builder. info (
965
945
"Could not determine the Enzyme submodule commit hash. \
@@ -973,6 +953,7 @@ impl Step for Enzyme {
973
953
return out_dir;
974
954
}
975
955
956
+ trace ! ( ?target, "(re)building enzyme artifacts" ) ;
976
957
builder. info ( & format ! ( "Building Enzyme for {}" , target) ) ;
977
958
t ! ( stamp. remove( ) ) ;
978
959
let _time = helpers:: timeit ( builder) ;
@@ -982,25 +963,23 @@ impl Step for Enzyme {
982
963
. config
983
964
. update_submodule ( Path :: new ( "src" ) . join ( "tools" ) . join ( "enzyme" ) . to_str ( ) . unwrap ( ) ) ;
984
965
let mut cfg = cmake:: Config :: new ( builder. src . join ( "src/tools/enzyme/enzyme/" ) ) ;
985
- // FIXME(ZuseZ4): Find a nicer way to use Enzyme Debug builds
986
- //cfg.profile("Debug");
987
- //cfg.define("CMAKE_BUILD_TYPE", "Debug");
988
966
configure_cmake ( builder, target, & mut cfg, true , LdFlags :: default ( ) , & [ ] ) ;
989
967
990
968
// Re-use the same flags as llvm to control the level of debug information
991
- // generated for lld.
969
+ // generated by Enzyme.
970
+ // FIXME(ZuseZ4): Find a nicer way to use Enzyme Debug builds.
992
971
let profile = match ( builder. config . llvm_optimize , builder. config . llvm_release_debuginfo ) {
993
972
( false , _) => "Debug" ,
994
973
( true , false ) => "Release" ,
995
974
( true , true ) => "RelWithDebInfo" ,
996
975
} ;
976
+ trace ! ( ?profile) ;
997
977
998
978
cfg. out_dir ( & out_dir)
999
979
. profile ( profile)
1000
980
. env ( "LLVM_CONFIG_REAL" , & llvm_config)
1001
981
. define ( "LLVM_ENABLE_ASSERTIONS" , "ON" )
1002
982
. define ( "ENZYME_EXTERNAL_SHARED_LIB" , "ON" )
1003
- . define ( "ENZYME_RUNPASS" , "ON" )
1004
983
. define ( "LLVM_DIR" , builder. llvm_out ( target) ) ;
1005
984
1006
985
cfg. build ( ) ;
@@ -1118,7 +1097,7 @@ impl Step for Lld {
1118
1097
. define ( "LLVM_CMAKE_DIR" , llvm_cmake_dir)
1119
1098
. define ( "LLVM_INCLUDE_TESTS" , "OFF" ) ;
1120
1099
1121
- if !builder. is_builder_target ( & target) {
1100
+ if !builder. is_builder_target ( target) {
1122
1101
// Use the host llvm-tblgen binary.
1123
1102
cfg. define (
1124
1103
"LLVM_TABLEGEN_EXE" ,
@@ -1204,6 +1183,10 @@ impl Step for Sanitizers {
1204
1183
cfg. define ( "COMPILER_RT_USE_LIBCXX" , "OFF" ) ;
1205
1184
cfg. define ( "LLVM_CONFIG_PATH" , & llvm_config) ;
1206
1185
1186
+ if self . target . contains ( "ohos" ) {
1187
+ cfg. define ( "COMPILER_RT_USE_BUILTINS_LIBRARY" , "ON" ) ;
1188
+ }
1189
+
1207
1190
// On Darwin targets the sanitizer runtimes are build as universal binaries.
1208
1191
// Unfortunately sccache currently lacks support to build them successfully.
1209
1192
// Disable compiler launcher on Darwin targets to avoid potential issues.
0 commit comments