File size: 7,128 Bytes
2ee40b0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
diff --git a/windows/private/extensions/windows_sdk.bzl b/windows/private/extensions/windows_sdk.bzl
index 420cee4..16d2cf3 100644
--- a/windows/private/extensions/windows_sdk.bzl
+++ b/windows/private/extensions/windows_sdk.bzl
@@ -133,19 +133,18 @@ def _repository_fs_is_case_sensitive(repository_ctx):
 def _apply_transformations(repository_ctx):
     transformations = repository_ctx.attr.transformations
     if not transformations:
-        return
+        return []
 
     sysroot = repository_ctx.path(_SYSROOT_DIR)
     if not sysroot.exists:
-        return
-    if not _repository_fs_is_case_sensitive(repository_ctx):
-        # Case-only aliases cannot be materialized on case-insensitive filesystems.
-        return
+        return []
+    repository_fs_is_case_sensitive = _repository_fs_is_case_sensitive(repository_ctx)
 
     all_files = []
     _collect_files_recursive(sysroot, all_files)
     all_rel_files = [_relative_to_repo_root(repository_ctx, f) for f in all_files]
     created = {}
+    logical_aliases = []
 
     for src_pattern, transform in transformations.items():
         src_pattern = _normalize_relpath(src_pattern)
@@ -165,11 +164,18 @@ def _apply_transformations(repository_ctx):
             if not dst_rel or dst_rel == src_rel or created.get(dst_rel, False):
                 continue
             if repository_ctx.path(dst_rel).exists:
+                if not repository_fs_is_case_sensitive and src_rel.lower() == dst_rel.lower():
+                    # Keep the alternate spelling as a Bazel source label. Bazel then
+                    # preserves that spelling in a case-sensitive remote input tree.
+                    logical_aliases.append(dst_rel)
+                    created[dst_rel] = True
                 continue
 
             repository_ctx.symlink(src_rel, dst_rel)
             created[dst_rel] = True
 
+    return sorted(logical_aliases)
+
 def _windows_sdk_repository_impl(repository_ctx):
     if not repository_ctx.attr.windows_sdk_version:
         fail("windows_sdk_version must be set")
@@ -220,8 +226,8 @@ def _windows_sdk_repository_impl(repository_ctx):
         "windows_sdk_include_versions",
     )
 
-    _apply_transformations(repository_ctx)
     _keep_exposed_windows_sdk_files(repository_ctx, _SYSROOT_DIR, include_version, requested_architectures)
+    logical_aliases = _apply_transformations(repository_ctx)
 
     repository_ctx.template(
         "BUILD.bazel",
@@ -229,6 +235,7 @@ def _windows_sdk_repository_impl(repository_ctx):
         substitutions = {
             "__WINSDK_DIR__": _SYSROOT_DIR,
             "__WINSDK_INCLUDE_VERSION__": include_version,
+            "__WINSDK_LOGICAL_ALIASES__": repr(logical_aliases),
         },
     )
 
