@@ -891,6 +891,17 @@ fn get_var(var_base: &str, host: &str, target: &str) -> Option<OsString> {
891891 . or_else ( || env:: var_os ( var_base) )
892892}
893893
894+ // FIXME(offload): In an ideal world, we would just enable the offload runtime in our previous LLVM
895+ // build step. For now, we still depend on the openmp runtime since we use some of it's API, so we
896+ // build both. However, when building those runtimes as part of the LLVM step, then LLVM's cmake
897+ // implicitely assumes that Clang has also been build and will try to use it. In the Rust CI, we
898+ // don't always build clang (due to compile times), but instead use a slightly older external clang.
899+ // LLVM tries to remove this build dependency of offload/openmp on Clang for LLVM-22, so in the
900+ // future we might be able to integrate this step into the LLVM step. For now, we instead introduce
901+ // a Clang_DIR bootstrap option, which allows us tell CMake to use an external clang for these two
902+ // runtimes. This external clang will try to use it's own (older) include dirs when building our
903+ // in-tree LLVM submodule, which will cause build failures. To prevent those, we now also
904+ // explicitely set our include dirs.
894905#[ derive( Debug , Copy , Clone , Hash , PartialEq , Eq ) ]
895906pub struct OmpOffload {
896907 pub target : TargetSelection ,
@@ -918,11 +929,17 @@ impl Step for OmpOffload {
918929
919930 let LlvmResult { host_llvm_config, .. } = builder. ensure ( Llvm { target : self . target } ) ;
920931
932+ // Running cmake twice in the same folder is known to cause issues, like deleting existing
933+ // binaries. We therefore write our offload artifacts into it's own subfolder. We use a
934+ // subfolder, so that all the logic that processes our build artifacts (hopefully) also
935+ // automatically manages our artifacts in the subfolder.
921936 let out_dir = builder. llvm_out ( target) . join ( "offload-outdir" ) ;
922937 if std:: fs:: exists ( & out_dir) . is_ok_and ( |x| x == false ) {
923938 std:: fs:: DirBuilder :: new ( ) . create ( & out_dir) . unwrap ( ) ;
924939 dbg ! ( "Created out subdir!" ) ;
925940 }
941+
942+ // Offload/OpenMP are just subfolders of LLVM, so we can use the LLVM sha.
926943 static STAMP_HASH_MEMO : OnceLock < String > = OnceLock :: new ( ) ;
927944 let smart_stamp_hash = STAMP_HASH_MEMO . get_or_init ( || {
928945 generate_smart_stamp_hash (
@@ -960,32 +977,16 @@ impl Step for OmpOffload {
960977 configure_cmake ( builder, target, & mut cfg, true , LdFlags :: default ( ) , & [ ] ) ;
961978
962979 // Re-use the same flags as llvm to control the level of debug information
963- // generated by Enzyme.
964- // FIXME(ZuseZ4): Find a nicer way to use Enzyme Debug builds.
980+ // generated for offload.
965981 let profile = match ( builder. config . llvm_optimize , builder. config . llvm_release_debuginfo ) {
966982 ( false , _) => "Debug" ,
967983 ( true , false ) => "Release" ,
968984 ( true , true ) => "RelWithDebInfo" ,
969985 } ;
970986 trace ! ( ?profile) ;
971987
972- //let cc = if let Some(p) = &builder.build.config.llvm_offload_cc {
973- // //p.clone()
974- // builder.cc(target)
975- //} else {
976- // builder.cc(target)
977- //};
978- //let cxx = if let Some(p) = &builder.build.config.llvm_offload_cxx {
979- // //p.clone()
980- // builder.cxx(target).unwrap()
981- //} else {
982- // builder.cxx(target).unwrap()
983- //};
984- let root = if let Some ( p) = & builder. build . config . llvm_root_offload {
985- p. clone ( )
986- } else {
987- builder. llvm_out ( target) . join ( "build" )
988- } ;
988+ // OpenMP/Offload builds currently (LLVM-21) still depend on Clang, although there are
989+ // intentions to loosen this requirement for LLVM-22. If we were to
989990 let clang_dir = if !builder. config . llvm_clang {
990991 // We must have an external clang to use.
991992 assert ! ( & builder. build. config. llvm_clang_dir. is_some( ) ) ;
@@ -995,17 +996,18 @@ impl Step for OmpOffload {
995996 None
996997 } ;
997998
999+ // FIXME(offload): Once we move from OMP to Offload (Ol) APIs, we should drop the openmp
1000+ // runtime to simplify our build. We should also re-evaluate the LLVM_Root and try to get
1001+ // rid of the Clang_DIR, once we upgrade to LLVM-22.
9981002 cfg. out_dir ( & out_dir)
9991003 . profile ( profile)
10001004 . env ( "LLVM_CONFIG_REAL" , & host_llvm_config)
10011005 . define ( "LLVM_ENABLE_ASSERTIONS" , "ON" )
10021006 . define ( "LLVM_ENABLE_RUNTIMES" , "openmp;offload" )
10031007 . define ( "LLVM_INCLUDE_TESTS" , "OFF" )
10041008 . define ( "OFFLOAD_INCLUDE_TESTS" , "OFF" )
1005- //.define("CMAKE_C_COMPILER", cc)
1006- //.define("CMAKE_CXX_COMPILER", cxx)
10071009 . define ( "OPENMP_STANDALONE_BUILD" , "ON" )
1008- . define ( "LLVM_ROOT" , root )
1010+ . define ( "LLVM_ROOT" , builder . llvm_out ( target ) . join ( "build" ) )
10091011 . define ( "LLVM_DIR" , builder. llvm_out ( target) . join ( "lib" ) . join ( "cmake" ) . join ( "llvm" ) ) ;
10101012 if let Some ( p) = clang_dir {
10111013 cfg. define ( "Clang_DIR" , p) ;
0 commit comments