|
40 | 40 | "SWIFT_FEATURE_USE_MODULE_WRAP",
|
41 | 41 | "SWIFT_FEATURE_USE_OLD_DRIVER",
|
42 | 42 | "SWIFT_FEATURE_USE_RESPONSE_FILES",
|
| 43 | + "SWIFT_FEATURE__SUPPORTS_MACROS", |
43 | 44 | )
|
44 | 45 |
|
45 | 46 | def _scratch_file(repository_ctx, temp_dir, name, content = ""):
|
@@ -170,6 +171,30 @@ def _write_swift_version(repository_ctx, swiftc_path):
|
170 | 171 | repository_ctx.file(filename, contents, executable = False)
|
171 | 172 | return filename
|
172 | 173 |
|
| 174 | +def _fetch_supported_features(repository_ctx, swiftc_path): |
| 175 | + """Fetch the json config of supported features from Swift |
| 176 | +
|
| 177 | + This can be used to flip rules specific features |
| 178 | +
|
| 179 | + Args: |
| 180 | + repository_ctx: The repository context. |
| 181 | + swiftc_path: The `path` to the `swiftc` executable. |
| 182 | +
|
| 183 | + Returns: |
| 184 | + The list of supported features, or an empty array if it fails |
| 185 | + """ |
| 186 | + repository_ctx.file("empty.swift") |
| 187 | + result = repository_ctx.execute([ |
| 188 | + swiftc_path, |
| 189 | + "-frontend", |
| 190 | + "-emit-supported-features", |
| 191 | + "empty.swift", |
| 192 | + ]) |
| 193 | + if result.return_code == 0: |
| 194 | + return json.decode(result.stdout.strip()).get("SupportedArguments", []) |
| 195 | + |
| 196 | + return [] |
| 197 | + |
173 | 198 | def _compute_feature_values(repository_ctx, swiftc_path):
|
174 | 199 | """Computes a list of supported/unsupported features by running checks.
|
175 | 200 |
|
@@ -252,6 +277,10 @@ def _create_linux_toolchain(repository_ctx):
|
252 | 277 | feature_values.append(SWIFT_FEATURE_USE_AUTOLINK_EXTRACT)
|
253 | 278 | feature_values.append(SWIFT_FEATURE_USE_MODULE_WRAP)
|
254 | 279 |
|
| 280 | + swift_features_config = _fetch_supported_features(repository_ctx, path_to_swiftc) |
| 281 | + if "load-plugin-executable" in swift_features_config: |
| 282 | + feature_values.append(SWIFT_FEATURE__SUPPORTS_MACROS) |
| 283 | + |
255 | 284 | repository_ctx.file(
|
256 | 285 | "BUILD",
|
257 | 286 | """
|
|
0 commit comments