Skip to content

Commit 83e533a

Browse files
committed
Improved windows-gnullvm override handling
1 parent 3822d99 commit 83e533a

6 files changed

Lines changed: 125 additions & 60 deletions

File tree

3rd_party/windows_aarch64_gnullvm/include.MODULE.bazel

Lines changed: 0 additions & 14 deletions
This file was deleted.

3rd_party/windows_x86_64_gnullvm/include.MODULE.bazel

Lines changed: 0 additions & 14 deletions
This file was deleted.

rs/experimental/rules_rust.bzl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@ def _rules_rust_impl(mctx):
3131

3232
http_archive(
3333
name = "rules_rust",
34-
integrity = "sha256-ITjyRzZMKtkwQGTzTUZ6JZwzeHGTt+2hRSOIKG3gcQU=",
35-
strip_prefix = "rules_rust-1e0d96fbbd20cfa5c535eeab66707472a51e1ee3",
36-
url = "https://github.com/dzbarsky/rules_rust/archive/1e0d96fbbd20cfa5c535eeab66707472a51e1ee3.tar.gz",
34+
integrity = "sha256-P1p0/ho43MPdj79OaklUnErCfIkNu1ijEgDpU9qR5P0=",
35+
strip_prefix = "rules_rust-6015481d6014a0d297b0c89f93a8757375dbe74d",
36+
url = "https://github.com/dzbarsky/rules_rust/archive/6015481d6014a0d297b0c89f93a8757375dbe74d.tar.gz",
3737
patches = patches,
3838
patch_strip = strip,
3939
)
@@ -45,4 +45,4 @@ rules_rust = module_extension(
4545
tag_classes = {
4646
"patch": _patch,
4747
},
48-
)
48+
)

rs/private/annotations.bzl

