Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 16 additions & 10 deletions .bazelci/presubmit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,24 +41,30 @@ x_defaults:
windows_common: &windows_common
platform: windows
environment:
SWIFT_VERSION: 6.1.0
PATH: "%LOCALAPPDATA%\\Programs\\Swift\\Toolchains\\%SWIFT_VERSION%+Asserts\\usr\\bin;%LOCALAPPDATA%\\Programs\\Swift\\Runtimes\\%SWIFT_VERSION%\\usr\\bin;%Path%"
SWIFT_VERSION: 6.2.1
Path: "%LOCALAPPDATA%\\Programs\\Swift\\Toolchains\\%SWIFT_VERSION%+Asserts\\usr\\bin;%LOCALAPPDATA%\\Programs\\Swift\\Runtimes\\%SWIFT_VERSION%\\usr\\bin;%Path%"
SDKROOT: "%LOCALAPPDATA%\\Programs\\Swift\\Platforms\\%SWIFT_VERSION%\\Windows.platform\\Developer\\SDKs\\Windows.sdk"
batch_commands:
- echo --- Installing Windows SDK
- curl.exe -L https://go.microsoft.com/fwlink/?linkid=2342616 -o %TEMP%\winsdkinstaller.exe
- PowerShell Start-Process -FilePath ${env:TEMP}\winsdkinstaller.exe -ArgumentList(\"/quiet\", \"/norestart\") -Wait -PassThru -Verb RunAs
- PowerShell Start-Process -FilePath "C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\VC\Auxiliary\Build\vcvarsall.bat" -ArgumentList(\"/amd64\") -Wait -PassThru -Verb RunAs
- echo --- Downloading and installing Swift %SWIFT_VERSION%
- curl.exe -L https://download.swift.org/swift-6.1-release/windows10/swift-6.1-RELEASE/swift-6.1-RELEASE-windows10.exe -o %TEMP%\installer.exe
- curl.exe -L https://download.swift.org/swift-6.2.1-release/windows10/swift-6.2.1-RELEASE/swift-6.2.1-RELEASE-windows10.exe -o %TEMP%\installer.exe
- PowerShell Start-Process -FilePath ${env:TEMP}\installer.exe -ArgumentList(\"/install\", \"/passive\", \"/norestart\", \"/log log.txt\") -Wait -PassThru -Verb RunAs
- dir "%LOCALAPPDATA%\\Programs\\Swift\\Toolchains\\%SWIFT_VERSION%+Asserts\\usr\\bin"
build_flags:
# Override 'sandboxed' strategy set in .bazelrc because it's not
# available on Windows
- "--strategy=SwiftCompile="
- "--repo_env=CC=clang-cl"
- "--repo_env=SDKROOT=%LOCALAPPDATA%\\Programs\\Swift\\Platforms\\%SWIFT_VERSION%\\Windows.platform\\Developer\\SDKs\\Windows.sdk"
- "--repo_env=Path=%LOCALAPPDATA%\\Programs\\Swift\\Toolchains\\%SWIFT_VERSION%+Asserts\\usr\\bin;%LOCALAPPDATA%\\Programs\\Swift\\Runtimes\\%SWIFT_VERSION%\\usr\\bin;%Path%"
- --repo_env=CC=clang
- --repo_env=CXX="%LOCALAPPDATA%\\Programs\\Swift\\Toolchains\\%SWIFT_VERSION%+Asserts\\usr\\bin\\clang++.exe"
- --repo_env=USE_CLANG_CL=1
- "--repo_env=CXX=clang++.exe"
# - "--repo_env=SDKROOT=%LOCALAPPDATA%\\Programs\\Swift\\Platforms\\%SWIFT_VERSION%\\Windows.platform\\Developer\\SDKs\\Windows.sdk"
# - "--repo_env=Path=%LOCALAPPDATA%\\Programs\\Swift\\Toolchains\\%SWIFT_VERSION%+Asserts\\usr\\bin;%LOCALAPPDATA%\\Programs\\Swift\\Runtimes\\%SWIFT_VERSION%\\usr\\bin;%Path%"
# - --repo_env=Path="%Path%"
# - --repo_env=PATH="%Path%"
- --repo_env="PATH=$($env:Path)"
# - --repo_env=BAZEL_LLVM="$($env:LOCALAPPDATA)\\Programs\\Swift\\Toolchains\\$($env:SWIFT_VERSION)+Asserts\\usr"
- --repo_env=BAZEL_LLVM="C:/Users/b/AppData/Local/Programs/Swift/Toolchains/6.2.1+Asserts/usr"

build_targets:
- "//tools/..."

Expand Down
11 changes: 11 additions & 0 deletions .bazelrc
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ common --incompatible_allow_tags_propagation
# Fail if a glob doesn't match anything (https://github.com/bazelbuild/bazel/issues/8195)
build --incompatible_disallow_empty_glob

# Easier syntax for passing swiftc flags
common --flag_alias=swiftcopt=@build_bazel_rules_swift//swift:copt
common --flag_alias=host_swiftcopt=@build_bazel_rules_swift//swift:exec_copt

build --host_macos_minimum_os=14.0
build --macos_minimum_os=14.0

Expand Down Expand Up @@ -50,3 +54,10 @@ build:linux --cxxopt='-std=c++14'
# There is an open issue about it on the zlib repository here:
# https://github.com/madler/zlib/issues/633
build --per_file_copt="external/.*zlib.*/.*.c@-Wno-deprecated-non-prototype"

build:windows --copt=-Wno-builtin-macro-redefined --host_copt=-Wno-builtin-macro-redefined
build:windows --extra_toolchains=@local_config_cc//:cc-toolchain-x64_windows-clang-cl --extra_execution_platforms=//:windows
build:windows --features=-compiler_param_file --host_features=-compiler_param_file
build:windows --swiftcopt=-wmo --host_swiftcopt=-wmo
build:windows --swiftcopt=-v --host_swiftcopt=-v
build:windows --worker_sandboxing=false
9 changes: 9 additions & 0 deletions BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,12 @@ filegroup(
"//tools:for_bazel_tests",
],
)

platform(
name = "windows",
constraint_values = [
"@platforms//cpu:x86_64",
"@platforms//os:windows",
"@bazel_tools//tools/cpp:clang-cl",
],
)
9 changes: 9 additions & 0 deletions MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,12 @@ single_version_override(
patch_strip = 1,
patches = ["//third_party/patches:stardoc-revert-load-statements-in-docs.patch"],
)

single_version_override(
module_name = "rules_cc",
patch_strip = 1,
patches = ["//:rules_cc.patch"],
)

cc_configure = use_extension("@rules_cc//cc:extensions.bzl", "cc_configure_extension")
use_repo(cc_configure, "local_config_cc")
59 changes: 59 additions & 0 deletions rules_cc.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
diff --git a/cc/private/toolchain/BUILD.windows.tpl b/cc/private/toolchain/BUILD.windows.tpl
index 1d0f8a0..a3a2aab 100644
--- a/cc/private/toolchain/BUILD.windows.tpl
+++ b/cc/private/toolchain/BUILD.windows.tpl
@@ -322,7 +322,7 @@ cc_toolchain_config(
"objcopy": "wrapper/bin/msvc_nop.bat",
"objdump": "wrapper/bin/msvc_nop.bat",
"strip": "wrapper/bin/msvc_nop.bat",
- "dumpbin": "%{msvc_dumpbin_path_x64}",
+ # "dumpbin": "%{msvc_dumpbin_path_x64}",
"cpp-module-deps-scanner": "%{msvc_deps_scanner_wrapper_path_x64}",
},
archiver_flags = ["/MACHINE:X64"],
diff --git a/cc/private/toolchain/windows_cc_configure.bzl b/cc/private/toolchain/windows_cc_configure.bzl
index 66ca5fb..4d8bfed 100644
--- a/cc/private/toolchain/windows_cc_configure.bzl
+++ b/cc/private/toolchain/windows_cc_configure.bzl
@@ -385,6 +385,7 @@ def setup_vc_env_vars(repository_ctx, vc_path, envvars = [], allow_empty = False
for env in envs:
key, value = env.split("=", 1)
env_map[key] = escape_string(value.replace("\\", "\\\\")) if escape else value
+ print(env_map)

if not allow_empty:
_check_env_vars(env_map, cmd, expected = envvars)
@@ -594,6 +595,7 @@ def find_llvm_tool(repository_ctx, llvm_path, tool):
tool_path = llvm_path + "\\bin\\" + tool

if not repository_ctx.path(tool_path).exists:
+ print("failed to find ", tool_path)
return None

return tool_path.replace("\\", "/")
@@ -723,6 +725,7 @@ def _get_msvc_vars(repository_ctx, paths, target_arch = "x64", msvc_vars_x64 = N
for path in escaped_include_paths.split(";"):
if path:
escaped_cxx_include_directories.append("\"%s\"" % path)
+ print("abc", build_tools)
if llvm_path:
clang_version = _get_clang_version(repository_ctx, build_tools["CL"])
clang_dir = _get_clang_dir(repository_ctx, llvm_path, clang_version)
@@ -741,6 +744,8 @@ Header pruning has been disabled since Bazel failed to recognize the output of /
This can result in unnecessary recompilation.
Fix this by installing the English language pack for the Visual Studio installation at {} and run 'bazel sync --configure'.""".format(vc_path))

+ print("build tools are ", build_tools)
+
msvc_vars = {
"%{msvc_env_tmp_" + target_arch + "}": escaped_tmp_dir,
"%{msvc_env_include_" + target_arch + "}": escaped_include_paths,
@@ -751,7 +756,7 @@ Fix this by installing the English language pack for the Visual Studio installat
"%{msvc_ml_path_" + target_arch + "}": build_tools.get("ML", "msvc_arm_toolchain_does_not_support_ml"),
"%{msvc_link_path_" + target_arch + "}": build_tools["LINK"],
"%{msvc_lib_path_" + target_arch + "}": build_tools["LIB"],
- "%{msvc_dumpbin_path_" + target_arch + "}": build_tools["DUMPBIN"],
+ # "%{msvc_dumpbin_path_" + target_arch + "}": build_tools["DUMPBIN"],
"%{msvc_parse_showincludes_" + target_arch + "}": repr(support_parse_showincludes),
"%{dbg_mode_debug_flag_" + target_arch + "}": "/DEBUG:FULL" if support_debug_fastlink else "/DEBUG",
"%{fastbuild_mode_debug_flag_" + target_arch + "}": "/DEBUG:FASTLINK" if support_debug_fastlink else "/DEBUG",
6 changes: 3 additions & 3 deletions swift/internal/swift_autoconfiguration.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -315,10 +315,10 @@ def _create_windows_toolchain(*, repository_ctx):
"""
path_to_swiftc = repository_ctx.which("swiftc.exe")
if not path_to_swiftc:
fail("""\
return """\
# No 'swiftc.exe' executable found in $PATH. Not auto-generating a Windows \
Swift toolchain.
""")
"""

root = path_to_swiftc.dirname.dirname
enabled_features = [
Expand All @@ -341,7 +341,7 @@ Swift toolchain.

env = {
"Path": repository_ctx.os.environ["Path"] if "Path" in repository_ctx.os.environ else repository_ctx.os.environ["PATH"],
# "ProgramData": repository_ctx.os.environ["ProgramData"],
"ProgramData": repository_ctx.os.environ["ProgramData"] if "ProgramData" in repository_ctx.os.environ else repository_ctx.os.environ["PROGRAMDATA"],
}

return """\
Expand Down
3 changes: 2 additions & 1 deletion swift/toolchains/swift_toolchain.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,8 @@ def _swift_toolchain_impl(ctx):
if "clang" not in cc_toolchain.compiler:
fail("Swift requires the configured CC toolchain to be LLVM (clang). " +
"Either use the locally installed LLVM by setting `CC=clang` in your environment " +
"before invoking Bazel, or configure a Bazel LLVM CC toolchain.")
"before invoking Bazel, or configure a Bazel LLVM CC toolchain." +
"The current CC toolchain uses: {}".format(cc_toolchain.compiler))

if ctx.attr.os == "windows":
swift_linkopts_cc_info = _swift_windows_linkopts_cc_info(
Expand Down
2 changes: 1 addition & 1 deletion tools/worker/swift_runner.cc
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ static std::unique_ptr<TempFile> WriteResponseFile(
}
response_file_stream << ch;
}
response_file_stream << "\"\n";
response_file_stream << "\"" << std::endl;
}

response_file_stream.close();
Expand Down
24 changes: 12 additions & 12 deletions tools/worker/work_processor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ void WorkProcessor::ProcessWorkRequest(
}

if (!arg.empty()) {
params_file_stream << arg << '\n';
params_file_stream << arg << std::endl;
}

prev_arg = original_arg;
Expand All @@ -134,18 +134,18 @@ void WorkProcessor::ProcessWorkRequest(
.string();
output_file_map.WriteToPath(new_path);

params_file_stream << "-output-file-map\n";
params_file_stream << new_path << '\n';
params_file_stream << "-output-file-map" << std::endl;
params_file_stream << new_path << std::endl;

// Pass the incremental flags only if WMO is disabled. WMO would overrule
// incremental mode anyway, but since we control the passing of this flag,
// there's no reason to pass it when it's a no-op.
params_file_stream << "-incremental\n";
params_file_stream << "-incremental" << std::endl;
} else {
// If WMO or -dump-ast is forcing us out of incremental mode, just put the
// original output file map back so the outputs end up where they should.
params_file_stream << "-output-file-map\n";
params_file_stream << output_file_map_path << '\n';
params_file_stream << "-output-file-map" << std::endl;
params_file_stream << output_file_map_path << std::endl;
}
}

Expand Down Expand Up @@ -198,7 +198,7 @@ void WorkProcessor::ProcessWorkRequest(
std::filesystem::create_directories(dir_path, ec);
if (ec) {
stderr_stream << "swift_worker: Could not create directory " << dir_path
<< " (" << ec.message() << ")\n";
<< " (" << ec.message() << ")" << std::endl;
FinalizeWorkRequest(request, response, EXIT_FAILURE, stderr_stream);
return;
}
Expand All @@ -222,7 +222,7 @@ void WorkProcessor::ProcessWorkRequest(
stderr_stream << "swift_worker: Could not copy "
<< expected_object_pair.second << " to "
<< expected_object_pair.first << " (" << ec.message()
<< ")\n";
<< ")" << std::endl;
FinalizeWorkRequest(request, response, EXIT_FAILURE, stderr_stream);
return;
}
Expand All @@ -238,7 +238,7 @@ void WorkProcessor::ProcessWorkRequest(
std::filesystem::remove(cleanup_output, ec);
if (ec) {
stderr_stream << "swift_worker: Could not remove " << cleanup_output
<< " (" << ec.message() << ")\n";
<< " (" << ec.message() << ")" << std::endl;
FinalizeWorkRequest(request, response, EXIT_FAILURE, stderr_stream);
return;
}
Expand All @@ -265,7 +265,7 @@ void WorkProcessor::ProcessWorkRequest(
stderr_stream << "swift_worker: Could not copy "
<< expected_object_pair.second << " to "
<< expected_object_pair.first << " (" << ec.message()
<< ")\n";
<< ")" << std::endl;
FinalizeWorkRequest(request, response, EXIT_FAILURE, stderr_stream);
return;
}
Expand All @@ -286,13 +286,13 @@ void WorkProcessor::ProcessWorkRequest(
stderr_stream << "swift_worker: Could not copy "
<< expected_object_pair.first << " to "
<< expected_object_pair.second << " (" << ec.message()
<< ")\n";
<< ")" << std::endl;
FinalizeWorkRequest(request, response, EXIT_FAILURE, stderr_stream);
return;
}
} else if (exit_code == 0) {
stderr_stream << "Failed to copy " << expected_object_pair.first
<< " for incremental builds, maybe it wasn't produced?\n";
<< " for incremental builds, maybe it wasn't produced?" << std::endl;
FinalizeWorkRequest(request, response, EXIT_FAILURE, stderr_stream);
return;
}
Expand Down