diff --git a/llvm/utils/gn/build/toolchain/BUILD.gn b/llvm/utils/gn/build/toolchain/BUILD.gn --- a/llvm/utils/gn/build/toolchain/BUILD.gn +++ b/llvm/utils/gn/build/toolchain/BUILD.gn @@ -9,6 +9,8 @@ assert(!use_goma || goma_dir != "", "set `goma_dir` to the output of `goma_ctl goma_dir` in your args.gn") +unix_copy_command = "ln -f {{source}} {{output}} 2>/dev/null || (rm -rf {{output}} && cp -af {{source}} {{output}})" + template("unix_toolchain") { toolchain(target_name) { # https://groups.google.com/a/chromium.org/g/gn-dev/c/F_lv5T-tNDM @@ -144,9 +146,8 @@ default_output_dir = "{{root_out_dir}}/bin" } - copy_command = "ln -f {{source}} {{output}} 2>/dev/null || (rm -rf {{output}} && cp -af {{source}} {{output}})" tool("copy") { - command = copy_command + command = unix_copy_command description = "COPY {{source}} {{output}}" } @@ -378,14 +379,23 @@ } tool("copy") { - # GN hands out slash-using paths, but cmd's copy needs backslashes. - # Use cmd's %foo:a=b% substitution feature to convert. - command = "cmd /c set source=\"{{source}}\" & set output=\"{{output}}\" & call copy /Y %source:/=\% %output:\=/% > nul" + if (host_os == "win") { + # GN hands out slash-using paths, but cmd's copy needs backslashes. + # Use cmd's %foo:a=b% substitution feature to convert. + command = "cmd /c set source=\"{{source}}\" & set output=\"{{output}}\" & call copy /Y %source:/=\% %output:\=/% > nul" + } else { + command = unix_copy_command + } + description = "COPY {{source}} {{output}}" } tool("stamp") { - command = "cmd /c type nul > {{output}}" + if (host_os == "win") { + command = "cmd /c type nul > {{output}}" + } else { + command = "touch {{output}}" + } description = "STAMP {{output}}" } } @@ -398,11 +408,14 @@ } } -win_toolchain("stage2_win") { +win_toolchain("stage2_win_x64") { toolchain_args = { - current_os = host_os - current_cpu = host_cpu + current_os = "win" + current_cpu = "x64" + if (host_os != "win") { + sysroot = win_sysroot + } clang_base_path = root_build_dir use_goma = false } @@ -414,9 +427,12 @@ win_toolchain("stage2_win_x86") { toolchain_args = { - current_os = host_os + current_os = "win" current_cpu = "x86" + if (host_os != "win") { + sysroot = win_sysroot + } clang_base_path = root_build_dir use_goma = false } diff --git a/llvm/utils/gn/build/toolchain/compiler.gni b/llvm/utils/gn/build/toolchain/compiler.gni --- a/llvm/utils/gn/build/toolchain/compiler.gni +++ b/llvm/utils/gn/build/toolchain/compiler.gni @@ -13,6 +13,9 @@ # Set this to the path to Android NDK r21. If set, cross compilation targeting # Android will be enabled. android_ndk_path = "" + + # Set this to the path of the Win SDK. Only used for cross compilation. If set, cross compilation targeting Windows will be enabled. + win_sysroot = "" } declare_args() { @@ -23,3 +26,7 @@ # Set this to true to link with LLD instead of the default linker. use_lld = clang_base_path != "" } + +assert( + !(host_os == "win" && win_sysroot != ""), + "win_sysroot should only be used for cross compilation, use sysroot on Windows") diff --git a/llvm/utils/gn/secondary/compiler-rt/BUILD.gn b/llvm/utils/gn/secondary/compiler-rt/BUILD.gn --- a/llvm/utils/gn/secondary/compiler-rt/BUILD.gn +++ b/llvm/utils/gn/secondary/compiler-rt/BUILD.gn @@ -5,11 +5,13 @@ # In the GN build, compiler-rt is always built by just-built clang and lld. # FIXME: For macOS and iOS builds, depend on lib in all needed target arch # toolchains and then lipo them together for the final output. -if (current_os == "win") { - supported_toolchains = [ "//llvm/utils/gn/build/toolchain:stage2_win" ] +supported_toolchains = [] +if (current_os == "win" || win_sysroot != "") { + supported_toolchains += [ "//llvm/utils/gn/build/toolchain:stage2_win_x64" ] supported_toolchains += [ "//llvm/utils/gn/build/toolchain:stage2_win_x86" ] -} else { - supported_toolchains = [ "//llvm/utils/gn/build/toolchain:stage2_unix" ] +} +if (current_os != "win") { + supported_toolchains += [ "//llvm/utils/gn/build/toolchain:stage2_unix" ] } supported_toolchains += supported_android_toolchains if (llvm_build_AArch64) { diff --git a/llvm/utils/gn/secondary/compiler-rt/test/asan/BUILD.gn b/llvm/utils/gn/secondary/compiler-rt/test/asan/BUILD.gn --- a/llvm/utils/gn/secondary/compiler-rt/test/asan/BUILD.gn +++ b/llvm/utils/gn/secondary/compiler-rt/test/asan/BUILD.gn @@ -48,8 +48,9 @@ if (host_os == "linux") { supported_toolchains += [ "//llvm/utils/gn/build/toolchain:stage2_unix" ] } else if (host_os == "win") { - supported_toolchains += [ "//llvm/utils/gn/build/toolchain:stage2_win" ] + supported_toolchains += [ "//llvm/utils/gn/build/toolchain:stage2_win_64" ] } + group("asan") { deps = [] foreach(toolchain, supported_toolchains) {