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