|
| 1 | +# Copyright 2024 The Bazel Authors. All rights reserved. |
| 2 | +# |
| 3 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +# you may not use this file except in compliance with the License. |
| 5 | +# You may obtain a copy of the License at |
| 6 | +# |
| 7 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +# |
| 9 | +# Unless required by applicable law or agreed to in writing, software |
| 10 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +# See the License for the specific language governing permissions and |
| 13 | +# limitations under the License. |
| 14 | + |
| 15 | +"""Tests for parallel compilation.""" |
| 16 | + |
| 17 | +load("@bazel_skylib//rules:build_test.bzl", "build_test") |
| 18 | +load( |
| 19 | + "@build_bazel_rules_swift//test/rules:actions_created_test.bzl", |
| 20 | + "actions_created_test", |
| 21 | +) |
| 22 | + |
| 23 | +visibility("private") |
| 24 | + |
| 25 | +def parallel_compilation_test_suite(name, tags = []): |
| 26 | + """Test suite for parallel compilation. |
| 27 | +
|
| 28 | + Args: |
| 29 | + name: The base name to be used in targets created by this macro. |
| 30 | + tags: Additional tags to apply to each test. |
| 31 | + """ |
| 32 | + all_tags = [name] + tags |
| 33 | + |
| 34 | + # Non-optimized, non-WMO can be compiled in parallel. |
| 35 | + actions_created_test( |
| 36 | + name = "{}_no_opt_no_wmo".format(name), |
| 37 | + mnemonics = ["SwiftCompileModule", "SwiftCompileCodegen", "-SwiftCompile"], |
| 38 | + tags = all_tags, |
| 39 | + target_under_test = "@build_bazel_rules_swift//test/fixtures/parallel_compilation:no_opt_no_wmo", |
| 40 | + ) |
| 41 | + |
| 42 | + # Non-optimized, with-WMO can be compiled in parallel. |
| 43 | + actions_created_test( |
| 44 | + name = "{}_no_opt_with_wmo".format(name), |
| 45 | + mnemonics = ["SwiftCompileModule", "SwiftCompileCodegen", "-SwiftCompile"], |
| 46 | + tags = all_tags, |
| 47 | + target_under_test = "@build_bazel_rules_swift//test/fixtures/parallel_compilation:no_opt_with_wmo", |
| 48 | + ) |
| 49 | + |
| 50 | + # Optimized, non-WMO cannot be compiled in parallel. |
| 51 | + # TODO: b/351801556 - This is actually incorrect based on further driver |
| 52 | + # testing; update the rules to allow compiling these in parallel. |
| 53 | + actions_created_test( |
| 54 | + name = "{}_with_opt_no_wmo".format(name), |
| 55 | + mnemonics = ["-SwiftCompileModule", "-SwiftCompileCodegen", "SwiftCompile"], |
| 56 | + tags = all_tags, |
| 57 | + target_under_test = "@build_bazel_rules_swift//test/fixtures/parallel_compilation:with_opt_no_wmo", |
| 58 | + ) |
| 59 | + |
| 60 | + # Optimized, with-WMO cannot be compiled in parallel. |
| 61 | + # TODO: b/351801556 - This should be allowed if cross-module-optimization is |
| 62 | + # disabled. Update the rules to allow this and add a new version of this |
| 63 | + # target that disables CMO so we can test both situtations. |
| 64 | + actions_created_test( |
| 65 | + name = "{}_with_opt_with_wmo".format(name), |
| 66 | + mnemonics = ["-SwiftCompileModule", "-SwiftCompileCodegen", "SwiftCompile"], |
| 67 | + tags = all_tags, |
| 68 | + target_under_test = "@build_bazel_rules_swift//test/fixtures/parallel_compilation:with_opt_with_wmo", |
| 69 | + ) |
| 70 | + |
| 71 | + # Make sure that when we look for optimizer flags, we don't treat `-Onone` |
| 72 | + # as being optimized. |
| 73 | + actions_created_test( |
| 74 | + name = "{}_onone_with_wmo".format(name), |
| 75 | + mnemonics = ["SwiftCompileModule", "SwiftCompileCodegen", "-SwiftCompile"], |
| 76 | + tags = all_tags, |
| 77 | + target_under_test = "@build_bazel_rules_swift//test/fixtures/parallel_compilation:onone_with_wmo", |
| 78 | + ) |
| 79 | + |
| 80 | + # The analysis tests verify that we register the actions we expect. Use a |
| 81 | + # `build_test` to make sure the actions execute successfully. |
| 82 | + build_test( |
| 83 | + name = "{}_build_test".format(name), |
| 84 | + targets = [ |
| 85 | + "@build_bazel_rules_swift//test/fixtures/parallel_compilation:no_opt_no_wmo", |
| 86 | + "@build_bazel_rules_swift//test/fixtures/parallel_compilation:no_opt_with_wmo", |
| 87 | + "@build_bazel_rules_swift//test/fixtures/parallel_compilation:with_opt_no_wmo", |
| 88 | + "@build_bazel_rules_swift//test/fixtures/parallel_compilation:with_opt_with_wmo", |
| 89 | + "@build_bazel_rules_swift//test/fixtures/parallel_compilation:onone_with_wmo", |
| 90 | + ], |
| 91 | + tags = all_tags, |
| 92 | + ) |
| 93 | + |
| 94 | + native.test_suite( |
| 95 | + name = name, |
| 96 | + tags = all_tags, |
| 97 | + ) |
0 commit comments