1616 * Author(s): David Krasowska <krasow@u.northwestern.edu>
1717 * Ethan Meitz <emeitz@andrew.cmu.edu>
1818=#
19+ using Pkg
1920using Preferences
2021using LegatePreferences
2122
23+ include (" buildtools/dev_tools.jl" )
2224include (" version.jl" )
2325
24- # Automatically pipes errors to new file
25- # and appends stdout to build.log
26- function run_sh (cmd:: Cmd , filename:: String )
27- println (cmd)
28-
29- build_log = joinpath (@__DIR__ , " build.log" )
30- tmp_build_log = joinpath (@__DIR__ , " $(filename) .log" )
31- err_log = joinpath (@__DIR__ , " $(filename) .err" )
32-
33- if isfile (err_log)
34- rm (err_log)
35- end
36-
37- if isfile (tmp_build_log)
38- rm (tmp_build_log)
39- end
40-
41- try
42- run (pipeline (cmd; stdout = tmp_build_log, stderr = err_log, append= false ))
43- contents = read (tmp_build_log, String)
44- open (build_log, " a" ) do io
45- println (contents)
46- end
47- catch e
48- println (" stderr log generated: " , err_log, ' \n ' )
49- contents = read (err_log, String)
50- if ! isempty (strip (contents))
51- println (" ---- Begin stderr log ----" )
52- println (contents)
53- println (" ---- End stderr log ----" )
54- end
55- end
56- end
57-
5826# patch legion. The readme below talks about our compilation error
5927# https://github.com/ejmeitz/cuNumeric.jl/blob/main/scripts/README.md
6028function patch_legion (repo_root:: String , legate_root:: String )
6129 if ! check_if_patch (legate_root)
6230 legion_patch = joinpath (repo_root, " scripts/patch_legion.sh" )
6331 @info " Legate.jl: Running legion patch script: $legion_patch "
64- run_sh (` bash $legion_patch $repo_root $legate_root ` , " legion_patch" )
65- end
66- end
67-
68- function build_jlcxxwrap (repo_root, legate_root)
69- build_libcxxwrap = joinpath (repo_root, " scripts/install_cxxwrap.sh" )
70- version_path = joinpath (DEPOT_PATH [1 ], " dev/libcxxwrap_julia_jll/override/LEGATE_INSTALL.txt" )
71- if isfile (version_path)
72- version = VersionNumber (strip (read (version_path, String)))
73- @info " libcxxwrap: Found Legate $version "
74- if is_supported_version (version)
75- @info " libcxxwrap: Found supported version built with Legate.jl: $version "
76- return nothing
77- else
78- @info " libcxxwrap: Unsupported version found: $version . Rebuilding..."
79- end
80- else
81- @info " libcxxwrap: No version file found. Starting build..."
82- end
83-
84- @info " libcxxwrap: Running build script: $build_libcxxwrap "
85- run_sh (` bash $build_libcxxwrap $repo_root ` , " libcxxwrap" )
86- open (version_path, " w" ) do io
87- write (io, string (get_legate_version (legate_root)))
32+ BuildTools. run_sh (
33+ ` bash $legion_patch $repo_root $legate_root ` , " legion_patch" ; log_dir= @__DIR__
34+ )
8835 end
8936end
9037
91- function build_cpp_wrapper (repo_root, legate_root, install_root)
38+ function build_cpp_wrapper (
39+ repo_root, legate_root, install_root; cuda_root= nothing , cuda_enabled= true
40+ )
9241 @info " liblegatewrapper: Building C++ Wrapper Library"
93- if isdir (install_root)
94- rm (install_root; recursive= true )
95- mkdir (install_root)
96- end
97-
98- build_cpp_wrapper = joinpath (repo_root, " scripts/build_cpp_wrapper.sh" )
99- nthreads = Threads. nthreads ()
100-
101- bld_command = ` $build_cpp_wrapper $repo_root $legate_root $install_root $nthreads `
102-
103- # write out a bash script for debugging
104- cmd_str = join (bld_command. exec, " " )
105- wrapper_path = joinpath (repo_root, " build_wrapper.sh" )
106- open (wrapper_path, " w" ) do io
107- println (io, " #!/bin/bash" )
108- println (io, " set -xe" )
109- println (io, cmd_str)
110- end
111- chmod (wrapper_path, 0o755 )
112-
113- @info " Running build command: $bld_command "
114- run_sh (` bash $bld_command ` , " cpp_wrapper" )
115- end
116-
117- function _find_jll_artifact_dir (jll)
118- eval (:(using $ (jll)))
119- jll_mod = getfield (Main, jll)
120- root = jll_mod. artifact_dir
121- return root
42+ isdir (install_root) && (rm (install_root; recursive= true ); mkdir (install_root))
43+ bld_command = ` $(joinpath (repo_root, " scripts/build_cpp_wrapper.sh" )) $repo_root $legate_root $install_root $(Threads. nthreads ()) `
44+ BuildTools. run_build_wrapper_script (
45+ repo_root, bld_command; cuda_root, cuda_enabled, log_dir= @__DIR__
46+ )
12247end
12348
124- function _start_build ()
125- pkg_root = up_dir (@__DIR__ )
126- deps_dir = joinpath (@__DIR__ )
127-
128- build_log = joinpath (deps_dir, " build.log" )
129- open (build_log, " w" ) do io
130- println (io, " === Build started ===" )
131- end
132-
133- @info " Legate.jl: Parsed Package Dir as: $(pkg_root) "
134- return pkg_root
135- end
136-
137- """
138- build CxxWrap and legate_jl_wrapper
139- """
140- function build_deps (pkg_root, legate_root)
49+ function build_deps (pkg_root, legate_root; cuda_root= nothing , cuda_enabled= true )
50+ BuildTools. check_cmake_version (MIN_CMAKE_VERSION)
14151 install_dir = joinpath (pkg_root, " lib" , " legate_jl_wrapper" , " build" )
14252 if ! legate_valid (legate_root)
14353 error (
14454 " Legate.jl: Unsupported Legate version at $(legate_root) . " *
145- " Installed version: $(installed_version ) not in range supported: " *
55+ " Installed version: $(get_legate_version (legate_root) ) not in range supported: " *
14656 " $(MIN_LEGATE_VERSION) -$(MAX_LEGATE_VERSION) ." ,
14757 )
14858 end
149- build_jlcxxwrap (pkg_root, legate_root) # $pkg_root/lib/libcxxwrap-julia
150- build_cpp_wrapper (pkg_root, legate_root, install_dir) # $pkg_root/lib/legate_jl_wrapper
59+ BuildTools. build_jlcxxwrap (
60+ pkg_root, get_legate_version (legate_root);
61+ log_dir= @__DIR__ , is_compatible= is_supported_version,
62+ )
63+ build_cpp_wrapper (pkg_root, legate_root, install_dir; cuda_root, cuda_enabled)
64+ BuildTools. set_jll_artifact_override (:legate_jl_wrapper_jll , install_dir)
15165end
15266
15367function build (:: LegatePreferences.JLL )
15771
15872function build (:: LegatePreferences.Conda )
15973 @warn " Conda Build does not currently pass our CI. Proceed with caution."
160- pkg_root = _start_build ( )
74+ pkg_root = BuildTools . start_build ( " Legate.jl " , @__DIR__ )
16175
16276 legate_root = load_preference (LegatePreferences, " legate_conda_env" , nothing )
16377 if isnothing (legate_root)
@@ -170,19 +84,20 @@ function build(::LegatePreferences.Conda)
17084end
17185
17286function build (:: LegatePreferences.Developer )
173- pkg_root = _start_build ( )
87+ pkg_root = BuildTools . start_build ( " Legate.jl " , @__DIR__ )
17488
175- # can be nothing so this errors if not set
17689 legate_root = load_preference (LegatePreferences, " legate_path" , nothing )
17790 if isnothing (legate_root)
178- # we are using legate_jll for legate
179- legate_root = _find_jll_artifact_dir ( :legate_jll )
91+ legate_root, cuda_root = BuildTools . setup_jll_build_env (pkg_root, BuildTools . LEGATE_JLL_DEP)
92+ cuda_enabled = ! isnothing (cuda_root) # cuda_root resolving to nothing means there is no cuda
18093 else
181- # this means we have a custom path set
18294 is_legate_installed (legate_root; throw_errors= true )
18395 patch_legion (pkg_root, legate_root)
96+ cuda_enabled, cuda_root = BuildTools. resolve_custom_cuda (" legate" ) # cuda_root is nothing.
18497 end
185- build_deps (pkg_root, legate_root)
98+
99+ build_deps (pkg_root, legate_root; cuda_root, cuda_enabled)
100+ set_preferences! (LegatePreferences, " LEGATE_LIBDIR" => joinpath (legate_root, " lib" ); force= true )
186101end
187102
188103const mode_str = load_preference (LegatePreferences, " legate_mode" , LegatePreferences. MODE_JLL)
0 commit comments