Lines changed: 78 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,86 @@
1-
_DEFAULT_CRATE_ANNOTATION = struct(
2-
additive_build_file = None,
3-
additive_build_file_content = "",
4-
gen_build_script = "auto",
5-
build_script_data = [],
6-
build_script_data_select = {},
7-
build_script_env = {},
8-
build_script_env_select = {},
9-
build_script_tools = [],
10-
build_script_tools_select = {},
11-
build_script_toolchains = [],
12-
build_script_tags = [],
13-
data = [],
14-
deps = [],
15-
tags = [],
16-
crate_features = [],
17-
crate_features_select = {},
18-
gen_binaries = [],
19-
rustc_flags = [],
20-
rustc_flags_select = {},
21-
patch_args = [],
22-
patch_tool = None,
23-
patches = [],
24-
strip_prefix = None,
25-
workspace_cargo_toml = "Cargo.toml",
1+
def _crate_annotation(
2+
additive_build_file = None,
3+
additive_build_file_content = "",
4+
gen_build_script = "auto",
5+
build_script_data = [],
6+
build_script_data_select = {},
7+
build_script_env = {},
8+
build_script_env_select = {},
9+
build_script_tools = [],
10+
build_script_tools_select = {},
11+
build_script_toolchains = [],
12+
build_script_tags = [],
13+
data = [],
14+
deps = [],
15+
tags = [],
16+
crate_features = [],
17+
crate_features_select = {},
18+
gen_binaries = [],
19+
rustc_flags = [],
20+
rustc_flags_select = {},
21+
patch_args = [],
22+
patch_tool = None,
23+
patches = [],
24+
strip_prefix = None,
25+
workspace_cargo_toml = "Cargo.toml"):
26+
return struct(
27+
additive_build_file = additive_build_file,
28+
additive_build_file_content = additive_build_file_content,
29+
gen_build_script = gen_build_script,
30+
build_script_data = build_script_data,
31+
build_script_data_select = build_script_data_select,
32+
build_script_env = build_script_env,
33+
build_script_env_select = build_script_env_select,
34+
build_script_tools = build_script_tools,
35+
build_script_tools_select = build_script_tools_select,
36+
build_script_toolchains = build_script_toolchains,
37+
build_script_tags = build_script_tags,
38+
data = data,
39+
deps = deps,
40+
tags = tags,
41+
crate_features = crate_features,
42+
crate_features_select = crate_features_select,
43+
gen_binaries = gen_binaries,
44+
rustc_flags = rustc_flags,
45+
rustc_flags_select = rustc_flags_select,
46+
patch_args = patch_args,
47+
patch_tool = patch_tool,
48+
patches = patches,
49+
strip_prefix = strip_prefix,
50+
workspace_cargo_toml = workspace_cargo_toml,
51+
)
52+
53+
_DEFAULT_CRATE_ANNOTATION = _crate_annotation()
54+
55+
_WINDOWS_GNULLVM_IMPLICIT_ANNOTATION = _crate_annotation(
56+
additive_build_file_content = """
57+
load("@rules_cc//cc:defs.bzl", "cc_import")
58+
59+
cc_import(
60+
name = "windows_import_lib",
61+
static_library = glob(["lib/*.a"])[0],
2662
)
63+
""",
64+
gen_build_script = "off",
65+
deps = [":windows_import_lib"],
66+
)
67+
68+
_IMPLICIT_ANNOTATIONS_BY_CRATE = {
69+
# These crates publish the needed import library in their package archive.
70+
# Treat the well-known snippet as a built-in default so users do not need
71+
# to include it manually.
72+
"windows_aarch64_gnullvm": _WINDOWS_GNULLVM_IMPLICIT_ANNOTATION,
73+
"windows_x86_64_gnullvm": _WINDOWS_GNULLVM_IMPLICIT_ANNOTATION,
74+
}
2775

2876
def annotation_for(annotations_by_crate, crate_name, version):
2977
"""Return the annotation matching crate/version, falling back to '*' or default."""
3078
version_map = annotations_by_crate.get(crate_name, {})
31-
return version_map.get(version) or version_map.get("*", _DEFAULT_CRATE_ANNOTATION)
79+
return (
80+
version_map.get(version) or
81+
version_map.get("*") or
82+
_IMPLICIT_ANNOTATIONS_BY_CRATE.get(crate_name, _DEFAULT_CRATE_ANNOTATION)
83+
)
3284

3385
def build_annotation_map(mod, cfg_name):
3486
"""Build mapping {crate: {version|\"*\": annotation}} for a cfg name."""
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
diff --git a/swift/internal/swift_autoconfiguration.bzl b/swift/internal/swift_autoconfiguration.bzl
2+
--- a/swift/internal/swift_autoconfiguration.bzl
3+
+++ b/swift/internal/swift_autoconfiguration.bzl
4+
@@ -40,6 +40,8 @@ load(
5+
)
6+
load(":toolchain_utils.bzl", "SWIFT_TOOLCHAIN_TYPE")
7+
8+
+SWIFT_AUTOCONFIG_DISABLE_ENV_VAR = "BAZEL_DO_NOT_DETECT_SWIFT_TOOLCHAIN"
9+
+
10+
def _scratch_file(repository_ctx, temp_dir, name, content = ""):
11+
"""Creates and returns a scratch file with the given name and content.
12+
13+
@@ -380,6 +382,15 @@ def _create_windows_toolchain(*, repository_ctx):
14+
)
15+
16+
def _swift_autoconfiguration_impl(repository_ctx):
17+
+ if repository_ctx.os.environ.get(SWIFT_AUTOCONFIG_DISABLE_ENV_VAR) == "1":
18+
+ repository_ctx.file(
19+
+ "BUILD",
20+
+ "# Swift toolchain autoconfiguration was disabled by {} env variable.".format(
21+
+ SWIFT_AUTOCONFIG_DISABLE_ENV_VAR,
22+
+ ),
23+
+ )
24+
+ return
25+
+
26+
repository_ctx.file(
27+
"BUILD",
28+
"\n".join([
29+
@@ -406,7 +417,7 @@ def _swift_autoconfiguration_impl(repository_ctx):
30+
)
31+
32+
swift_autoconfiguration = repository_rule(
33+
- environ = ["CC", "PATH", "ProgramData", "Path"],
34+
+ environ = ["CC", "PATH", "ProgramData", "Path", SWIFT_AUTOCONFIG_DISABLE_ENV_VAR],
35+
implementation = _swift_autoconfiguration_impl,
36+
local = True,
37+
)

test/MODULE.bazel

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,12 @@ single_version_override(
4545
patches = ["//:libffi-aarch64-trampoline.patch"],
4646
)
4747

48+
single_version_override(
49+
module_name = "rules_swift",
50+
patch_strip = 1,
51+
patches = ["//:0001-allow-disabling-autoconfiguration.patch"],
52+
)
53+
4854
bazel_dep(name = "rules_rs", version = "0.0.0")
4955
local_path_override(
5056
module_name = "rules_rs",
@@ -273,8 +279,6 @@ inject_repo(crate, "mimalloc")
273279

274280
include("//:3rd_party/libz-sys/include.MODULE.bazel")
275281
include("//:3rd_party/libgit2-sys/include.MODULE.bazel")
276-
include("//:3rd_party/windows_x86_64_gnullvm/include.MODULE.bazel")
277-
include("//:3rd_party/windows_aarch64_gnullvm/include.MODULE.bazel")
278282
include("//:3rd_party/coreaudio-sys/include.MODULE.bazel")
279283

280284
# TODO(zbarsky): fix this for realz

0 commit comments

Comments
 (0)