-
Notifications
You must be signed in to change notification settings - Fork 140
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add
swift.global_module_cache_uses_tmpdir
feature
This adds a new feature, that can be enabled by passing `--features=swift.use_global_module_cache` and `--features=swift.global_module_cache_uses_tmpdir` to the build command. This feature, when enabled, will makes the Swift compilation actions use the shared Clang module cache path written to `/private/tmp/__build_bazel_rules_swift/swift_module_cache/REPOSITORY_NAME`. This makes the embedded Clang module breadcrumbs deterministic between Bazel instances, because they are always embedded as absolute paths. Note that the use of this cache is non-hermetic--the cached modules are not wiped between builds, and won't be cleaned when invoking bazel clean; the user is responsible for manually cleaning them. Additionally, this can be used as a workaround for a bug in the Swift compiler that causes the module breadcrumbs to be embedded even though the `-no-clang-module-breadcrumbs` flag is passed (https://bugs.swift.org/browse/SR-13275). Since the source path of modulemaps might be different for the same module, (i.e. multiple checkouts of the same repository, or remote execution), multiple modules with different hashes can end up in the cache. This can result in build failures. Don't use this feature with sandboxing (or probably remote execution as well).
- Loading branch information
1 parent
aab5e21
commit cddd976
Showing
9 changed files
with
167 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
# Copyright 2021 The Bazel Authors. All rights reserved. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
"""Tests for module cache related command line flags under various configs.""" | ||
|
||
load( | ||
"@build_bazel_rules_swift//test/rules:action_command_line_test.bzl", | ||
"make_action_command_line_test_rule", | ||
) | ||
|
||
use_global_module_cache_action_command_line_test = make_action_command_line_test_rule( | ||
config_settings = { | ||
"//command_line_option:features": [ | ||
"swift.use_global_module_cache", | ||
], | ||
}, | ||
) | ||
|
||
global_module_cache_uses_tmpdir_action_command_line_test = make_action_command_line_test_rule( | ||
config_settings = { | ||
"//command_line_option:features": [ | ||
"swift.global_module_cache_uses_tmpdir", | ||
"swift.use_global_module_cache", | ||
], | ||
}, | ||
) | ||
|
||
incorrect_global_module_cache_uses_tmpdir_action_command_line_test = make_action_command_line_test_rule( | ||
config_settings = { | ||
"//command_line_option:features": [ | ||
"swift.global_module_cache_uses_tmpdir", | ||
], | ||
}, | ||
) | ||
|
||
def module_cache_settings_test_suite(name = "module_cache_settings"): | ||
"""Test suite for module cache options. | ||
Args: | ||
name: The name prefix for all the nested tests | ||
""" | ||
|
||
# Verify that a global module cache path is passed to swiftc. | ||
use_global_module_cache_action_command_line_test( | ||
name = "{}_global_module_cache_build".format(name), | ||
expected_argv = [ | ||
"-module-cache-path", | ||
# Starlark doesn't have support for regular expression yet, so we | ||
# can't verify the whole argument here. | ||
"/bin/_swift_module_cache", | ||
], | ||
not_expected_argv = [ | ||
"-Xwrapped-swift=-ephemeral-module-cache", | ||
"/private/tmp/__build_bazel_rules_swift/swift_module_cache/build_bazel_rules_swift", | ||
], | ||
mnemonic = "SwiftCompile", | ||
tags = [name], | ||
target_under_test = "@build_bazel_rules_swift//test/fixtures/debug_settings:simple", | ||
) | ||
|
||
# Verify that a pre-defined shared module cache path in `/private/tmp` is | ||
# passed to swiftc. | ||
global_module_cache_uses_tmpdir_action_command_line_test( | ||
name = "{}_tmpdir_module_cache_build".format(name), | ||
expected_argv = [ | ||
"-module-cache-path", | ||
"/private/tmp/__build_bazel_rules_swift/swift_module_cache/build_bazel_rules_swift", | ||
], | ||
not_expected_argv = [ | ||
"-Xwrapped-swift=-ephemeral-module-cache", | ||
], | ||
mnemonic = "SwiftCompile", | ||
tags = [name], | ||
target_under_test = "@build_bazel_rules_swift//test/fixtures/debug_settings:simple", | ||
) | ||
|
||
# Verify that no module cache path is used when only | ||
# `swift.global_module_cache_uses_tmpdir` is passed. | ||
incorrect_global_module_cache_uses_tmpdir_action_command_line_test( | ||
name = "{}_incorrect_tmpdir_module_cache_build".format(name), | ||
not_expected_argv = [ | ||
"/private/tmp/__build_bazel_rules_swift/swift_module_cache/build_bazel_rules_swift", | ||
], | ||
mnemonic = "SwiftCompile", | ||
tags = [name], | ||
target_under_test = "@build_bazel_rules_swift//test/fixtures/debug_settings:simple", | ||
) | ||
|
||
native.test_suite( | ||
name = name, | ||
tags = [name], | ||
) |