@@ -258,7 +265,9 @@ _WINDOWS_SDK_ATTR = {
     "transformations": attr.string_dict(
         default = {},
         doc = """
-            Dict of source path patterns to transformations applied when run on case-sensitive filesystems.
+            Dict of source path patterns to transformations applied to extracted Windows SDK files.
+            Case-only transformations are Bazel aliases on case-insensitive filesystems and symlinks on
+            case-sensitive filesystems.
 
             Supports exact paths and `**/*.ext` patterns. Use value `lowercase` to create lowercase aliases.
 
diff --git a/windows/private/extensions/windows_sdk.BUILD.bazel b/windows/private/extensions/windows_sdk.BUILD.bazel
index 0d03f4e..199fdf0 100644
--- a/windows/private/extensions/windows_sdk.BUILD.bazel
+++ b/windows/private/extensions/windows_sdk.BUILD.bazel
@@ -5,6 +5,8 @@ load("@bazel_skylib//rules/directory:subdirectory.bzl", "subdirectory")
 
 package(default_visibility = ["//visibility:public"])
 
+_LOGICAL_ALIASES = __WINSDK_LOGICAL_ALIASES__
+
 config_setting(
     name = "windows_aarch64",
     constraint_values = [
@@ -18,7 +20,7 @@ directory(
     srcs = glob(
         ["__WINSDK_DIR__/**"],
         allow_empty = True,
-    ),
+    ) + _LOGICAL_ALIASES,
 )
 
 subdirectory(
@@ -32,7 +34,11 @@ directory(
     srcs = glob(
         ["__WINSDK_DIR__/base/c/Include/__WINSDK_INCLUDE_VERSION__/ucrt/**"],
         allow_empty = True,
-    ),
+    ) + [
+        f
+        for f in _LOGICAL_ALIASES
+        if f.startswith("__WINSDK_DIR__/base/c/Include/__WINSDK_INCLUDE_VERSION__/ucrt/")
+    ],
 )
 
 subdirectory(
@@ -46,7 +52,11 @@ directory(
     srcs = glob(
         ["__WINSDK_DIR__/base/c/Include/__WINSDK_INCLUDE_VERSION__/shared/**"],
         allow_empty = True,
-    ),
+    ) + [
+        f
+        for f in _LOGICAL_ALIASES
+        if f.startswith("__WINSDK_DIR__/base/c/Include/__WINSDK_INCLUDE_VERSION__/shared/")
+    ],
 )
 
 subdirectory(
@@ -60,7 +70,11 @@ directory(
     srcs = glob(
         ["__WINSDK_DIR__/base/c/Include/__WINSDK_INCLUDE_VERSION__/um/**"],
         allow_empty = True,
-    ),
+    ) + [
+        f
+        for f in _LOGICAL_ALIASES
+        if f.startswith("__WINSDK_DIR__/base/c/Include/__WINSDK_INCLUDE_VERSION__/um/")
+    ],
 )
 
 subdirectory(
@@ -74,7 +88,11 @@ directory(
     srcs = glob(
         ["__WINSDK_DIR__/base/c/Include/__WINSDK_INCLUDE_VERSION__/winrt/**"],
         allow_empty = True,
-    ),
+    ) + [
+        f
+        for f in _LOGICAL_ALIASES
+        if f.startswith("__WINSDK_DIR__/base/c/Include/__WINSDK_INCLUDE_VERSION__/winrt/")
+    ],
 )
 
 subdirectory(
@@ -88,7 +106,11 @@ directory(
     srcs = glob(
         ["__WINSDK_DIR__/arm64/c/ucrt/arm64/**"],
         allow_empty = True,
-    ),
+    ) + [
+        f
+        for f in _LOGICAL_ALIASES
+        if f.startswith("__WINSDK_DIR__/arm64/c/ucrt/arm64/")
+    ],
 )
 
 subdirectory(
@@ -102,7 +124,11 @@ directory(
     srcs = glob(
         ["__WINSDK_DIR__/x64/c/ucrt/x64/**"],
         allow_empty = True,
-    ),
+    ) + [
+        f
+        for f in _LOGICAL_ALIASES
+        if f.startswith("__WINSDK_DIR__/x64/c/ucrt/x64/")
+    ],
 )
 
 subdirectory(
@@ -116,7 +142,11 @@ directory(
     srcs = glob(
         ["__WINSDK_DIR__/arm64/c/um/arm64/**"],
         allow_empty = True,
-    ),
+    ) + [
+        f
+        for f in _LOGICAL_ALIASES
+        if f.startswith("__WINSDK_DIR__/arm64/c/um/arm64/")
+    ],
 )
 
 subdirectory(
@@ -130,7 +160,11 @@ directory(
     srcs = glob(
         ["__WINSDK_DIR__/x64/c/um/x64/**"],
         allow_empty = True,
-    ),
+    ) + [
+        f
+        for f in _LOGICAL_ALIASES
+        if f.startswith("__WINSDK_DIR__/x64/c/um/x64/")
+    ],
 )
 
 subdirectory(
@@ -160,7 +194,7 @@ filegroup(
     srcs = glob(
         ["**"],
         allow_empty = True,
-    ),
+    ) + _LOGICAL_ALIASES,
 )
 
 filegroup(
@@ -177,7 +211,11 @@ filegroup(
             "**/*.hpp",
         ],
         allow_empty = True,
-    ),
+    ) + [
+        f
+        for f in _LOGICAL_ALIASES
+        if f.endswith(".h") or f.endswith(".hh") or f.endswith(".hpp")
+    ],
 )
 
 filegroup(
@@ -185,5 +223,9 @@ filegroup(
     srcs = glob(
         ["**/*.lib"],
         allow_empty = True,
-    ),
+    ) + [
+        f
+        for f in _LOGICAL_ALIASES
+        if f.endswith(".lib")
+    ],
 )