diff --git a/MODULE.bazel b/MODULE.bazel index 6d82d392d46560..6920f71bc7e3e1 100644 --- a/MODULE.bazel +++ b/MODULE.bazel @@ -23,7 +23,7 @@ bazel_dep(name = "stardoc", version = "0.7.1", repo_name = "io_bazel_skydoc") bazel_dep(name = "zstd-jni", version = "1.5.2-3.bcr.1") bazel_dep(name = "blake3", version = "1.5.1.bcr.1") bazel_dep(name = "zlib", version = "1.3.1.bcr.3") -bazel_dep(name = "rules_cc", version = "0.0.10") +bazel_dep(name = "rules_cc", version = "0.0.12") bazel_dep(name = "rules_java", version = "8.0.0-rc2") bazel_dep(name = "rules_graalvm", version = "0.11.1") bazel_dep(name = "rules_proto", version = "6.0.2") diff --git a/MODULE.bazel.lock b/MODULE.bazel.lock index e5ae669f0cae3c..5b05b3559717f5 100644 --- a/MODULE.bazel.lock +++ b/MODULE.bazel.lock @@ -111,7 +111,8 @@ "https://bcr.bazel.build/modules/rules_apple/3.5.1/source.json": "e7593cdf26437d35dbda64faeaf5b82cbdd9df72674b0f041fdde75c1d20dda7", "https://bcr.bazel.build/modules/rules_cc/0.0.1/MODULE.bazel": "cb2aa0747f84c6c3a78dad4e2049c154f08ab9d166b1273835a8174940365647", "https://bcr.bazel.build/modules/rules_cc/0.0.10/MODULE.bazel": "ec1705118f7eaedd6e118508d3d26deba2a4e76476ada7e0e3965211be012002", - "https://bcr.bazel.build/modules/rules_cc/0.0.10/source.json": "90310b16e0e7df0cf40f8d1dccd7d373360f42419a6bfbbf5bb013182dd70e84", + "https://bcr.bazel.build/modules/rules_cc/0.0.12/MODULE.bazel": "28259f5cb8dd72d7503eb4fd1f9c89ab13759a438b1b78cb9655568d8566d7f9", + "https://bcr.bazel.build/modules/rules_cc/0.0.12/source.json": "e04b3b0e32e3eb102e551143610cbfe8cf836b9825c8c9d22084586de03dbe12", "https://bcr.bazel.build/modules/rules_cc/0.0.2/MODULE.bazel": "6915987c90970493ab97393024c156ea8fb9f3bea953b2f3ec05c34f19b5695c", "https://bcr.bazel.build/modules/rules_cc/0.0.5/MODULE.bazel": "be41f87587998fe8890cd82ea4e848ed8eb799e053c224f78f3ff7fe1a1d9b74", "https://bcr.bazel.build/modules/rules_cc/0.0.6/MODULE.bazel": "abf360251023dfe3efcef65ab9d56beefa8394d4176dd29529750e1c57eaa33f", diff --git a/src/MODULE.tools b/src/MODULE.tools index b5989bb23c2f3b..535311bcab250e 100644 --- a/src/MODULE.tools +++ b/src/MODULE.tools @@ -10,10 +10,6 @@ bazel_dep(name = "buildozer", version = "7.1.2") bazel_dep(name = "platforms", version = "0.0.10") bazel_dep(name = "zlib", version = "1.3.1.bcr.3") -cc_configure = use_extension("//tools/cpp:cc_configure.bzl", "cc_configure_extension") -use_repo(cc_configure, "local_config_cc", "local_config_cc_toolchains") -register_toolchains("@local_config_cc_toolchains//:all") - xcode_configure = use_extension("//tools/osx:xcode_configure.bzl", "xcode_configure_extension") use_repo(xcode_configure, "local_config_xcode") @@ -42,7 +38,7 @@ use_repo(buildozer_binary, "buildozer_binary") # Dependencies used to auto-load removed symbols and rules from Bazel (due to Starlarkification) # See also: --incompatible_autoload_externally, AutoloadSymbols bazel_dep(name = "rules_java", version = "8.0.0-rc2") -bazel_dep(name = "rules_cc", version = "0.0.10") +bazel_dep(name = "rules_cc", version = "0.0.12") bazel_dep(name = "rules_python", version = "0.36.0") # add rules_android # add apple_support diff --git a/src/main/java/com/google/devtools/build/lib/bazel/rules/cpp/BUILD b/src/main/java/com/google/devtools/build/lib/bazel/rules/cpp/BUILD index c64c12a199e09d..76dcb7c8584e66 100644 --- a/src/main/java/com/google/devtools/build/lib/bazel/rules/cpp/BUILD +++ b/src/main/java/com/google/devtools/build/lib/bazel/rules/cpp/BUILD @@ -62,12 +62,12 @@ gen_workspace_stanza( name = "workspace_with_rules_cc", out = "cc_configure.WORKSPACE", postamble = """ + load("@bazel_tools//tools/cpp:cc_configure.bzl", "cc_configure") cc_configure() """, preamble = """ load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") load("@bazel_tools//tools/build_defs/repo:utils.bzl", "maybe") - load("@bazel_tools//tools/cpp:cc_configure.bzl", "cc_configure") """, repos = ["rules_cc"], use_maybe = 1, diff --git a/src/main/starlark/tests/builtins_bzl/cc_builtin_tests.sh b/src/main/starlark/tests/builtins_bzl/cc_builtin_tests.sh index 09d2c6916b9298..c3f4e7a2e069af 100755 --- a/src/main/starlark/tests/builtins_bzl/cc_builtin_tests.sh +++ b/src/main/starlark/tests/builtins_bzl/cc_builtin_tests.sh @@ -61,6 +61,7 @@ function test_starlark_cc() { mkdir -p "src/conditions" cp "$(rlocation "io_bazel/src/conditions/BUILD")" "src/conditions/BUILD" + add_rules_cc "MODULE.bazel" cat >> MODULE.bazel< override/BUILD < override/cc/private/toolchain/cc_configure.bzl < override/cc/toolchains/toolchain_config_utils.bzl <> MODULE.bazel <> MODULE.bazel <<'EOF' -cc_configure = use_extension("@bazel_tools//tools/cpp:cc_configure.bzl", "cc_configure_extension") +cc_configure = use_extension("@rules_cc//cc:extensions.bzl", "cc_configure_extension") use_repo(cc_configure, "local_config_cc") EOF diff --git a/src/test/tools/bzlmod/MODULE.bazel.lock b/src/test/tools/bzlmod/MODULE.bazel.lock index dca900280aea73..63b3b0b2f56866 100644 --- a/src/test/tools/bzlmod/MODULE.bazel.lock +++ b/src/test/tools/bzlmod/MODULE.bazel.lock @@ -40,7 +40,8 @@ "https://bcr.bazel.build/modules/protobuf/27.0/source.json": "1acf3d080c728d42f423fde5422fd0a1a24f44c15908124ce12363a253384193", "https://bcr.bazel.build/modules/rules_cc/0.0.1/MODULE.bazel": "cb2aa0747f84c6c3a78dad4e2049c154f08ab9d166b1273835a8174940365647", "https://bcr.bazel.build/modules/rules_cc/0.0.10/MODULE.bazel": "ec1705118f7eaedd6e118508d3d26deba2a4e76476ada7e0e3965211be012002", - "https://bcr.bazel.build/modules/rules_cc/0.0.10/source.json": "90310b16e0e7df0cf40f8d1dccd7d373360f42419a6bfbbf5bb013182dd70e84", + "https://bcr.bazel.build/modules/rules_cc/0.0.12/MODULE.bazel": "28259f5cb8dd72d7503eb4fd1f9c89ab13759a438b1b78cb9655568d8566d7f9", + "https://bcr.bazel.build/modules/rules_cc/0.0.12/source.json": "e04b3b0e32e3eb102e551143610cbfe8cf836b9825c8c9d22084586de03dbe12", "https://bcr.bazel.build/modules/rules_cc/0.0.2/MODULE.bazel": "6915987c90970493ab97393024c156ea8fb9f3bea953b2f3ec05c34f19b5695c", "https://bcr.bazel.build/modules/rules_cc/0.0.6/MODULE.bazel": "abf360251023dfe3efcef65ab9d56beefa8394d4176dd29529750e1c57eaa33f", "https://bcr.bazel.build/modules/rules_cc/0.0.8/MODULE.bazel": "964c85c82cfeb6f3855e6a07054fdb159aced38e99a5eecf7bce9d53990afa3e", @@ -100,7 +101,7 @@ "@@rules_jvm_external+//:extensions.bzl%maven": { "general": { "bzlTransitiveDigest": "mLp5egTYHBwh51cnzz5DFLc8C6bKoL2o7uOj7ozbGiI=", - "usagesDigest": "ohRl9OQfT0h3QfYtB8SE6k43dD80+M1e12/ehyMtmno=", + "usagesDigest": "D4pzNNc0xMo/xkafrajjWOmuEsgZjCK/xfDI5gVSzU4=", "recordedFileInputs": { "@@rules_jvm_external+//rules_jvm_external_deps_install.json": "3ab1f67b0de4815df110bc72ccd6c77882b3b21d3d1e0a84445847b6ce3235a3", "@@stardoc+//maven_install.json": "de0bfa778b4ed6aebb77509362dd87ab8d20fc7c7c18d2a7429cdfee03949a21" @@ -108,230 +109,6 @@ "recordedDirentsInputs": {}, "envVariables": {}, "generatedRepoSpecs": { - "unpinned_stardoc_maven": { - "bzlFile": "@@rules_jvm_external+//:coursier.bzl", - "ruleClassName": "coursier_fetch", - "attributes": { - "repositories": [ - "{ \"repo_url\": \"https://repo1.maven.org/maven2\" }" - ], - "artifacts": [ - "{ \"group\": \"com.beust\", \"artifact\": \"jcommander\", \"version\": \"1.82\" }", - "{ \"group\": \"com.google.escapevelocity\", \"artifact\": \"escapevelocity\", \"version\": \"1.1\" }", - "{ \"group\": \"com.google.guava\", \"artifact\": \"guava\", \"version\": \"31.1-jre\" }", - "{ \"group\": \"com.google.truth\", \"artifact\": \"truth\", \"version\": \"1.1.3\" }", - "{ \"group\": \"junit\", \"artifact\": \"junit\", \"version\": \"4.13.2\" }" - ], - "fail_on_missing_checksum": true, - "fetch_sources": true, - "fetch_javadoc": false, - "excluded_artifacts": [], - "generate_compat_repositories": false, - "version_conflict_policy": "default", - "override_targets": {}, - "strict_visibility": true, - "strict_visibility_value": [ - "@@//visibility:private" - ], - "maven_install_json": "@@stardoc+//:maven_install.json", - "resolve_timeout": 600, - "jetify": false, - "jetify_include_list": [ - "*" - ], - "use_starlark_android_rules": false, - "aar_import_bzl_label": "@build_bazel_rules_android//android:rules.bzl", - "duplicate_version_warning": "warn" - } - }, - "com_beust_jcommander_1_82": { - "bzlFile": "@@bazel_tools//tools/build_defs/repo:http.bzl", - "ruleClassName": "http_file", - "attributes": { - "sha256": "deeac157c8de6822878d85d0c7bc8467a19cc8484d37788f7804f039dde280b1", - "urls": [ - "https://repo1.maven.org/maven2/com/beust/jcommander/1.82/jcommander-1.82.jar" - ], - "downloaded_file_path": "com/beust/jcommander/1.82/jcommander-1.82.jar" - } - }, - "com_google_auto_value_auto_value_annotations_1_8_1": { - "bzlFile": "@@bazel_tools//tools/build_defs/repo:http.bzl", - "ruleClassName": "http_file", - "attributes": { - "sha256": "37ec09b47d7ed35a99d13927db5c86fc9071f620f943ead5d757144698310852", - "urls": [ - "https://repo1.maven.org/maven2/com/google/auto/value/auto-value-annotations/1.8.1/auto-value-annotations-1.8.1.jar" - ], - "downloaded_file_path": "com/google/auto/value/auto-value-annotations/1.8.1/auto-value-annotations-1.8.1.jar" - } - }, - "com_google_code_findbugs_jsr305_3_0_2": { - "bzlFile": "@@bazel_tools//tools/build_defs/repo:http.bzl", - "ruleClassName": "http_file", - "attributes": { - "sha256": "766ad2a0783f2687962c8ad74ceecc38a28b9f72a2d085ee438b7813e928d0c7", - "urls": [ - "https://repo1.maven.org/maven2/com/google/code/findbugs/jsr305/3.0.2/jsr305-3.0.2.jar" - ], - "downloaded_file_path": "com/google/code/findbugs/jsr305/3.0.2/jsr305-3.0.2.jar" - } - }, - "com_google_errorprone_error_prone_annotations_2_11_0": { - "bzlFile": "@@bazel_tools//tools/build_defs/repo:http.bzl", - "ruleClassName": "http_file", - "attributes": { - "sha256": "721cb91842b46fa056847d104d5225c8b8e1e8b62263b993051e1e5a0137b7ec", - "urls": [ - "https://repo1.maven.org/maven2/com/google/errorprone/error_prone_annotations/2.11.0/error_prone_annotations-2.11.0.jar" - ], - "downloaded_file_path": "com/google/errorprone/error_prone_annotations/2.11.0/error_prone_annotations-2.11.0.jar" - } - }, - "com_google_escapevelocity_escapevelocity_1_1": { - "bzlFile": "@@bazel_tools//tools/build_defs/repo:http.bzl", - "ruleClassName": "http_file", - "attributes": { - "sha256": "37e76e4466836dedb864fb82355cd01c3bd21325ab642d89a0f759291b171231", - "urls": [ - "https://repo1.maven.org/maven2/com/google/escapevelocity/escapevelocity/1.1/escapevelocity-1.1.jar" - ], - "downloaded_file_path": "com/google/escapevelocity/escapevelocity/1.1/escapevelocity-1.1.jar" - } - }, - "com_google_guava_failureaccess_1_0_1": { - "bzlFile": "@@bazel_tools//tools/build_defs/repo:http.bzl", - "ruleClassName": "http_file", - "attributes": { - "sha256": "a171ee4c734dd2da837e4b16be9df4661afab72a41adaf31eb84dfdaf936ca26", - "urls": [ - "https://repo1.maven.org/maven2/com/google/guava/failureaccess/1.0.1/failureaccess-1.0.1.jar" - ], - "downloaded_file_path": "com/google/guava/failureaccess/1.0.1/failureaccess-1.0.1.jar" - } - }, - "com_google_guava_guava_31_1_jre": { - "bzlFile": "@@bazel_tools//tools/build_defs/repo:http.bzl", - "ruleClassName": "http_file", - "attributes": { - "sha256": "a42edc9cab792e39fe39bb94f3fca655ed157ff87a8af78e1d6ba5b07c4a00ab", - "urls": [ - "https://repo1.maven.org/maven2/com/google/guava/guava/31.1-jre/guava-31.1-jre.jar" - ], - "downloaded_file_path": "com/google/guava/guava/31.1-jre/guava-31.1-jre.jar" - } - }, - "com_google_guava_listenablefuture_9999_0_empty_to_avoid_conflict_with_guava": { - "bzlFile": "@@bazel_tools//tools/build_defs/repo:http.bzl", - "ruleClassName": "http_file", - "attributes": { - "sha256": "b372a037d4230aa57fbeffdef30fd6123f9c0c2db85d0aced00c91b974f33f99", - "urls": [ - "https://repo1.maven.org/maven2/com/google/guava/listenablefuture/9999.0-empty-to-avoid-conflict-with-guava/listenablefuture-9999.0-empty-to-avoid-conflict-with-guava.jar" - ], - "downloaded_file_path": "com/google/guava/listenablefuture/9999.0-empty-to-avoid-conflict-with-guava/listenablefuture-9999.0-empty-to-avoid-conflict-with-guava.jar" - } - }, - "com_google_j2objc_j2objc_annotations_1_3": { - "bzlFile": "@@bazel_tools//tools/build_defs/repo:http.bzl", - "ruleClassName": "http_file", - "attributes": { - "sha256": "21af30c92267bd6122c0e0b4d20cccb6641a37eaf956c6540ec471d584e64a7b", - "urls": [ - "https://repo1.maven.org/maven2/com/google/j2objc/j2objc-annotations/1.3/j2objc-annotations-1.3.jar" - ], - "downloaded_file_path": "com/google/j2objc/j2objc-annotations/1.3/j2objc-annotations-1.3.jar" - } - }, - "com_google_truth_truth_1_1_3": { - "bzlFile": "@@bazel_tools//tools/build_defs/repo:http.bzl", - "ruleClassName": "http_file", - "attributes": { - "sha256": "fc0b67782289a2aabfddfdf99eff1dcd5edc890d49143fcd489214b107b8f4f3", - "urls": [ - "https://repo1.maven.org/maven2/com/google/truth/truth/1.1.3/truth-1.1.3.jar" - ], - "downloaded_file_path": "com/google/truth/truth/1.1.3/truth-1.1.3.jar" - } - }, - "junit_junit_4_13_2": { - "bzlFile": "@@bazel_tools//tools/build_defs/repo:http.bzl", - "ruleClassName": "http_file", - "attributes": { - "sha256": "8e495b634469d64fb8acfa3495a065cbacc8a0fff55ce1e31007be4c16dc57d3", - "urls": [ - "https://repo1.maven.org/maven2/junit/junit/4.13.2/junit-4.13.2.jar" - ], - "downloaded_file_path": "junit/junit/4.13.2/junit-4.13.2.jar" - } - }, - "org_checkerframework_checker_qual_3_13_0": { - "bzlFile": "@@bazel_tools//tools/build_defs/repo:http.bzl", - "ruleClassName": "http_file", - "attributes": { - "sha256": "3ea0dcd73b4d6cb2fb34bd7ed4dad6db327a01ebad7db05eb7894076b3d64491", - "urls": [ - "https://repo1.maven.org/maven2/org/checkerframework/checker-qual/3.13.0/checker-qual-3.13.0.jar" - ], - "downloaded_file_path": "org/checkerframework/checker-qual/3.13.0/checker-qual-3.13.0.jar" - } - }, - "org_hamcrest_hamcrest_core_1_3": { - "bzlFile": "@@bazel_tools//tools/build_defs/repo:http.bzl", - "ruleClassName": "http_file", - "attributes": { - "sha256": "66fdef91e9739348df7a096aa384a5685f4e875584cce89386a7a47251c4d8e9", - "urls": [ - "https://repo1.maven.org/maven2/org/hamcrest/hamcrest-core/1.3/hamcrest-core-1.3.jar" - ], - "downloaded_file_path": "org/hamcrest/hamcrest-core/1.3/hamcrest-core-1.3.jar" - } - }, - "org_ow2_asm_asm_9_1": { - "bzlFile": "@@bazel_tools//tools/build_defs/repo:http.bzl", - "ruleClassName": "http_file", - "attributes": { - "sha256": "cda4de455fab48ff0bcb7c48b4639447d4de859a7afc30a094a986f0936beba2", - "urls": [ - "https://repo1.maven.org/maven2/org/ow2/asm/asm/9.1/asm-9.1.jar" - ], - "downloaded_file_path": "org/ow2/asm/asm/9.1/asm-9.1.jar" - } - }, - "stardoc_maven": { - "bzlFile": "@@rules_jvm_external+//:coursier.bzl", - "ruleClassName": "pinned_coursier_fetch", - "attributes": { - "repositories": [ - "{ \"repo_url\": \"https://repo1.maven.org/maven2\" }" - ], - "artifacts": [ - "{ \"group\": \"com.beust\", \"artifact\": \"jcommander\", \"version\": \"1.82\" }", - "{ \"group\": \"com.google.escapevelocity\", \"artifact\": \"escapevelocity\", \"version\": \"1.1\" }", - "{ \"group\": \"com.google.guava\", \"artifact\": \"guava\", \"version\": \"31.1-jre\" }", - "{ \"group\": \"com.google.truth\", \"artifact\": \"truth\", \"version\": \"1.1.3\" }", - "{ \"group\": \"junit\", \"artifact\": \"junit\", \"version\": \"4.13.2\" }" - ], - "fetch_sources": true, - "fetch_javadoc": false, - "generate_compat_repositories": false, - "maven_install_json": "@@stardoc+//:maven_install.json", - "override_targets": {}, - "strict_visibility": true, - "strict_visibility_value": [ - "@@//visibility:private" - ], - "jetify": false, - "jetify_include_list": [ - "*" - ], - "additional_netrc_lines": [], - "fail_if_repin_required": true, - "use_starlark_android_rules": false, - "aar_import_bzl_label": "@build_bazel_rules_android//android:rules.bzl", - "duplicate_version_warning": "warn" - } - }, "unpinned_rules_jvm_external_deps": { "bzlFile": "@@rules_jvm_external+//:coursier.bzl", "ruleClassName": "coursier_fetch", @@ -540,6 +317,18 @@ "downloaded_file_path": "com/google/cloud/google-cloud-storage/1.113.4/google-cloud-storage-1.113.4.jar" } }, + "com_google_code_findbugs_jsr305_3_0_2": { + "bzlFile": "@@bazel_tools//tools/build_defs/repo:http.bzl", + "ruleClassName": "http_file", + "attributes": { + "sha256": "766ad2a0783f2687962c8ad74ceecc38a28b9f72a2d085ee438b7813e928d0c7", + "urls": [ + "https://repo1.maven.org/maven2/com/google/code/findbugs/jsr305/3.0.2/jsr305-3.0.2.jar", + "https://maven.google.com/com/google/code/findbugs/jsr305/3.0.2/jsr305-3.0.2.jar" + ], + "downloaded_file_path": "com/google/code/findbugs/jsr305/3.0.2/jsr305-3.0.2.jar" + } + }, "com_google_code_gson_gson_2_9_0": { "bzlFile": "@@bazel_tools//tools/build_defs/repo:http.bzl", "ruleClassName": "http_file", @@ -552,6 +341,18 @@ "downloaded_file_path": "com/google/code/gson/gson/2.9.0/gson-2.9.0.jar" } }, + "com_google_errorprone_error_prone_annotations_2_11_0": { + "bzlFile": "@@bazel_tools//tools/build_defs/repo:http.bzl", + "ruleClassName": "http_file", + "attributes": { + "sha256": "721cb91842b46fa056847d104d5225c8b8e1e8b62263b993051e1e5a0137b7ec", + "urls": [ + "https://repo1.maven.org/maven2/com/google/errorprone/error_prone_annotations/2.11.0/error_prone_annotations-2.11.0.jar", + "https://maven.google.com/com/google/errorprone/error_prone_annotations/2.11.0/error_prone_annotations-2.11.0.jar" + ], + "downloaded_file_path": "com/google/errorprone/error_prone_annotations/2.11.0/error_prone_annotations-2.11.0.jar" + } + }, "com_google_googlejavaformat_google_java_format_1_15_0": { "bzlFile": "@@bazel_tools//tools/build_defs/repo:http.bzl", "ruleClassName": "http_file", @@ -564,6 +365,42 @@ "downloaded_file_path": "com/google/googlejavaformat/google-java-format/1.15.0/google-java-format-1.15.0.jar" } }, + "com_google_guava_failureaccess_1_0_1": { + "bzlFile": "@@bazel_tools//tools/build_defs/repo:http.bzl", + "ruleClassName": "http_file", + "attributes": { + "sha256": "a171ee4c734dd2da837e4b16be9df4661afab72a41adaf31eb84dfdaf936ca26", + "urls": [ + "https://repo1.maven.org/maven2/com/google/guava/failureaccess/1.0.1/failureaccess-1.0.1.jar", + "https://maven.google.com/com/google/guava/failureaccess/1.0.1/failureaccess-1.0.1.jar" + ], + "downloaded_file_path": "com/google/guava/failureaccess/1.0.1/failureaccess-1.0.1.jar" + } + }, + "com_google_guava_guava_31_1_jre": { + "bzlFile": "@@bazel_tools//tools/build_defs/repo:http.bzl", + "ruleClassName": "http_file", + "attributes": { + "sha256": "a42edc9cab792e39fe39bb94f3fca655ed157ff87a8af78e1d6ba5b07c4a00ab", + "urls": [ + "https://repo1.maven.org/maven2/com/google/guava/guava/31.1-jre/guava-31.1-jre.jar", + "https://maven.google.com/com/google/guava/guava/31.1-jre/guava-31.1-jre.jar" + ], + "downloaded_file_path": "com/google/guava/guava/31.1-jre/guava-31.1-jre.jar" + } + }, + "com_google_guava_listenablefuture_9999_0_empty_to_avoid_conflict_with_guava": { + "bzlFile": "@@bazel_tools//tools/build_defs/repo:http.bzl", + "ruleClassName": "http_file", + "attributes": { + "sha256": "b372a037d4230aa57fbeffdef30fd6123f9c0c2db85d0aced00c91b974f33f99", + "urls": [ + "https://repo1.maven.org/maven2/com/google/guava/listenablefuture/9999.0-empty-to-avoid-conflict-with-guava/listenablefuture-9999.0-empty-to-avoid-conflict-with-guava.jar", + "https://maven.google.com/com/google/guava/listenablefuture/9999.0-empty-to-avoid-conflict-with-guava/listenablefuture-9999.0-empty-to-avoid-conflict-with-guava.jar" + ], + "downloaded_file_path": "com/google/guava/listenablefuture/9999.0-empty-to-avoid-conflict-with-guava/listenablefuture-9999.0-empty-to-avoid-conflict-with-guava.jar" + } + }, "com_google_http_client_google_http_client_1_38_0": { "bzlFile": "@@bazel_tools//tools/build_defs/repo:http.bzl", "ruleClassName": "http_file", @@ -600,6 +437,18 @@ "downloaded_file_path": "com/google/http-client/google-http-client-jackson2/1.38.0/google-http-client-jackson2-1.38.0.jar" } }, + "com_google_j2objc_j2objc_annotations_1_3": { + "bzlFile": "@@bazel_tools//tools/build_defs/repo:http.bzl", + "ruleClassName": "http_file", + "attributes": { + "sha256": "21af30c92267bd6122c0e0b4d20cccb6641a37eaf956c6540ec471d584e64a7b", + "urls": [ + "https://repo1.maven.org/maven2/com/google/j2objc/j2objc-annotations/1.3/j2objc-annotations-1.3.jar", + "https://maven.google.com/com/google/j2objc/j2objc-annotations/1.3/j2objc-annotations-1.3.jar" + ], + "downloaded_file_path": "com/google/j2objc/j2objc-annotations/1.3/j2objc-annotations-1.3.jar" + } + }, "com_google_oauth_client_google_oauth_client_1_31_1": { "bzlFile": "@@bazel_tools//tools/build_defs/repo:http.bzl", "ruleClassName": "http_file", @@ -1249,6 +1098,164 @@ "aar_import_bzl_label": "@build_bazel_rules_android//android:rules.bzl", "duplicate_version_warning": "warn" } + }, + "unpinned_stardoc_maven": { + "bzlFile": "@@rules_jvm_external+//:coursier.bzl", + "ruleClassName": "coursier_fetch", + "attributes": { + "repositories": [ + "{ \"repo_url\": \"https://repo1.maven.org/maven2\" }" + ], + "artifacts": [ + "{ \"group\": \"com.beust\", \"artifact\": \"jcommander\", \"version\": \"1.82\" }", + "{ \"group\": \"com.google.escapevelocity\", \"artifact\": \"escapevelocity\", \"version\": \"1.1\" }", + "{ \"group\": \"com.google.guava\", \"artifact\": \"guava\", \"version\": \"31.1-jre\" }", + "{ \"group\": \"com.google.truth\", \"artifact\": \"truth\", \"version\": \"1.1.3\" }", + "{ \"group\": \"junit\", \"artifact\": \"junit\", \"version\": \"4.13.2\" }" + ], + "fail_on_missing_checksum": true, + "fetch_sources": true, + "fetch_javadoc": false, + "excluded_artifacts": [], + "generate_compat_repositories": false, + "version_conflict_policy": "default", + "override_targets": {}, + "strict_visibility": true, + "strict_visibility_value": [ + "@@//visibility:private" + ], + "maven_install_json": "@@stardoc+//:maven_install.json", + "resolve_timeout": 600, + "jetify": false, + "jetify_include_list": [ + "*" + ], + "use_starlark_android_rules": false, + "aar_import_bzl_label": "@build_bazel_rules_android//android:rules.bzl", + "duplicate_version_warning": "warn" + } + }, + "com_beust_jcommander_1_82": { + "bzlFile": "@@bazel_tools//tools/build_defs/repo:http.bzl", + "ruleClassName": "http_file", + "attributes": { + "sha256": "deeac157c8de6822878d85d0c7bc8467a19cc8484d37788f7804f039dde280b1", + "urls": [ + "https://repo1.maven.org/maven2/com/beust/jcommander/1.82/jcommander-1.82.jar" + ], + "downloaded_file_path": "com/beust/jcommander/1.82/jcommander-1.82.jar" + } + }, + "com_google_auto_value_auto_value_annotations_1_8_1": { + "bzlFile": "@@bazel_tools//tools/build_defs/repo:http.bzl", + "ruleClassName": "http_file", + "attributes": { + "sha256": "37ec09b47d7ed35a99d13927db5c86fc9071f620f943ead5d757144698310852", + "urls": [ + "https://repo1.maven.org/maven2/com/google/auto/value/auto-value-annotations/1.8.1/auto-value-annotations-1.8.1.jar" + ], + "downloaded_file_path": "com/google/auto/value/auto-value-annotations/1.8.1/auto-value-annotations-1.8.1.jar" + } + }, + "com_google_escapevelocity_escapevelocity_1_1": { + "bzlFile": "@@bazel_tools//tools/build_defs/repo:http.bzl", + "ruleClassName": "http_file", + "attributes": { + "sha256": "37e76e4466836dedb864fb82355cd01c3bd21325ab642d89a0f759291b171231", + "urls": [ + "https://repo1.maven.org/maven2/com/google/escapevelocity/escapevelocity/1.1/escapevelocity-1.1.jar" + ], + "downloaded_file_path": "com/google/escapevelocity/escapevelocity/1.1/escapevelocity-1.1.jar" + } + }, + "com_google_truth_truth_1_1_3": { + "bzlFile": "@@bazel_tools//tools/build_defs/repo:http.bzl", + "ruleClassName": "http_file", + "attributes": { + "sha256": "fc0b67782289a2aabfddfdf99eff1dcd5edc890d49143fcd489214b107b8f4f3", + "urls": [ + "https://repo1.maven.org/maven2/com/google/truth/truth/1.1.3/truth-1.1.3.jar" + ], + "downloaded_file_path": "com/google/truth/truth/1.1.3/truth-1.1.3.jar" + } + }, + "junit_junit_4_13_2": { + "bzlFile": "@@bazel_tools//tools/build_defs/repo:http.bzl", + "ruleClassName": "http_file", + "attributes": { + "sha256": "8e495b634469d64fb8acfa3495a065cbacc8a0fff55ce1e31007be4c16dc57d3", + "urls": [ + "https://repo1.maven.org/maven2/junit/junit/4.13.2/junit-4.13.2.jar" + ], + "downloaded_file_path": "junit/junit/4.13.2/junit-4.13.2.jar" + } + }, + "org_checkerframework_checker_qual_3_13_0": { + "bzlFile": "@@bazel_tools//tools/build_defs/repo:http.bzl", + "ruleClassName": "http_file", + "attributes": { + "sha256": "3ea0dcd73b4d6cb2fb34bd7ed4dad6db327a01ebad7db05eb7894076b3d64491", + "urls": [ + "https://repo1.maven.org/maven2/org/checkerframework/checker-qual/3.13.0/checker-qual-3.13.0.jar" + ], + "downloaded_file_path": "org/checkerframework/checker-qual/3.13.0/checker-qual-3.13.0.jar" + } + }, + "org_hamcrest_hamcrest_core_1_3": { + "bzlFile": "@@bazel_tools//tools/build_defs/repo:http.bzl", + "ruleClassName": "http_file", + "attributes": { + "sha256": "66fdef91e9739348df7a096aa384a5685f4e875584cce89386a7a47251c4d8e9", + "urls": [ + "https://repo1.maven.org/maven2/org/hamcrest/hamcrest-core/1.3/hamcrest-core-1.3.jar" + ], + "downloaded_file_path": "org/hamcrest/hamcrest-core/1.3/hamcrest-core-1.3.jar" + } + }, + "org_ow2_asm_asm_9_1": { + "bzlFile": "@@bazel_tools//tools/build_defs/repo:http.bzl", + "ruleClassName": "http_file", + "attributes": { + "sha256": "cda4de455fab48ff0bcb7c48b4639447d4de859a7afc30a094a986f0936beba2", + "urls": [ + "https://repo1.maven.org/maven2/org/ow2/asm/asm/9.1/asm-9.1.jar" + ], + "downloaded_file_path": "org/ow2/asm/asm/9.1/asm-9.1.jar" + } + }, + "stardoc_maven": { + "bzlFile": "@@rules_jvm_external+//:coursier.bzl", + "ruleClassName": "pinned_coursier_fetch", + "attributes": { + "repositories": [ + "{ \"repo_url\": \"https://repo1.maven.org/maven2\" }" + ], + "artifacts": [ + "{ \"group\": \"com.beust\", \"artifact\": \"jcommander\", \"version\": \"1.82\" }", + "{ \"group\": \"com.google.escapevelocity\", \"artifact\": \"escapevelocity\", \"version\": \"1.1\" }", + "{ \"group\": \"com.google.guava\", \"artifact\": \"guava\", \"version\": \"31.1-jre\" }", + "{ \"group\": \"com.google.truth\", \"artifact\": \"truth\", \"version\": \"1.1.3\" }", + "{ \"group\": \"junit\", \"artifact\": \"junit\", \"version\": \"4.13.2\" }" + ], + "fetch_sources": true, + "fetch_javadoc": false, + "generate_compat_repositories": false, + "maven_install_json": "@@stardoc+//:maven_install.json", + "override_targets": {}, + "strict_visibility": true, + "strict_visibility_value": [ + "@@//visibility:private" + ], + "jetify": false, + "jetify_include_list": [ + "*" + ], + "additional_netrc_lines": [], + "fail_if_repin_required": true, + "use_starlark_android_rules": false, + "aar_import_bzl_label": "@build_bazel_rules_android//android:rules.bzl", + "duplicate_version_warning": "warn" + } } }, "recordedRepoMappingEntries": [ diff --git a/tools/cpp/BUILD.empty.tpl b/tools/cpp/BUILD.empty.tpl deleted file mode 100644 index 89b491877e7268..00000000000000 --- a/tools/cpp/BUILD.empty.tpl +++ /dev/null @@ -1,54 +0,0 @@ -# Copyright 2018 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. - -load(":cc_toolchain_config.bzl", "cc_toolchain_config") - -package(default_visibility = ["//visibility:public"]) - -cc_library( - name = "link_extra_lib", -) - -cc_library( - name = "malloc", -) - -filegroup( - name = "empty", - srcs = [], -) - -cc_toolchain_suite( - name = "toolchain", - toolchains = { - "%{cpu}|local": ":local", - "%{cpu}": ":local", - }, -) - -cc_toolchain( - name = "local", - all_files = ":empty", - ar_files = ":empty", - as_files = ":empty", - compiler_files = ":empty", - dwp_files = ":empty", - linker_files = ":empty", - objcopy_files = ":empty", - strip_files = ":empty", - toolchain_config = ":local_config", - toolchain_identifier = "local", -) - -cc_toolchain_config(name = "local_config") diff --git a/tools/cpp/BUILD.static.bsd b/tools/cpp/BUILD.static.bsd deleted file mode 100644 index b0d52e651d29d2..00000000000000 --- a/tools/cpp/BUILD.static.bsd +++ /dev/null @@ -1,166 +0,0 @@ -# Copyright 2018 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. - -# This becomes the BUILD file for @local_config_cc// under FreeBSD and OpenBSD. - -load(":cc_toolchain_config.bzl", "cc_toolchain_config") -load("@rules_cc//cc:defs.bzl", "cc_library", "cc_toolchain", "cc_toolchain_suite") - -package(default_visibility = ["//visibility:public"]) - -cc_library(name = "empty_lib") - -# Label flag for extra libraries to be linked into every binary. -# TODO(bazel-team): Support passing flag multiple times to build a list. -label_flag( - name = "link_extra_libs", - build_setting_default = ":empty_lib", -) - -# The final extra library to be linked into every binary target. This collects -# the above flag, but may also include more libraries depending on config. -cc_library( - name = "link_extra_lib", - deps = [ - ":link_extra_libs", - ], -) - -cc_library( - name = "malloc", -) - -filegroup( - name = "empty", - srcs = [], -) - -# Hardcoded toolchain, legacy behaviour. -cc_toolchain_suite( - name = "toolchain", - toolchains = { - "armeabi-v7a|compiler": ":cc-compiler-armeabi-v7a", - "freebsd|compiler": ":cc-compiler-freebsd", - "openbsd|compiler": ":cc-compiler-openbsd", - "armeabi-v7a": ":cc-compiler-armeabi-v7a", - "freebsd": ":cc-compiler-freebsd", - "openbsd": ":cc-compiler-openbsd", - }, -) - -cc_toolchain( - name = "cc-compiler-freebsd", - all_files = ":empty", - ar_files = ":empty", - as_files = ":empty", - compiler_files = ":empty", - dwp_files = ":empty", - linker_files = ":empty", - objcopy_files = ":empty", - strip_files = ":empty", - supports_param_files = 0, - toolchain_config = ":local_freebsd", - toolchain_identifier = "local_freebsd", -) - -cc_toolchain_config( - name = "local_freebsd", - cpu = "freebsd", -) - -toolchain( - name = "cc-toolchain-freebsd", - exec_compatible_with = [ - "@platforms//cpu:x86_64", - "@platforms//os:freebsd", - ], - target_compatible_with = [ - "@platforms//cpu:x86_64", - "@platforms//os:freebsd", - ], - toolchain = ":cc-compiler-freebsd", - toolchain_type = "@bazel_tools//tools/cpp:toolchain_type", -) - -cc_toolchain( - name = "cc-compiler-openbsd", - all_files = ":empty", - ar_files = ":empty", - as_files = ":empty", - compiler_files = ":empty", - dwp_files = ":empty", - linker_files = ":empty", - objcopy_files = ":empty", - strip_files = ":empty", - supports_param_files = 0, - toolchain_config = ":local_openbsd", - toolchain_identifier = "local_openbsd", -) - -cc_toolchain_config( - name = "local_openbsd", - cpu = "openbsd", -) - -toolchain( - name = "cc-toolchain-openbsd", - exec_compatible_with = [ - "@platforms//cpu:x86_64", - "@platforms//os:openbsd", - ], - target_compatible_with = [ - "@platforms//cpu:x86_64", - "@platforms//os:openbsd", - ], - toolchain = ":cc-compiler-openbsd", - toolchain_type = "@bazel_tools//tools/cpp:toolchain_type", -) - -cc_toolchain( - name = "cc-compiler-armeabi-v7a", - all_files = ":empty", - ar_files = ":empty", - as_files = ":empty", - compiler_files = ":empty", - dwp_files = ":empty", - linker_files = ":empty", - objcopy_files = ":empty", - strip_files = ":empty", - supports_param_files = 0, - toolchain_config = ":stub_armeabi-v7a", - toolchain_identifier = "stub_armeabi-v7a", -) - -cc_toolchain_config( - name = "stub_armeabi-v7a", - cpu = "armeabi-v7a", -) - -toolchain( - name = "cc-toolchain-armeabi-v7a", - exec_compatible_with = [ - "@platforms//cpu:arm", - ], - target_compatible_with = [ - "@platforms//cpu:armv7", - "@platforms//os:android", - ], - toolchain = ":cc-compiler-armeabi-v7a", - toolchain_type = "@bazel_tools//tools/cpp:toolchain_type", -) - -filegroup( - name = "link_dynamic_library", - srcs = ["link_dynamic_library.sh"], -) diff --git a/tools/cpp/BUILD.toolchains.tpl b/tools/cpp/BUILD.toolchains.tpl deleted file mode 100644 index 7d3d6d6fb9706e..00000000000000 --- a/tools/cpp/BUILD.toolchains.tpl +++ /dev/null @@ -1,20 +0,0 @@ -load("@local_config_platform//:constraints.bzl", "HOST_CONSTRAINTS") - -toolchain( - name = "cc-toolchain-%{name}", - exec_compatible_with = HOST_CONSTRAINTS, - target_compatible_with = HOST_CONSTRAINTS, - toolchain = "@local_config_cc//:cc-compiler-%{name}", - toolchain_type = "@bazel_tools//tools/cpp:toolchain_type", -) - -toolchain( - name = "cc-toolchain-armeabi-v7a", - exec_compatible_with = HOST_CONSTRAINTS, - target_compatible_with = [ - "@platforms//cpu:armv7", - "@platforms//os:android", - ], - toolchain = "@local_config_cc//:cc-compiler-armeabi-v7a", - toolchain_type = "@bazel_tools//tools/cpp:toolchain_type", -) diff --git a/tools/cpp/BUILD.tools b/tools/cpp/BUILD.tools index d950d1ede4761e..a5aae3351b65b8 100644 --- a/tools/cpp/BUILD.tools +++ b/tools/cpp/BUILD.tools @@ -22,47 +22,32 @@ toolchain_type(name = "toolchain_type") # The toolchain_type used for cc test runners. toolchain_type(name = "test_runner_toolchain_type") -# It is frequently necessary to constrain platforms based on the cc compiler type. -constraint_setting(name = "cc_compiler") - -constraint_value( - name = "clang", - constraint_setting = ":cc_compiler", -) - -constraint_value( - name = "gcc", - constraint_setting = ":cc_compiler", -) - -constraint_value( - name = "msvc", - constraint_setting = ":cc_compiler", -) - -constraint_value( - name = "clang-cl", - constraint_setting = ":cc_compiler", -) - -constraint_value( - name = "mingw", - constraint_setting = ":cc_compiler", -) - -constraint_value( - name = "msys", - constraint_setting = ":cc_compiler", -) - -cc_toolchain_alias(name = "current_cc_toolchain") - -cc_toolchain_alias( - name = "optional_current_cc_toolchain", - mandatory = False, -) - -cc_libc_top_alias(name = "current_libc_top") +# Aliases to @rules_cc +[ + alias( + name = target, + actual = actual, + deprecation = "Please use %s instead." % actual, + ) + for target, actual in { + "cc_compiler": "@rules_cc//cc/private/toolchain:cc_compiler", + "clang": "@rules_cc//cc/private/toolchain:clang", + "gcc": "@rules_cc//cc/private/toolchain:gcc", + "msvc": "@rules_cc//cc/private/toolchain:msvc", + "clang-cl": "@rules_cc//cc/private/toolchain:clang-cl", + "mingw": "@rules_cc//cc/private/toolchain:mingw", + "msys": "@rules_cc//cc/private/toolchain:msys", + "grep-includes": "@rules_cc//cc/private/toolchain:grep-includes", + "interface_library_builder": "@rules_cc//cc/private/toolchain:interface_library_builder", + "link_dynamic_library": "@rules_cc//cc/private/toolchain:link_dynamic_library", + "lib_cc_configure": "@rules_cc//cc/private/toolchain:lib_cc_configure", + "compiler": "@rules_cc//cc/private/toolchain:compiler", + "cc_flags": "@rules_cc//cc/private/toolchain:cc_flags", + "current_cc_toolchain": "@rules_cc//cc:current_cc_toolchain", + "optional_current_cc_toolchain": "@rules_cc//cc:optional_current_cc_toolchain", + "current_libc_top": "@rules_cc//cc:current_libc_top", + }.items() +] cc_library( name = "empty_lib", @@ -91,11 +76,6 @@ cc_library( tags = ["__DONT_DEPEND_ON_DEF_PARSER__"], ) -filegroup( - name = "grep-includes", - srcs = ["grep-includes.sh"], -) - filegroup( name = "aggregate-ddi", srcs = ["//tools/cpp/modules_tools:aggregate-ddi-bin"], @@ -111,6 +91,12 @@ filegroup( srcs = [], ) +filegroup( + name = "bzl_srcs", + srcs = glob(["*.bzl"]), + visibility = ["//tools:__pkg__"], +) + config_setting( name = "disable_static_cc_toolchains", values = { @@ -136,64 +122,3 @@ alias( name = "host_xcodes", actual = "@local_config_xcode//:host_xcodes", ) - -filegroup( - name = "srcs", - srcs = glob(["**"]) + [ - "//tools/cpp/runfiles:srcs", - ], -) - -filegroup( - name = "embedded_tools", - srcs = glob(["**"]) + [ - "//tools/cpp/runfiles:embedded_tools", - ], -) - -filegroup( - name = "interface_library_builder", - srcs = ["build_interface_so"], -) - -filegroup( - name = "link_dynamic_library", - srcs = ["link_dynamic_library.sh"], -) - -filegroup( - name = "lib_cc_configure", - srcs = ["lib_cc_configure.bzl"], -) - -filegroup( - name = "bzl_srcs", - srcs = glob(["*.bzl"]), - visibility = ["//tools:__pkg__"], -) - -cc_library( - name = "build_info_translation_helper", - srcs = [":build_info_translation_helper.cc"], - hdrs = [":build_info_translation_helper.h"], - deps = [ - "@com_google_absl//absl/status", - "@com_google_absl//absl/strings"], -) - -cc_library( - name = "bazel_build_info_translation_helper", - srcs = [":bazel_build_info_translation_helper.cc"], - hdrs = [":bazel_build_info_translation_helper.h"], - deps = [":build_info_translation_helper"], -) - -load(":compiler_flag.bzl", "compiler_flag") - -compiler_flag(name = "compiler") - -# Target that can provide the CC_FLAGS variable based on the current -# cc_toolchain. -load("@bazel_tools//tools/cpp:cc_flags_supplier.bzl", "cc_flags_supplier") - -cc_flags_supplier(name = "cc_flags") diff --git a/tools/cpp/BUILD.tpl b/tools/cpp/BUILD.tpl deleted file mode 100644 index 99896dc93f3054..00000000000000 --- a/tools/cpp/BUILD.tpl +++ /dev/null @@ -1,144 +0,0 @@ -# Copyright 2016 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. - -# This becomes the BUILD file for @local_config_cc// under non-BSD unixes. - -load(":cc_toolchain_config.bzl", "cc_toolchain_config") -load(":armeabi_cc_toolchain_config.bzl", "armeabi_cc_toolchain_config") -load("@rules_cc//cc:defs.bzl", "cc_toolchain", "cc_toolchain_suite") - -package(default_visibility = ["//visibility:public"]) - -licenses(["notice"]) # Apache 2.0 - -cc_library(name = "empty_lib") - -# Label flag for extra libraries to be linked into every binary. -# TODO(bazel-team): Support passing flag multiple times to build a list. -label_flag( - name = "link_extra_libs", - build_setting_default = ":empty_lib", -) - -# The final extra library to be linked into every binary target. This collects -# the above flag, but may also include more libraries depending on config. -cc_library( - name = "link_extra_lib", - deps = [ - ":link_extra_libs", - ], -) - -cc_library( - name = "malloc", -) - -filegroup( - name = "empty", - srcs = [], -) - -filegroup( - name = "cc_wrapper", - srcs = ["cc_wrapper.sh"], -) - -filegroup( - name = "validate_static_library", - srcs = ["validate_static_library.sh"], -) - -filegroup( - name = "deps_scanner_wrapper", - srcs = ["deps_scanner_wrapper.sh"], -) -filegroup( - name = "compiler_deps", - srcs = glob(["extra_tools/**"], allow_empty = True) + [%{cc_compiler_deps}], -) - -# This is the entry point for --crosstool_top. Toolchains are found -# by lopping off the name of --crosstool_top and searching for -# the "${CPU}" entry in the toolchains attribute. -cc_toolchain_suite( - name = "toolchain", - toolchains = { - "%{name}|%{compiler}": ":cc-compiler-%{name}", - "%{name}": ":cc-compiler-%{name}", - "armeabi-v7a|compiler": ":cc-compiler-armeabi-v7a", - "armeabi-v7a": ":cc-compiler-armeabi-v7a", - }, -) - -cc_toolchain( - name = "cc-compiler-%{name}", - toolchain_identifier = "%{cc_toolchain_identifier}", - toolchain_config = ":%{cc_toolchain_identifier}", - all_files = ":compiler_deps", - ar_files = ":compiler_deps", - as_files = ":compiler_deps", - compiler_files = ":compiler_deps", - dwp_files = ":empty", - linker_files = ":compiler_deps", - objcopy_files = ":empty", - strip_files = ":empty", - supports_header_parsing = 1, - supports_param_files = 1, - module_map = %{modulemap}, -) - -cc_toolchain_config( - name = "%{cc_toolchain_identifier}", - cpu = "%{target_cpu}", - compiler = "%{compiler}", - toolchain_identifier = "%{cc_toolchain_identifier}", - host_system_name = "%{host_system_name}", - target_system_name = "%{target_system_name}", - target_libc = "%{target_libc}", - abi_version = "%{abi_version}", - abi_libc_version = "%{abi_libc_version}", - cxx_builtin_include_directories = [%{cxx_builtin_include_directories}], - tool_paths = {%{tool_paths}}, - compile_flags = [%{compile_flags}], - opt_compile_flags = [%{opt_compile_flags}], - dbg_compile_flags = [%{dbg_compile_flags}], - conly_flags = [%{conly_flags}], - cxx_flags = [%{cxx_flags}], - link_flags = [%{link_flags}], - link_libs = [%{link_libs}], - opt_link_flags = [%{opt_link_flags}], - unfiltered_compile_flags = [%{unfiltered_compile_flags}], - coverage_compile_flags = [%{coverage_compile_flags}], - coverage_link_flags = [%{coverage_link_flags}], - supports_start_end_lib = %{supports_start_end_lib}, - extra_flags_per_feature = %{extra_flags_per_feature}, -) - -# Android tooling requires a default toolchain for the armeabi-v7a cpu. -cc_toolchain( - name = "cc-compiler-armeabi-v7a", - toolchain_identifier = "stub_armeabi-v7a", - toolchain_config = ":stub_armeabi-v7a", - all_files = ":empty", - ar_files = ":empty", - as_files = ":empty", - compiler_files = ":empty", - dwp_files = ":empty", - linker_files = ":empty", - objcopy_files = ":empty", - strip_files = ":empty", - supports_param_files = 1, -) - -armeabi_cc_toolchain_config(name = "stub_armeabi-v7a") diff --git a/tools/cpp/BUILD.windows.tpl b/tools/cpp/BUILD.windows.tpl deleted file mode 100644 index ec25b2ec368a62..00000000000000 --- a/tools/cpp/BUILD.windows.tpl +++ /dev/null @@ -1,716 +0,0 @@ -# Copyright 2018 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. - -# This becomes the BUILD file for @local_config_cc// under Windows. - -load("@rules_cc//cc:defs.bzl", "cc_toolchain", "cc_toolchain_suite", "cc_library") -load(":windows_cc_toolchain_config.bzl", "cc_toolchain_config") -load(":armeabi_cc_toolchain_config.bzl", "armeabi_cc_toolchain_config") - -package(default_visibility = ["//visibility:public"]) - -cc_library(name = "empty_lib") - -# Label flag for extra libraries to be linked into every binary. -# TODO(bazel-team): Support passing flag multiple times to build a list. -label_flag( - name = "link_extra_libs", - build_setting_default = ":empty_lib", -) - -# The final extra library to be linked into every binary target. This collects -# the above flag, but may also include more libraries depending on config. -cc_library( - name = "link_extra_lib", - deps = [ - ":link_extra_libs", - ], -) - -cc_library( - name = "malloc", -) - -filegroup( - name = "empty", - srcs = [], -) - -filegroup( - name = "mingw_compiler_files", - srcs = [":builtin_include_directory_paths_mingw"] -) - -filegroup( - name = "clangcl_compiler_files", - srcs = [":builtin_include_directory_paths_clangcl"] -) - -filegroup( - name = "msvc_compiler_files", - srcs = [ - ":builtin_include_directory_paths_msvc", - "%{msvc_deps_scanner_wrapper_path_x86}", - "%{msvc_deps_scanner_wrapper_path_x64}", - "%{msvc_deps_scanner_wrapper_path_arm}", - "%{msvc_deps_scanner_wrapper_path_arm64}", - ] -) - -# Hardcoded toolchain, legacy behaviour. -cc_toolchain_suite( - name = "toolchain", - toolchains = { - "armeabi-v7a|compiler": ":cc-compiler-armeabi-v7a", - "x64_windows|msvc-cl": ":cc-compiler-x64_windows", - "x64_x86_windows|msvc-cl": ":cc-compiler-x64_x86_windows", - "x64_arm_windows|msvc-cl": ":cc-compiler-x64_arm_windows", - "x64_arm64_windows|msvc-cl": ":cc-compiler-arm64_windows", - "arm64_windows|msvc-cl": ":cc-compiler-arm64_windows", - "x64_windows|msys-gcc": ":cc-compiler-x64_windows_msys", - "x64_x86_windows|msys-gcc": ":cc-compiler-x64_x86_windows_msys", - "x64_windows|mingw-gcc": ":cc-compiler-x64_windows_mingw", - "x64_x86_windows|mingw-gcc": ":cc-compiler-x64_x86_windows_mingw", - "x64_windows|clang-cl": ":cc-compiler-x64_windows-clang-cl", - "x64_windows_msys": ":cc-compiler-x64_windows_msys", - "x64_windows": ":cc-compiler-x64_windows", - "x64_x86_windows": ":cc-compiler-x64_x86_windows", - "x64_arm_windows": ":cc-compiler-x64_arm_windows", - "x64_arm64_windows": ":cc-compiler-arm64_windows", - "arm64_windows": ":cc-compiler-arm64_windows", - "x64_arm64_windows|clang-cl": ":cc-compiler-arm64_windows-clang-cl", - "arm64_windows|clang-cl": ":cc-compiler-arm64_windows-clang-cl", - "armeabi-v7a": ":cc-compiler-armeabi-v7a", - }, -) - -cc_toolchain( - name = "cc-compiler-x64_windows_msys", - toolchain_identifier = "msys_x64", - toolchain_config = ":msys_x64", - all_files = ":empty", - ar_files = ":empty", - as_files = ":mingw_compiler_files", - compiler_files = ":mingw_compiler_files", - dwp_files = ":empty", - linker_files = ":empty", - objcopy_files = ":empty", - strip_files = ":empty", - supports_param_files = 1, -) - -cc_toolchain_config( - name = "msys_x64", - cpu = "x64_windows", - compiler = "msys-gcc", - host_system_name = "local", - target_system_name = "local", - target_libc = "msys", - abi_version = "local", - abi_libc_version = "local", - cxx_builtin_include_directories = [%{cxx_builtin_include_directories}], - tool_paths = {%{tool_paths}}, - tool_bin_path = "%{tool_bin_path}", -) - -toolchain( - name = "cc-toolchain-x64_windows_msys", - exec_compatible_with = [ - "@platforms//cpu:x86_64", - "@platforms//os:windows", - "@bazel_tools//tools/cpp:msys", - ], - target_compatible_with = [ - "@platforms//cpu:x86_64", - "@platforms//os:windows", - ], - toolchain = ":cc-compiler-x64_windows_msys", - toolchain_type = "@bazel_tools//tools/cpp:toolchain_type", -) - -cc_toolchain( - name = "cc-compiler-x64_x86_windows_msys", - toolchain_identifier = "msys_x64_x86", - toolchain_config = ":msys_x64_x86", - all_files = ":empty", - ar_files = ":empty", - as_files = ":mingw_compiler_files", - compiler_files = ":mingw_compiler_files", - dwp_files = ":empty", - linker_files = ":empty", - objcopy_files = ":empty", - strip_files = ":empty", - supports_param_files = 1, -) - -cc_toolchain_config( - name = "msys_x64_x86", - cpu = "x64_x86_windows", - compiler = "msys-gcc", - host_system_name = "local", - target_system_name = "local", - target_libc = "msys", - abi_version = "local", - abi_libc_version = "local", - cxx_builtin_include_directories = [%{cxx_builtin_include_directories}], - tool_paths = {%{tool_paths}}, - tool_bin_path = "%{tool_bin_path}", - default_compile_flags = ["-m32"], - default_link_flags = ["-m32"], -) - -toolchain( - name = "cc-toolchain-x64_x86_windows_msys", - exec_compatible_with = [ - "@platforms//cpu:x86_64", - "@platforms//os:windows", - "@bazel_tools//tools/cpp:msys", - ], - target_compatible_with = [ - "@platforms//cpu:x86_32", - "@platforms//os:windows", - ], - toolchain = ":cc-compiler-x64_x86_windows_msys", - toolchain_type = "@bazel_tools//tools/cpp:toolchain_type", -) - -cc_toolchain( - name = "cc-compiler-x64_windows_mingw", - toolchain_identifier = "msys_x64_mingw", - toolchain_config = ":msys_x64_mingw", - all_files = ":empty", - ar_files = ":empty", - as_files = ":mingw_compiler_files", - compiler_files = ":mingw_compiler_files", - dwp_files = ":empty", - linker_files = ":empty", - objcopy_files = ":empty", - strip_files = ":empty", - supports_param_files = 0, -) - -cc_toolchain_config( - name = "msys_x64_mingw", - cpu = "x64_windows", - compiler = "mingw-gcc", - host_system_name = "local", - target_system_name = "local", - target_libc = "mingw", - abi_version = "local", - abi_libc_version = "local", - tool_bin_path = "%{mingw_tool_bin_path}", - cxx_builtin_include_directories = [%{mingw_cxx_builtin_include_directories}], - tool_paths = {%{mingw_tool_paths}}, -) - -toolchain( - name = "cc-toolchain-x64_windows_mingw", - exec_compatible_with = [ - "@platforms//cpu:x86_64", - "@platforms//os:windows", - "@bazel_tools//tools/cpp:mingw", - ], - target_compatible_with = [ - "@platforms//cpu:x86_64", - "@platforms//os:windows", - ], - toolchain = ":cc-compiler-x64_windows_mingw", - toolchain_type = "@bazel_tools//tools/cpp:toolchain_type", -) - -cc_toolchain( - name = "cc-compiler-x64_x86_windows_mingw", - toolchain_identifier = "msys_x64_x86_mingw", - toolchain_config = ":msys_x64_x86_mingw", - all_files = ":empty", - ar_files = ":empty", - as_files = ":mingw_compiler_files", - compiler_files = ":mingw_compiler_files", - dwp_files = ":empty", - linker_files = ":empty", - objcopy_files = ":empty", - strip_files = ":empty", - supports_param_files = 0, -) - -cc_toolchain_config( - name = "msys_x64_x86_mingw", - cpu = "x64_x86_windows", - compiler = "mingw-gcc", - host_system_name = "local", - target_system_name = "local", - target_libc = "mingw", - abi_version = "local", - abi_libc_version = "local", - tool_bin_path = "%{mingw_tool_bin_path}", - cxx_builtin_include_directories = [%{mingw_cxx_builtin_include_directories}], - tool_paths = {%{mingw_tool_paths}}, - default_compile_flags = ["-m32"], - default_link_flags = ["-m32"], -) - -toolchain( - name = "cc-toolchain-x64_x86_windows_mingw", - exec_compatible_with = [ - "@platforms//cpu:x86_64", - "@platforms//os:windows", - "@bazel_tools//tools/cpp:mingw", - ], - target_compatible_with = [ - "@platforms//cpu:x86_32", - "@platforms//os:windows", - ], - toolchain = ":cc-compiler-x64_x86_windows_mingw", - toolchain_type = "@bazel_tools//tools/cpp:toolchain_type", -) - -cc_toolchain( - name = "cc-compiler-x64_windows", - toolchain_identifier = "msvc_x64", - toolchain_config = ":msvc_x64", - all_files = ":empty", - ar_files = ":empty", - as_files = ":msvc_compiler_files", - compiler_files = ":msvc_compiler_files", - dwp_files = ":empty", - linker_files = ":empty", - objcopy_files = ":empty", - strip_files = ":empty", - supports_param_files = 1, -) - -cc_toolchain_config( - name = "msvc_x64", - cpu = "x64_windows", - compiler = "msvc-cl", - host_system_name = "local", - target_system_name = "local", - target_libc = "msvcrt", - abi_version = "local", - abi_libc_version = "local", - toolchain_identifier = "msvc_x64", - msvc_env_tmp = "%{msvc_env_tmp_x64}", - msvc_env_path = "%{msvc_env_path_x64}", - msvc_env_include = "%{msvc_env_include_x64}", - msvc_env_lib = "%{msvc_env_lib_x64}", - msvc_cl_path = "%{msvc_cl_path_x64}", - msvc_ml_path = "%{msvc_ml_path_x64}", - msvc_link_path = "%{msvc_link_path_x64}", - msvc_lib_path = "%{msvc_lib_path_x64}", - cxx_builtin_include_directories = [%{msvc_cxx_builtin_include_directories_x64}], - tool_paths = { - "ar": "%{msvc_lib_path_x64}", - "ml": "%{msvc_ml_path_x64}", - "cpp": "%{msvc_cl_path_x64}", - "gcc": "%{msvc_cl_path_x64}", - "gcov": "wrapper/bin/msvc_nop.bat", - "ld": "%{msvc_link_path_x64}", - "nm": "wrapper/bin/msvc_nop.bat", - "objcopy": "wrapper/bin/msvc_nop.bat", - "objdump": "wrapper/bin/msvc_nop.bat", - "strip": "wrapper/bin/msvc_nop.bat", - "dumpbin": "%{msvc_dumpbin_path_x64}", - "cpp-module-deps-scanner": "%{msvc_deps_scanner_wrapper_path_x64}", - }, - archiver_flags = ["/MACHINE:X64"], - default_link_flags = ["/MACHINE:X64"], - dbg_mode_debug_flag = "%{dbg_mode_debug_flag_x64}", - fastbuild_mode_debug_flag = "%{fastbuild_mode_debug_flag_x64}", - supports_parse_showincludes = %{msvc_parse_showincludes_x64}, -) - -toolchain( - name = "cc-toolchain-x64_windows", - exec_compatible_with = [ - "@platforms//cpu:x86_64", - "@platforms//os:windows", - ], - target_compatible_with = [ - "@platforms//cpu:x86_64", - "@platforms//os:windows", - ], - toolchain = ":cc-compiler-x64_windows", - toolchain_type = "@bazel_tools//tools/cpp:toolchain_type", -) - -cc_toolchain( - name = "cc-compiler-x64_x86_windows", - toolchain_identifier = "msvc_x64_x86", - toolchain_config = ":msvc_x64_x86", - all_files = ":empty", - ar_files = ":empty", - as_files = ":msvc_compiler_files", - compiler_files = ":msvc_compiler_files", - dwp_files = ":empty", - linker_files = ":empty", - objcopy_files = ":empty", - strip_files = ":empty", - supports_param_files = 1, -) - -cc_toolchain_config( - name = "msvc_x64_x86", - cpu = "x64_windows", - compiler = "msvc-cl", - host_system_name = "local", - target_system_name = "local", - target_libc = "msvcrt", - abi_version = "local", - abi_libc_version = "local", - toolchain_identifier = "msvc_x64_x86", - msvc_env_tmp = "%{msvc_env_tmp_x86}", - msvc_env_path = "%{msvc_env_path_x86}", - msvc_env_include = "%{msvc_env_include_x86}", - msvc_env_lib = "%{msvc_env_lib_x86}", - msvc_cl_path = "%{msvc_cl_path_x86}", - msvc_ml_path = "%{msvc_ml_path_x86}", - msvc_link_path = "%{msvc_link_path_x86}", - msvc_lib_path = "%{msvc_lib_path_x86}", - cxx_builtin_include_directories = [%{msvc_cxx_builtin_include_directories_x86}], - tool_paths = { - "ar": "%{msvc_lib_path_x86}", - "ml": "%{msvc_ml_path_x86}", - "cpp": "%{msvc_cl_path_x86}", - "gcc": "%{msvc_cl_path_x86}", - "gcov": "wrapper/bin/msvc_nop.bat", - "ld": "%{msvc_link_path_x86}", - "nm": "wrapper/bin/msvc_nop.bat", - "objcopy": "wrapper/bin/msvc_nop.bat", - "objdump": "wrapper/bin/msvc_nop.bat", - "strip": "wrapper/bin/msvc_nop.bat", - "dumpbin": "%{msvc_dumpbin_path_x86}", - "cpp-module-deps-scanner": "%{msvc_deps_scanner_wrapper_path_x86}", - }, - archiver_flags = ["/MACHINE:X86"], - default_link_flags = ["/MACHINE:X86"], - dbg_mode_debug_flag = "%{dbg_mode_debug_flag_x86}", - fastbuild_mode_debug_flag = "%{fastbuild_mode_debug_flag_x86}", - supports_parse_showincludes = %{msvc_parse_showincludes_x86}, -) - -toolchain( - name = "cc-toolchain-x64_x86_windows", - exec_compatible_with = [ - "@platforms//cpu:x86_64", - "@platforms//os:windows", - ], - target_compatible_with = [ - "@platforms//cpu:x86_32", - "@platforms//os:windows", - ], - toolchain = ":cc-compiler-x64_x86_windows", - toolchain_type = "@bazel_tools//tools/cpp:toolchain_type", -) - -cc_toolchain( - name = "cc-compiler-x64_arm_windows", - toolchain_identifier = "msvc_x64_arm", - toolchain_config = ":msvc_x64_arm", - all_files = ":empty", - ar_files = ":empty", - as_files = ":msvc_compiler_files", - compiler_files = ":msvc_compiler_files", - dwp_files = ":empty", - linker_files = ":empty", - objcopy_files = ":empty", - strip_files = ":empty", - supports_param_files = 1, -) - -cc_toolchain_config( - name = "msvc_x64_arm", - cpu = "x64_windows", - compiler = "msvc-cl", - host_system_name = "local", - target_system_name = "local", - target_libc = "msvcrt", - abi_version = "local", - abi_libc_version = "local", - toolchain_identifier = "msvc_x64_arm", - msvc_env_tmp = "%{msvc_env_tmp_arm}", - msvc_env_path = "%{msvc_env_path_arm}", - msvc_env_include = "%{msvc_env_include_arm}", - msvc_env_lib = "%{msvc_env_lib_arm}", - msvc_cl_path = "%{msvc_cl_path_arm}", - msvc_ml_path = "%{msvc_ml_path_arm}", - msvc_link_path = "%{msvc_link_path_arm}", - msvc_lib_path = "%{msvc_lib_path_arm}", - cxx_builtin_include_directories = [%{msvc_cxx_builtin_include_directories_arm}], - tool_paths = { - "ar": "%{msvc_lib_path_arm}", - "ml": "%{msvc_ml_path_arm}", - "cpp": "%{msvc_cl_path_arm}", - "gcc": "%{msvc_cl_path_arm}", - "gcov": "wrapper/bin/msvc_nop.bat", - "ld": "%{msvc_link_path_arm}", - "nm": "wrapper/bin/msvc_nop.bat", - "objcopy": "wrapper/bin/msvc_nop.bat", - "objdump": "wrapper/bin/msvc_nop.bat", - "strip": "wrapper/bin/msvc_nop.bat", - "dumpbin": "%{msvc_dumpbin_path_arm}", - "cpp-module-deps-scanner": "%{msvc_deps_scanner_wrapper_path_arm}", - }, - archiver_flags = ["/MACHINE:ARM"], - default_link_flags = ["/MACHINE:ARM"], - dbg_mode_debug_flag = "%{dbg_mode_debug_flag_arm}", - fastbuild_mode_debug_flag = "%{fastbuild_mode_debug_flag_arm}", - supports_parse_showincludes = %{msvc_parse_showincludes_arm}, -) - -toolchain( - name = "cc-toolchain-x64_arm_windows", - exec_compatible_with = [ - "@platforms//cpu:x86_64", - "@platforms//os:windows", - ], - target_compatible_with = [ - "@platforms//cpu:arm", - "@platforms//os:windows", - ], - toolchain = ":cc-compiler-x64_arm_windows", - toolchain_type = "@bazel_tools//tools/cpp:toolchain_type", -) - -cc_toolchain( - name = "cc-compiler-arm64_windows", - toolchain_identifier = "msvc_arm64", - toolchain_config = ":msvc_arm64", - all_files = ":empty", - ar_files = ":empty", - as_files = ":msvc_compiler_files", - compiler_files = ":msvc_compiler_files", - dwp_files = ":empty", - linker_files = ":empty", - objcopy_files = ":empty", - strip_files = ":empty", - supports_param_files = 1, -) - -cc_toolchain_config( - name = "msvc_arm64", - cpu = "x64_windows", - compiler = "msvc-cl", - host_system_name = "local", - target_system_name = "local", - target_libc = "msvcrt", - abi_version = "local", - abi_libc_version = "local", - toolchain_identifier = "msvc_arm64", - msvc_env_tmp = "%{msvc_env_tmp_arm64}", - msvc_env_path = "%{msvc_env_path_arm64}", - msvc_env_include = "%{msvc_env_include_arm64}", - msvc_env_lib = "%{msvc_env_lib_arm64}", - msvc_cl_path = "%{msvc_cl_path_arm64}", - msvc_ml_path = "%{msvc_ml_path_arm64}", - msvc_link_path = "%{msvc_link_path_arm64}", - msvc_lib_path = "%{msvc_lib_path_arm64}", - cxx_builtin_include_directories = [%{msvc_cxx_builtin_include_directories_arm64}], - tool_paths = { - "ar": "%{msvc_lib_path_arm64}", - "ml": "%{msvc_ml_path_arm64}", - "cpp": "%{msvc_cl_path_arm64}", - "gcc": "%{msvc_cl_path_arm64}", - "gcov": "wrapper/bin/msvc_nop.bat", - "ld": "%{msvc_link_path_arm64}", - "nm": "wrapper/bin/msvc_nop.bat", - "objcopy": "wrapper/bin/msvc_nop.bat", - "objdump": "wrapper/bin/msvc_nop.bat", - "strip": "wrapper/bin/msvc_nop.bat", - "dumpbin": "%{msvc_dumpbin_path_arm64}", - "cpp-module-deps-scanner": "%{msvc_deps_scanner_wrapper_path_arm64}", - }, - archiver_flags = ["/MACHINE:ARM64"], - default_link_flags = ["/MACHINE:ARM64"], - dbg_mode_debug_flag = "%{dbg_mode_debug_flag_arm64}", - fastbuild_mode_debug_flag = "%{fastbuild_mode_debug_flag_arm64}", - supports_parse_showincludes = %{msvc_parse_showincludes_arm64}, -) - -toolchain( - name = "cc-toolchain-arm64_windows", - exec_compatible_with = [ - "@platforms//os:windows", - ], - target_compatible_with = [ - "@platforms//cpu:arm64", - "@platforms//os:windows", - ], - toolchain = ":cc-compiler-arm64_windows", - toolchain_type = "@bazel_tools//tools/cpp:toolchain_type", -) - - -cc_toolchain( - name = "cc-compiler-x64_windows-clang-cl", - toolchain_identifier = "clang_cl_x64", - toolchain_config = ":clang_cl_x64", - all_files = ":empty", - ar_files = ":empty", - as_files = ":clangcl_compiler_files", - compiler_files = ":clangcl_compiler_files", - dwp_files = ":empty", - linker_files = ":empty", - objcopy_files = ":empty", - strip_files = ":empty", - supports_param_files = 1, -) - -cc_toolchain_config( - name = "clang_cl_x64", - cpu = "x64_windows", - compiler = "clang-cl", - host_system_name = "local", - target_system_name = "local", - target_libc = "msvcrt", - abi_version = "local", - abi_libc_version = "local", - toolchain_identifier = "clang_cl_x64", - msvc_env_tmp = "%{clang_cl_env_tmp_x64}", - msvc_env_path = "%{clang_cl_env_path_x64}", - msvc_env_include = "%{clang_cl_env_include_x64}", - msvc_env_lib = "%{clang_cl_env_lib_x64}", - msvc_cl_path = "%{clang_cl_cl_path_x64}", - msvc_ml_path = "%{clang_cl_ml_path_x64}", - msvc_link_path = "%{clang_cl_link_path_x64}", - msvc_lib_path = "%{clang_cl_lib_path_x64}", - cxx_builtin_include_directories = [%{clang_cl_cxx_builtin_include_directories_x64}], - tool_paths = { - "ar": "%{clang_cl_lib_path_x64}", - "ml": "%{clang_cl_ml_path_x64}", - "cpp": "%{clang_cl_cl_path_x64}", - "gcc": "%{clang_cl_cl_path_x64}", - "gcov": "wrapper/bin/msvc_nop.bat", - "ld": "%{clang_cl_link_path_x64}", - "nm": "wrapper/bin/msvc_nop.bat", - "objcopy": "wrapper/bin/msvc_nop.bat", - "objdump": "wrapper/bin/msvc_nop.bat", - "strip": "wrapper/bin/msvc_nop.bat", - }, - archiver_flags = ["/MACHINE:X64"], - default_link_flags = ["/MACHINE:X64"], - dbg_mode_debug_flag = "%{clang_cl_dbg_mode_debug_flag_x64}", - fastbuild_mode_debug_flag = "%{clang_cl_fastbuild_mode_debug_flag_x64}", - supports_parse_showincludes = %{clang_cl_parse_showincludes_x64}, -) - -toolchain( - name = "cc-toolchain-x64_windows-clang-cl", - exec_compatible_with = [ - "@platforms//cpu:x86_64", - "@platforms//os:windows", - "@bazel_tools//tools/cpp:clang-cl", - ], - target_compatible_with = [ - "@platforms//cpu:x86_64", - "@platforms//os:windows", - ], - toolchain = ":cc-compiler-x64_windows-clang-cl", - toolchain_type = "@bazel_tools//tools/cpp:toolchain_type", -) - -cc_toolchain( - name = "cc-compiler-arm64_windows-clang-cl", - toolchain_identifier = "clang_cl_arm64", - toolchain_config = ":clang_cl_arm64", - all_files = ":empty", - ar_files = ":empty", - as_files = ":clangcl_compiler_files", - compiler_files = ":clangcl_compiler_files", - dwp_files = ":empty", - linker_files = ":empty", - objcopy_files = ":empty", - strip_files = ":empty", - supports_param_files = 1, -) - -cc_toolchain_config( - name = "clang_cl_arm64", - cpu = "arm64_windows", - compiler = "clang-cl", - host_system_name = "local", - target_system_name = "aarch64-pc-windows-msvc", - target_libc = "msvcrt", - abi_version = "local", - abi_libc_version = "local", - toolchain_identifier = "clang_cl_arm64", - msvc_env_tmp = "%{clang_cl_env_tmp_arm64}", - msvc_env_path = "%{clang_cl_env_path_arm64}", - msvc_env_include = "%{clang_cl_env_include_arm64}", - msvc_env_lib = "%{clang_cl_env_lib_arm64}", - msvc_cl_path = "%{clang_cl_cl_path_arm64}", - msvc_ml_path = "%{clang_cl_ml_path_arm64}", - msvc_link_path = "%{clang_cl_link_path_arm64}", - msvc_lib_path = "%{clang_cl_lib_path_arm64}", - cxx_builtin_include_directories = [%{clang_cl_cxx_builtin_include_directories_arm64}], - tool_paths = { - "ar": "%{clang_cl_lib_path_arm64}", - "ml": "%{clang_cl_ml_path_arm64}", - "cpp": "%{clang_cl_cl_path_arm64}", - "gcc": "%{clang_cl_cl_path_arm64}", - "gcov": "wrapper/bin/msvc_nop.bat", - "ld": "%{clang_cl_link_path_arm64}", - "nm": "wrapper/bin/msvc_nop.bat", - "objcopy": "wrapper/bin/msvc_nop.bat", - "objdump": "wrapper/bin/msvc_nop.bat", - "strip": "wrapper/bin/msvc_nop.bat", - }, - archiver_flags = ["/MACHINE:ARM64"], - default_link_flags = ["/MACHINE:ARM64"], - dbg_mode_debug_flag = "%{clang_cl_dbg_mode_debug_flag_arm64}", - fastbuild_mode_debug_flag = "%{clang_cl_fastbuild_mode_debug_flag_arm64}", - supports_parse_showincludes = %{clang_cl_parse_showincludes_arm64}, -) - -toolchain( - name = "cc-toolchain-arm64_windows-clang-cl", - exec_compatible_with = [ - "@platforms//os:windows", - "@bazel_tools//tools/cpp:clang-cl", - ], - target_compatible_with = [ - "@platforms//cpu:arm64", - "@platforms//os:windows", - ], - toolchain = ":cc-compiler-arm64_windows-clang-cl", - toolchain_type = "@bazel_tools//tools/cpp:toolchain_type", -) - -cc_toolchain( - name = "cc-compiler-armeabi-v7a", - toolchain_identifier = "stub_armeabi-v7a", - toolchain_config = ":stub_armeabi-v7a", - all_files = ":empty", - ar_files = ":empty", - as_files = ":empty", - compiler_files = ":empty", - dwp_files = ":empty", - linker_files = ":empty", - objcopy_files = ":empty", - strip_files = ":empty", - supports_param_files = 1, -) - -armeabi_cc_toolchain_config(name = "stub_armeabi-v7a") - -toolchain( - name = "cc-toolchain-armeabi-v7a", - exec_compatible_with = [ - ], - target_compatible_with = [ - "@platforms//cpu:armv7", - "@platforms//os:android", - ], - toolchain = ":cc-compiler-armeabi-v7a", - toolchain_type = "@bazel_tools//tools/cpp:toolchain_type", -) diff --git a/tools/cpp/armeabi_cc_toolchain_config.bzl b/tools/cpp/armeabi_cc_toolchain_config.bzl deleted file mode 100644 index 72ef48ae6d6dfc..00000000000000 --- a/tools/cpp/armeabi_cc_toolchain_config.bzl +++ /dev/null @@ -1,82 +0,0 @@ -# Copyright 2019 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. - -"""A Starlark cc_toolchain configuration rule""" - -load( - "@bazel_tools//tools/cpp:cc_toolchain_config_lib.bzl", - "feature", - "tool_path", -) - -def _impl(ctx): - toolchain_identifier = "stub_armeabi-v7a" - host_system_name = "armeabi-v7a" - target_system_name = "armeabi-v7a" - target_cpu = "armeabi-v7a" - target_libc = "armeabi-v7a" - compiler = "compiler" - abi_version = "armeabi-v7a" - abi_libc_version = "armeabi-v7a" - cc_target_os = None - builtin_sysroot = None - action_configs = [] - - supports_pic_feature = feature(name = "supports_pic", enabled = True) - supports_dynamic_linker_feature = feature(name = "supports_dynamic_linker", enabled = True) - features = [supports_dynamic_linker_feature, supports_pic_feature] - - cxx_builtin_include_directories = [] - artifact_name_patterns = [] - make_variables = [] - - tool_paths = [ - tool_path(name = "ar", path = "/bin/false"), - tool_path(name = "cpp", path = "/bin/false"), - tool_path(name = "dwp", path = "/bin/false"), - tool_path(name = "gcc", path = "/bin/false"), - tool_path(name = "gcov", path = "/bin/false"), - tool_path(name = "ld", path = "/bin/false"), - tool_path(name = "llvm-profdata", path = "/bin/false"), - tool_path(name = "nm", path = "/bin/false"), - tool_path(name = "objcopy", path = "/bin/false"), - tool_path(name = "objdump", path = "/bin/false"), - tool_path(name = "strip", path = "/bin/false"), - ] - - return cc_common.create_cc_toolchain_config_info( - ctx = ctx, - features = features, - action_configs = action_configs, - artifact_name_patterns = artifact_name_patterns, - cxx_builtin_include_directories = cxx_builtin_include_directories, - toolchain_identifier = toolchain_identifier, - host_system_name = host_system_name, - target_system_name = target_system_name, - target_cpu = target_cpu, - target_libc = target_libc, - compiler = compiler, - abi_version = abi_version, - abi_libc_version = abi_libc_version, - tool_paths = tool_paths, - make_variables = make_variables, - builtin_sysroot = builtin_sysroot, - cc_target_os = cc_target_os, - ) - -armeabi_cc_toolchain_config = rule( - implementation = _impl, - attrs = {}, - provides = [CcToolchainConfigInfo], -) diff --git a/tools/cpp/bsd_cc_toolchain_config.bzl b/tools/cpp/bsd_cc_toolchain_config.bzl deleted file mode 100644 index 8c7682669255f2..00000000000000 --- a/tools/cpp/bsd_cc_toolchain_config.bzl +++ /dev/null @@ -1,306 +0,0 @@ -# Copyright 2019 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. - -"""A Starlark cc_toolchain configuration rule for FreeBSD and OpenBSD.""" - -load("@bazel_tools//tools/build_defs/cc:action_names.bzl", "ACTION_NAMES") -load( - "@bazel_tools//tools/cpp:cc_toolchain_config_lib.bzl", - "action_config", - "feature", - "flag_group", - "flag_set", - "tool", - "tool_path", - "with_feature_set", -) - -all_compile_actions = [ - ACTION_NAMES.c_compile, - ACTION_NAMES.cpp_compile, - ACTION_NAMES.linkstamp_compile, - ACTION_NAMES.assemble, - ACTION_NAMES.preprocess_assemble, - ACTION_NAMES.cpp_header_parsing, - ACTION_NAMES.cpp_module_compile, - ACTION_NAMES.cpp_module_codegen, - ACTION_NAMES.clif_match, - ACTION_NAMES.lto_backend, -] - -all_cpp_compile_actions = [ - ACTION_NAMES.cpp_compile, - ACTION_NAMES.linkstamp_compile, - ACTION_NAMES.cpp_header_parsing, - ACTION_NAMES.cpp_module_compile, - ACTION_NAMES.cpp_module_codegen, - ACTION_NAMES.clif_match, -] - -all_link_actions = [ - ACTION_NAMES.cpp_link_executable, - ACTION_NAMES.cpp_link_dynamic_library, - ACTION_NAMES.cpp_link_nodeps_dynamic_library, -] - -def _impl(ctx): - cpu = ctx.attr.cpu - is_bsd = cpu == "freebsd" or cpu == "openbsd" - compiler = "compiler" - toolchain_identifier = "local_{}".format(cpu) if is_bsd else "stub_armeabi-v7a" - host_system_name = "local" if is_bsd else "armeabi-v7a" - target_system_name = "local" if is_bsd else "armeabi-v7a" - target_libc = "local" if is_bsd else "armeabi-v7a" - abi_version = "local" if is_bsd else "armeabi-v7a" - abi_libc_version = "local" if is_bsd else "armeabi-v7a" - - objcopy_embed_data_action = action_config( - action_name = "objcopy_embed_data", - enabled = True, - tools = [tool(path = "/usr/bin/objcopy")], - ) - - action_configs = [objcopy_embed_data_action] if is_bsd else [] - - default_link_flags_feature = feature( - name = "default_link_flags", - enabled = True, - flag_sets = [ - flag_set( - actions = all_link_actions, - flag_groups = [ - flag_group( - flags = [ - "-lstdc++", - "-Wl,-z,relro,-z,now", - "-no-canonical-prefixes", - ], - ), - ], - ), - flag_set( - actions = all_link_actions, - flag_groups = [flag_group(flags = ["-Wl,--gc-sections"])], - with_features = [with_feature_set(features = ["opt"])], - ), - ], - ) - - unfiltered_compile_flags_feature = feature( - name = "unfiltered_compile_flags", - enabled = True, - flag_sets = [ - flag_set( - actions = all_compile_actions, - flag_groups = [ - flag_group( - flags = [ - "-no-canonical-prefixes", - "-Wno-builtin-macro-redefined", - "-D__DATE__=\"redacted\"", - "-D__TIMESTAMP__=\"redacted\"", - "-D__TIME__=\"redacted\"", - ], - ), - ], - ), - ], - ) - - supports_pic_feature = feature(name = "supports_pic", enabled = True) - - default_compile_flags_feature = feature( - name = "default_compile_flags", - enabled = True, - flag_sets = [ - flag_set( - actions = all_compile_actions, - flag_groups = [ - flag_group( - flags = [ - "-U_FORTIFY_SOURCE", - "-D_FORTIFY_SOURCE=1", - "-fstack-protector", - "-Wall", - "-fno-omit-frame-pointer", - ], - ), - ], - ), - flag_set( - actions = all_compile_actions, - flag_groups = [flag_group(flags = ["-g"])], - with_features = [with_feature_set(features = ["dbg"])], - ), - flag_set( - actions = all_compile_actions, - flag_groups = [ - flag_group( - flags = [ - "-g0", - "-O2", - "-DNDEBUG", - "-ffunction-sections", - "-fdata-sections", - ], - ), - ], - with_features = [with_feature_set(features = ["opt"])], - ), - flag_set( - actions = all_cpp_compile_actions + [ACTION_NAMES.lto_backend], - flag_groups = [flag_group(flags = ["-std=c++17"])], - ), - ], - ) - - opt_feature = feature(name = "opt") - - supports_dynamic_linker_feature = feature(name = "supports_dynamic_linker", enabled = True) - - objcopy_embed_flags_feature = feature( - name = "objcopy_embed_flags", - enabled = True, - flag_sets = [ - flag_set( - actions = ["objcopy_embed_data"], - flag_groups = [flag_group(flags = ["-I", "binary"])], - ), - ], - ) - - dbg_feature = feature(name = "dbg") - - user_compile_flags_feature = feature( - name = "user_compile_flags", - enabled = True, - flag_sets = [ - flag_set( - actions = all_compile_actions, - flag_groups = [ - flag_group( - flags = ["%{user_compile_flags}"], - iterate_over = "user_compile_flags", - expand_if_available = "user_compile_flags", - ), - ], - ), - ], - ) - - sysroot_feature = feature( - name = "sysroot", - enabled = True, - flag_sets = [ - flag_set( - actions = [ - ACTION_NAMES.c_compile, - ACTION_NAMES.cpp_compile, - ACTION_NAMES.linkstamp_compile, - ACTION_NAMES.preprocess_assemble, - ACTION_NAMES.cpp_header_parsing, - ACTION_NAMES.cpp_module_compile, - ACTION_NAMES.cpp_module_codegen, - ACTION_NAMES.clif_match, - ACTION_NAMES.lto_backend, - ] + all_link_actions, - flag_groups = [ - flag_group( - flags = ["--sysroot=%{sysroot}"], - expand_if_available = "sysroot", - ), - ], - ), - ], - ) - - if is_bsd: - features = [ - default_compile_flags_feature, - default_link_flags_feature, - supports_dynamic_linker_feature, - supports_pic_feature, - objcopy_embed_flags_feature, - opt_feature, - dbg_feature, - user_compile_flags_feature, - sysroot_feature, - unfiltered_compile_flags_feature, - ] - else: - features = [supports_dynamic_linker_feature, supports_pic_feature] - - if (is_bsd): - cxx_builtin_include_directories = ["/usr/lib/clang", "/usr/local/include", "/usr/include"] - else: - cxx_builtin_include_directories = [] - - if is_bsd: - tool_paths = [ - tool_path(name = "ar", path = "/usr/bin/ar"), - tool_path(name = "cpp", path = "/usr/bin/cpp"), - tool_path(name = "dwp", path = "/usr/bin/dwp"), - tool_path(name = "gcc", path = "/usr/bin/clang"), - tool_path(name = "gcov", path = "/usr/bin/gcov"), - tool_path(name = "ld", path = "/usr/bin/ld"), - tool_path(name = "nm", path = "/usr/bin/nm"), - tool_path(name = "objcopy", path = "/usr/bin/objcopy"), - tool_path(name = "objdump", path = "/usr/bin/objdump"), - tool_path(name = "strip", path = "/usr/bin/strip"), - ] - else: - tool_paths = [ - tool_path(name = "ar", path = "/bin/false"), - tool_path(name = "cpp", path = "/bin/false"), - tool_path(name = "dwp", path = "/bin/false"), - tool_path(name = "gcc", path = "/bin/false"), - tool_path(name = "gcov", path = "/bin/false"), - tool_path(name = "ld", path = "/bin/false"), - tool_path(name = "nm", path = "/bin/false"), - tool_path(name = "objcopy", path = "/bin/false"), - tool_path(name = "objdump", path = "/bin/false"), - tool_path(name = "strip", path = "/bin/false"), - ] - - out = ctx.actions.declare_file(ctx.label.name) - ctx.actions.write(out, "Fake executable") - return [ - cc_common.create_cc_toolchain_config_info( - ctx = ctx, - features = features, - action_configs = action_configs, - cxx_builtin_include_directories = cxx_builtin_include_directories, - toolchain_identifier = toolchain_identifier, - host_system_name = host_system_name, - target_system_name = target_system_name, - target_cpu = cpu, - target_libc = target_libc, - compiler = compiler, - abi_version = abi_version, - abi_libc_version = abi_libc_version, - tool_paths = tool_paths, - ), - DefaultInfo( - executable = out, - ), - ] - -cc_toolchain_config = rule( - implementation = _impl, - attrs = { - "cpu": attr.string(mandatory = True), - }, - provides = [CcToolchainConfigInfo], - executable = True, -) diff --git a/tools/cpp/build_interface_so b/tools/cpp/build_interface_so deleted file mode 100644 index 626e707c6ceb2d..00000000000000 --- a/tools/cpp/build_interface_so +++ /dev/null @@ -1,8 +0,0 @@ -#!/bin/bash - -if [[ $# != 2 ]]; then - echo "Usage: $0 " 1>&2 - exit 1 -fi - -exec cp $1 $2 diff --git a/tools/cpp/cc_configure.bzl b/tools/cpp/cc_configure.bzl index 1e724c0b156e4b..82fb6b5778b500 100644 --- a/tools/cpp/cc_configure.bzl +++ b/tools/cpp/cc_configure.bzl @@ -1,161 +1,19 @@ -# Copyright 2016 The Bazel Authors. All rights reserved. +# Copyright 2024 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 +# 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. -"""Rules for configuring the C++ toolchain (experimental).""" -load( - "@bazel_tools//tools/cpp:lib_cc_configure.bzl", - "get_cpu_value", - "resolve_labels", -) -load("@bazel_tools//tools/cpp:unix_cc_configure.bzl", "configure_unix_toolchain") -load("@bazel_tools//tools/cpp:windows_cc_configure.bzl", "configure_windows_toolchain") +load("@rules_cc//cc/toolchains:toolchain_config_utils.bzl", _MSVC_ENVVARS="MSVC_ENVVARS") +load("@rules_cc//cc/private/toolchain:cc_configure.bzl", _cc_configure="cc_configure") -def cc_autoconf_toolchains_impl(repository_ctx): - """Generate BUILD file with 'toolchain' targets for the local host C++ toolchain. - - Args: - repository_ctx: repository context - """ - env = repository_ctx.os.environ - - # Should we try to find C++ toolchain at all? If not, we don't have to generate toolchains for C++ at all. - should_detect_cpp_toolchain = "BAZEL_DO_NOT_DETECT_CPP_TOOLCHAIN" not in env or env["BAZEL_DO_NOT_DETECT_CPP_TOOLCHAIN"] != "1" - - if should_detect_cpp_toolchain: - paths = resolve_labels(repository_ctx, [ - "@bazel_tools//tools/cpp:BUILD.toolchains.tpl", - ]) - repository_ctx.template( - "BUILD", - paths["@bazel_tools//tools/cpp:BUILD.toolchains.tpl"], - {"%{name}": get_cpu_value(repository_ctx)}, - ) - else: - repository_ctx.file("BUILD", "# C++ toolchain autoconfiguration was disabled by BAZEL_DO_NOT_DETECT_CPP_TOOLCHAIN env variable.") - -cc_autoconf_toolchains = repository_rule( - environ = [ - "BAZEL_DO_NOT_DETECT_CPP_TOOLCHAIN", - ], - implementation = cc_autoconf_toolchains_impl, - configure = True, -) - -def cc_autoconf_impl(repository_ctx, overriden_tools = dict()): - """Generate BUILD file with 'cc_toolchain' targets for the local host C++ toolchain. - - Args: - repository_ctx: repository context - overriden_tools: dict of tool paths to use instead of autoconfigured tools - """ - - env = repository_ctx.os.environ - cpu_value = get_cpu_value(repository_ctx) - if "BAZEL_DO_NOT_DETECT_CPP_TOOLCHAIN" in env and env["BAZEL_DO_NOT_DETECT_CPP_TOOLCHAIN"] == "1": - paths = resolve_labels(repository_ctx, [ - "@bazel_tools//tools/cpp:BUILD.empty.tpl", - "@bazel_tools//tools/cpp:empty_cc_toolchain_config.bzl", - ]) - repository_ctx.symlink(paths["@bazel_tools//tools/cpp:empty_cc_toolchain_config.bzl"], "cc_toolchain_config.bzl") - repository_ctx.template("BUILD", paths["@bazel_tools//tools/cpp:BUILD.empty.tpl"], { - "%{cpu}": get_cpu_value(repository_ctx), - }) - elif cpu_value == "freebsd" or cpu_value == "openbsd": - paths = resolve_labels(repository_ctx, [ - "@bazel_tools//tools/cpp:BUILD.static.bsd", - "@bazel_tools//tools/cpp:bsd_cc_toolchain_config.bzl", - ]) - - # This is defaulting to a static crosstool. We should eventually - # autoconfigure this platform too. Theoretically, FreeBSD and OpenBSD - # should be straightforward to add but we cannot run them in a Docker - # container so skipping until we have proper tests for these platforms. - repository_ctx.symlink(paths["@bazel_tools//tools/cpp:bsd_cc_toolchain_config.bzl"], "cc_toolchain_config.bzl") - repository_ctx.symlink(paths["@bazel_tools//tools/cpp:BUILD.static.bsd"], "BUILD") - elif cpu_value in ["x64_windows", "arm64_windows"]: - # TODO(ibiryukov): overriden_tools are only supported in configure_unix_toolchain. - # We might want to add that to Windows too(at least for msys toolchain). - configure_windows_toolchain(repository_ctx) - else: - configure_unix_toolchain(repository_ctx, cpu_value, overriden_tools) - -MSVC_ENVVARS = [ - "BAZEL_VC", - "BAZEL_VC_FULL_VERSION", - "BAZEL_VS", - "BAZEL_WINSDK_FULL_VERSION", - "VS90COMNTOOLS", - "VS100COMNTOOLS", - "VS110COMNTOOLS", - "VS120COMNTOOLS", - "VS140COMNTOOLS", - "VS150COMNTOOLS", - "VS160COMNTOOLS", - "TMP", - "TEMP", -] - -cc_autoconf = repository_rule( - environ = [ - "ABI_LIBC_VERSION", - "ABI_VERSION", - "BAZEL_COMPILER", - "BAZEL_HOST_SYSTEM", - "BAZEL_CONLYOPTS", - "BAZEL_CXXOPTS", - "BAZEL_LINKOPTS", - "BAZEL_LINKLIBS", - "BAZEL_LLVM_COV", - "BAZEL_LLVM_PROFDATA", - "BAZEL_PYTHON", - "BAZEL_SH", - "BAZEL_TARGET_CPU", - "BAZEL_TARGET_LIBC", - "BAZEL_TARGET_SYSTEM", - "BAZEL_DO_NOT_DETECT_CPP_TOOLCHAIN", - "BAZEL_USE_LLVM_NATIVE_COVERAGE", - "BAZEL_LLVM", - "BAZEL_IGNORE_SYSTEM_HEADERS_VERSIONS", - "USE_CLANG_CL", - "CC", - "CC_CONFIGURE_DEBUG", - "CC_TOOLCHAIN_NAME", - "CPLUS_INCLUDE_PATH", - "DEVELOPER_DIR", - "GCOV", - "LIBTOOL", - "HOMEBREW_RUBY_PATH", - "SYSTEMROOT", - "USER", - ] + MSVC_ENVVARS, - implementation = cc_autoconf_impl, - configure = True, -) - -def cc_configure(): - """A C++ configuration rules that generate the crosstool file.""" - cc_autoconf_toolchains(name = "local_config_cc_toolchains") - cc_autoconf(name = "local_config_cc") - native.bind(name = "cc_toolchain", actual = "@local_config_cc//:toolchain") - native.register_toolchains( - # Use register_toolchain's target pattern expansion to register all toolchains in the package. - "@local_config_cc_toolchains//:all", - ) - -def _cc_configure_extension_impl(ctx): - cc_autoconf_toolchains(name = "local_config_cc_toolchains") - cc_autoconf(name = "local_config_cc") - return ctx.extension_metadata(reproducible = True) - -cc_configure_extension = module_extension(implementation = _cc_configure_extension_impl) +MSVC_ENVVARS = _MSVC_ENVVARS +cc_configure = _cc_configure diff --git a/tools/cpp/cc_flags_supplier.bzl b/tools/cpp/cc_flags_supplier.bzl index 11d9db8ab8ada6..3ebc4ff5e8f8a4 100644 --- a/tools/cpp/cc_flags_supplier.bzl +++ b/tools/cpp/cc_flags_supplier.bzl @@ -1,35 +1,17 @@ -# Copyright 2018 The Bazel Authors. All rights reserved. +# Copyright 2024 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 +# 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. -"""Rule that provides the CC_FLAGS Make variable.""" -load("@bazel_tools//tools/build_defs/cc:action_names.bzl", "CC_FLAGS_MAKE_VARIABLE_ACTION_NAME") -load("@bazel_tools//tools/cpp:cc_flags_supplier_lib.bzl", "build_cc_flags") -load("@bazel_tools//tools/cpp:toolchain_utils.bzl", "find_cpp_toolchain", "use_cpp_toolchain") +load("@rules_cc//cc:defs.bzl", _cc_flags_supplier="cc_flags_supplier") -def _cc_flags_supplier_impl(ctx): - cc_toolchain = find_cpp_toolchain(ctx) - cc_flags = build_cc_flags(ctx, cc_toolchain, CC_FLAGS_MAKE_VARIABLE_ACTION_NAME) - variables = platform_common.TemplateVariableInfo({ - "CC_FLAGS": cc_flags, - }) - return [variables] - -cc_flags_supplier = rule( - implementation = _cc_flags_supplier_impl, - attrs = { - "_cc_toolchain": attr.label(default = Label("@bazel_tools//tools/cpp:current_cc_toolchain")), - }, - toolchains = use_cpp_toolchain(), - fragments = ["cpp"], -) +cc_flags_supplier = _cc_flags_supplier diff --git a/tools/cpp/cc_flags_supplier_lib.bzl b/tools/cpp/cc_flags_supplier_lib.bzl deleted file mode 100644 index 042ecef940353d..00000000000000 --- a/tools/cpp/cc_flags_supplier_lib.bzl +++ /dev/null @@ -1,71 +0,0 @@ -# Copyright 2018 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. -"""Library of functions that provide the CC_FLAGS Make variable.""" - -# This should match the logic in CcCommon.computeCcFlags: -def build_cc_flags(ctx, cc_toolchain, action_name): - """Determine the value for CC_FLAGS based on the given toolchain.""" - - # Get default cc flags from toolchain's make_variables. - legacy_cc_flags = cc_common.legacy_cc_flags_make_variable_do_not_use( - cc_toolchain = cc_toolchain, - ) - - # Determine the sysroot flag. - sysroot_cc_flags = _from_sysroot(cc_toolchain) - - # Flags from feature config. - feature_config_cc_flags = _from_features(ctx, cc_toolchain, action_name) - - # Combine the different sources, but only add the sysroot flag if nothing - # else adds sysroot. - # If added, it must appear before the feature config flags. - cc_flags = [] - if legacy_cc_flags: - cc_flags.append(legacy_cc_flags) - if sysroot_cc_flags and not _contains_sysroot(feature_config_cc_flags): - cc_flags.append(sysroot_cc_flags) - cc_flags.extend(feature_config_cc_flags) - - return " ".join(cc_flags) - -def _contains_sysroot(flags): - for flag in flags: - if "--sysroot=" in flag: - return True - return False - -def _from_sysroot(cc_toolchain): - sysroot = cc_toolchain.sysroot - if sysroot: - return "--sysroot=%s" % sysroot - else: - return None - -def _from_features(ctx, cc_toolchain, action_name): - feature_configuration = cc_common.configure_features( - ctx = ctx, - cc_toolchain = cc_toolchain, - requested_features = ctx.features, - unsupported_features = ctx.disabled_features, - ) - - variables = cc_common.empty_variables() - - cc_flags = cc_common.get_memory_inefficient_command_line( - feature_configuration = feature_configuration, - action_name = action_name, - variables = variables, - ) - return cc_flags diff --git a/tools/cpp/cc_toolchain_config_lib.bzl b/tools/cpp/cc_toolchain_config_lib.bzl index c09530671d5719..6bd457bf73888f 100644 --- a/tools/cpp/cc_toolchain_config_lib.bzl +++ b/tools/cpp/cc_toolchain_config_lib.bzl @@ -1,10 +1,10 @@ -# Copyright 2018 The Bazel Authors. All rights reserved. +# Copyright 2024 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 +# 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, @@ -12,558 +12,31 @@ # See the License for the specific language governing permissions and # limitations under the License. -""" A library of functions creating structs for CcToolchainConfigInfo.""" - -def _check_is_none(obj, parameter_name, method_name): - if obj != None: - fail("{} parameter of {} should be None, found {}." - .format(parameter_name, method_name, type(obj))) - -def _check_is_none_or_right_type(obj, obj_of_right_type, parameter_name, method_name): - if obj != None: - _check_same_type(obj, obj_of_right_type, parameter_name, method_name) - -def _check_right_type(obj, expected_type, parameter_name, method_name): - if type(obj) != expected_type: - fail("{} parameter of {} should be a {}, found {}." - .format(parameter_name, method_name, expected_type, type(obj))) - -def _check_same_type(obj, obj_of_right_type, parameter_name, method_name): - _check_right_type(obj, type(obj_of_right_type), parameter_name, method_name) - -def _check_is_nonempty_string(obj, parameter_name, method_name): - _check_same_type(obj, "", parameter_name, method_name) - if obj == "": - fail("{} parameter of {} must be a nonempty string." - .format(parameter_name, method_name)) - -def _check_is_nonempty_list(obj, parameter_name, method_name): - _check_same_type(obj, [], parameter_name, method_name) - if len(obj) == 0: - fail("{} parameter of {} must be a nonempty list." - .format(parameter_name, method_name)) - -EnvEntryInfo = provider(fields = ["key", "value", "type_name"]) - -def env_entry(key, value): - """ A key/value pair to be added as an environment variable. - - The returned EnvEntry provider finds its use in EnvSet creation through - the env_entries parameter of env_set(); EnvSet groups environment variables - that need to be expanded for specific actions. - The value of this pair is expanded in the same way as is described in - flag_group. The key remains an unexpanded string literal. - - Args: - key: a string literal representing the name of the variable. - value: the value to be expanded. - - Returns: - An EnvEntryInfo provider. - """ - _check_is_nonempty_string(key, "key", "env_entry") - _check_is_nonempty_string(value, "value", "env_entry") - return EnvEntryInfo(key = key, value = value, type_name = "env_entry") - -VariableWithValueInfo = provider(fields = ["name", "value", "type_name"]) - -def variable_with_value(name, value): - """ Represents equality check between a variable and a certain value. - - The returned provider finds its use through flag_group.expand_if_equal, - making the expansion of the flag_group conditional on the value of the - variable. - - Args: - name: name of the variable. - value: the value the variable should be compared against. - - Returns: - A VariableWithValueInfo provider. - """ - _check_is_nonempty_string(name, "name", "variable_with_value") - _check_is_nonempty_string(value, "value", "variable_with_value") - return VariableWithValueInfo( - name = name, - value = value, - type_name = "variable_with_value", - ) - -MakeVariableInfo = provider(fields = ["name", "value", "type_name"]) - -def make_variable(name, value): - """ A make variable that is made accessible to rules.""" - _check_is_nonempty_string(name, "name", "make_variable") - _check_is_nonempty_string(value, "value", "make_variable") - return MakeVariableInfo( - name = name, - value = value, - type_name = "make_variable", - ) - -FeatureSetInfo = provider(fields = ["features", "type_name"]) - -def feature_set(features = []): - """ A set of features. - - Used to support logical 'and' when specifying feature requirements in a - feature. - - Args: - features: A list of unordered feature names. - - Returns: - A FeatureSetInfo provider. - """ - _check_same_type(features, [], "features", "feature_set") - return FeatureSetInfo(features = features, type_name = "feature_set") - -WithFeatureSetInfo = provider(fields = ["features", "not_features", "type_name"]) - -def with_feature_set(features = [], not_features = []): - """ A set of positive and negative features. - - This stanza will evaluate to true when every 'feature' is enabled, and - every 'not_feature' is not enabled. - - Args: - features: A list of feature names that need to be enabled. - not_features: A list of feature names that need to not be enabled. - - Returns: - A WithFeatureSetInfo provider. - """ - _check_same_type(features, [], "features", "with_feature_set") - _check_same_type(not_features, [], "not_features", "with_feature_set") - return WithFeatureSetInfo( - features = features, - not_features = not_features, - type_name = "with_feature_set", - ) - -EnvSetInfo = provider(fields = ["actions", "env_entries", "with_features", "type_name"]) - -def env_set(actions, env_entries = [], with_features = []): - """ Groups a set of environment variables to apply for certain actions. - - EnvSet providers are passed to feature() and action_config(), to be applied to - the actions they are specified for. - - Args: - actions: A list of actions this env set applies to; each env set must - specify at least one action. - env_entries: A list of EnvEntry - the environment variables applied - via this env set. - with_features: A list of feature sets defining when this env set gets - applied. The env set will be applied when any one of the feature - sets evaluate to true. (That is, when when every 'feature' is - enabled, and every 'not_feature' is not enabled.) - If 'with_features' is omitted, the env set will be applied - unconditionally for every action specified. - - Returns: - An EnvSetInfo provider. - """ - _check_is_nonempty_list(actions, "actions", "env_set") - _check_same_type(env_entries, [], "env_entries", "env_set") - _check_same_type(with_features, [], "with_features", "env_set") - return EnvSetInfo( - actions = actions, - env_entries = env_entries, - with_features = with_features, - type_name = "env_set", - ) - -FlagGroupInfo = provider(fields = [ - "flags", - "flag_groups", - "iterate_over", - "expand_if_available", - "expand_if_not_available", - "expand_if_true", - "expand_if_false", - "expand_if_equal", - "type_name", -]) - -def flag_group( - flags = [], - flag_groups = [], - iterate_over = None, - expand_if_available = None, - expand_if_not_available = None, - expand_if_true = None, - expand_if_false = None, - expand_if_equal = None): - """ A group of flags. Supports parametrization via variable expansion. - - To expand a variable of list type, flag_group has to be annotated with - `iterate_over` message. Then all nested flags or flag_groups will be - expanded repeatedly for each element of the list. - For example: - flag_group( - iterate_over = 'include_path', - flags = ['-I', '%{include_path}'], - ) - ... will get expanded to -I /to/path1 -I /to/path2 ... for each - include_path /to/pathN. - - To expand a variable of structure type, use dot-notation, e.g.: - flag_group( - iterate_over = "libraries_to_link", - flag_groups = [ - flag_group( - iterate_over = "libraries_to_link.libraries", - flags = ["-L%{libraries_to_link.libraries.directory}"], - ) - ] - ) - - Flag groups can be nested; if they are, the flag group must only contain - other flag groups (no flags) so the order is unambiguously specified. - In order to expand a variable of nested lists, 'iterate_over' can be used. - For example: - flag_group ( - iterate_over = 'object_files', - flag_groups = [ - flag_group ( - flags = ['--start-lib'], - ), - flag_group ( - iterate_over = 'object_files', - flags = ['%{object_files}'], - ), - flag_group ( - flags = ['--end-lib'], - ) - ] - ) - ... will get expanded to - --start-lib a1.o a2.o ... --end-lib --start-lib b1.o b2.o .. --end-lib - with %{object_files} being a variable of nested list type - [['a1.o', 'a2.o', ...], ['b1.o', 'b2.o', ...], ...]. - - Args: - flags: a string list, representing flags. Only one of flags and - flag_groups can be set, as to avoid ambiguity. - flag_groups: a list of FlagGroup entries. Only one of flags and - flag_groups can be set, as to avoid ambiguity. - iterate_over: a string, representing a variable of list type. - expand_if_available: A build variable that needs to be available - in order to expand the flag_group. - expand_if_not_available: A build variable that needs to be - unavailable in order for this flag_group to be expanded. - expand_if_true: if set, this variable needs to evaluate to True in - order for the flag_group to be expanded. - expand_if_false: if set, this variable needs to evalate to False in - order for the flag_group to be expanded. - expand_if_equal: a VariableWithValue, the flag_group is expanded in - case of equality. - - Returns: - A FlagGroupInfo provider. - """ - - _check_same_type(flags, [], "flags", "flag_group") - _check_same_type(flag_groups, [], "flag_groups", "flag_group") - if len(flags) > 0 and len(flag_groups) > 0: - fail("flag_group must not contain both a flag and another flag_group.") - if len(flags) == 0 and len(flag_groups) == 0: - fail("flag_group must contain either a list of flags or a list of flag_groups.") - _check_is_none_or_right_type(expand_if_true, "string", "expand_if_true", "flag_group") - _check_is_none_or_right_type(expand_if_false, "string", "expand_if_false", "flag_group") - _check_is_none_or_right_type(expand_if_available, "string", "expand_if_available", "flag_group") - _check_is_none_or_right_type( - expand_if_not_available, - "string", - "expand_if_not_available", - "flag_group", - ) - _check_is_none_or_right_type(iterate_over, "string", "iterate_over", "flag_group") - - return FlagGroupInfo( - flags = flags, - flag_groups = flag_groups, - iterate_over = iterate_over, - expand_if_available = expand_if_available, - expand_if_not_available = expand_if_not_available, - expand_if_true = expand_if_true, - expand_if_false = expand_if_false, - expand_if_equal = expand_if_equal, - type_name = "flag_group", - ) - -FlagSetInfo = provider(fields = [ - "actions", - "with_features", - "flag_groups", - "type_name", -]) - -def flag_set( - actions = [], - with_features = [], - flag_groups = []): - """ A set of flags to be expanded in the command line for specific actions. - - Args: - actions: The actions this flag set applies to; each flag set must - specify at least one action. - with_features: A list of feature sets defining when this flag set gets - applied. The flag set will be applied when any one of the feature - sets evaluate to true. (That is, when when every 'feature' is - enabled, and every 'not_feature' is not enabled.) - If 'with_feature' is omitted, the flag set will be applied - unconditionally for every action specified. - flag_groups: A FlagGroup list - the flags applied via this flag set. - - Returns: - A FlagSetInfo provider. - """ - _check_same_type(actions, [], "actions", "flag_set") - _check_same_type(with_features, [], "with_features", "flag_set") - _check_same_type(flag_groups, [], "flag_groups", "flag_set") - return FlagSetInfo( - actions = actions, - with_features = with_features, - flag_groups = flag_groups, - type_name = "flag_set", - ) - -FeatureInfo = provider(fields = [ - "name", - "enabled", - "flag_sets", - "env_sets", - "requires", - "implies", - "provides", - "type_name", -]) - -def feature( - name, - enabled = False, - flag_sets = [], - env_sets = [], - requires = [], - implies = [], - provides = []): - """ Contains all flag specifications for one feature. - - Args: - name: The feature's name. It is possible to introduce a feature without - a change to Bazel by adding a 'feature' section to the toolchain - and adding the corresponding string as feature in the BUILD file. - enabled: If 'True', this feature is enabled unless a rule type - explicitly marks it as unsupported. - flag_sets: A FlagSet list - If the given feature is enabled, the flag - sets will be applied for the actions are specified for. - env_sets: an EnvSet list - If the given feature is enabled, the env - sets will be applied for the actions they are specified for. - requires: A list of feature sets defining when this feature is - supported by the toolchain. The feature is supported if any of the - feature sets fully apply, that is, when all features of a feature - set are enabled. - If 'requires' is omitted, the feature is supported independently of - which other features are enabled. - Use this for example to filter flags depending on the build mode - enabled (opt / fastbuild / dbg). - implies: A string list of features or action configs that are - automatically enabled when this feature is enabled. If any of the - implied features or action configs cannot be enabled, this feature - will (silently) not be enabled either. - provides: A list of names this feature conflicts with. - A feature cannot be enabled if: - - 'provides' contains the name of a different feature or action - config that we want to enable. - - 'provides' contains the same value as a 'provides' in a - different feature or action config that we want to enable. - Use this in order to ensure that incompatible features cannot be - accidentally activated at the same time, leading to hard to - diagnose compiler errors. - - Returns: - A FeatureInfo provider. - """ - _check_same_type(enabled, True, "enabled", "feature") - _check_same_type(flag_sets, [], "flag_sets", "feature") - _check_same_type(env_sets, [], "env_sets", "feature") - _check_same_type(requires, [], "requires", "feature") - _check_same_type(provides, [], "provides", "feature") - _check_same_type(implies, [], "implies", "feature") - return FeatureInfo( - name = name, - enabled = enabled, - flag_sets = flag_sets, - env_sets = env_sets, - requires = requires, - implies = implies, - provides = provides, - type_name = "feature", - ) - -ToolPathInfo = provider(fields = ["name", "path", "type_name"]) - -def tool_path(name, path): - """ Tool locations. - - Args: - name: Name of the tool. - path: Location of the tool; Can be absolute path (in case of non hermetic - toolchain), or path relative to the cc_toolchain's package. - - Returns: - A ToolPathInfo provider. - - Deprecated: - Prefer specifying an ActionConfig for the action that needs the tool. - TODO(b/27903698) migrate to ActionConfig. - """ - _check_is_nonempty_string(name, "name", "tool_path") - _check_is_nonempty_string(path, "path", "tool_path") - return ToolPathInfo(name = name, path = path, type_name = "tool_path") - -ToolInfo = provider(fields = [ - "path", - "tool", - "with_features", - "execution_requirements", - "type_name", -]) - -def tool(path = None, with_features = [], execution_requirements = [], tool = None): - """ Describes a tool associated with a crosstool action config. - - Args: - path: Location of the tool; Can be absolute path (in case of non hermetic - toolchain), or path relative to the cc_toolchain's package. If this - parameter is set, tool must not be set. - tool: The built-artifact that should be used as this tool. If this is - set, path must not be set. - with_features: A list of feature sets defining when this tool is - applicable. The tool will used when any one of the feature sets - evaluate to true. (That is, when when every 'feature' is enabled, - and every 'not_feature' is not enabled.) - If 'with_feature' is omitted, the tool will apply for any feature - configuration. - execution_requirements: Requirements on the execution environment for - the execution of this tool, to be passed as out-of-band "hints" to - the execution backend. - Ex. "requires-darwin" - - Returns: - A ToolInfo provider. - """ - if path == None and tool == None: - fail("Parameter path or parameter tool of tool should not be None.") - - if path != None: - _check_is_nonempty_string(path, "path", "tool") - _check_is_none(tool, "tool", "tool") - if tool != None: - _check_is_none(path, "path", "tool") - _check_right_type(tool, "File", "tool", "tool") - - _check_same_type(with_features, [], "with_features", "tool") - _check_same_type(execution_requirements, [], "execution_requirements", "tool") - return ToolInfo( - path = path, - tool = tool, - with_features = with_features, - execution_requirements = execution_requirements, - type_name = "tool", - ) - -ActionConfigInfo = provider(fields = [ - "config_name", - "action_name", - "enabled", - "tools", - "flag_sets", - "implies", - "type_name", -]) - -def action_config( - action_name, - enabled = False, - tools = [], - flag_sets = [], - implies = []): - """ Configuration of a Bazel action. - - An action config corresponds to a Bazel action, and allows selection of - a tool based on activated features. - Action config activation occurs by the same semantics as features: a - feature can 'require' or 'imply' an action config in the same way that it - would another feature. - - Args: - action_name: The name of the Bazel action that this config applies to, - ex. 'c-compile' or 'c-module-compile'. - enabled: If 'True', this action is enabled unless a rule type - explicitly marks it as unsupported. - tools: The tool applied to the action will be the first Tool with a - feature set that matches the feature configuration. An error will - be thrown if no tool matches a provided feature configuration - for - that reason, it's a good idea to provide a default tool with an - empty feature set. - flag_sets: If the given action config is enabled, the flag sets will be - applied to the corresponding action. - implies: A list of features or action configs that are automatically - enabled when this action config is enabled. If any of the implied - features or action configs cannot be enabled, this action config - will (silently) not be enabled either. - - Returns: - An ActionConfigInfo provider. - """ - _check_is_nonempty_string(action_name, "name", "action_config") - _check_same_type(enabled, True, "enabled", "action_config") - _check_same_type(tools, [], "tools", "action_config") - _check_same_type(flag_sets, [], "flag_sets", "action_config") - _check_same_type(implies, [], "implies", "action_config") - return ActionConfigInfo( - action_name = action_name, - enabled = enabled, - tools = tools, - flag_sets = flag_sets, - implies = implies, - type_name = "action_config", - ) - -ArtifactNamePatternInfo = provider(fields = [ - "category_name", - "prefix", - "extension", - "type_name", -]) - -def artifact_name_pattern(category_name, prefix, extension): - """ The name for an artifact of a given category of input or output artifacts to an action. - - Args: - category_name: The category of artifacts that this selection applies - to. This field is compared against a list of categories defined - in bazel. Example categories include "linked_output" or - "debug_symbols". An error is thrown if no category is matched. - prefix: The prefix for creating the artifact for this selection. - Together with the extension it is used to create an artifact name - based on the target name. - extension: The extension for creating the artifact for this selection. - Together with the prefix it is used to create an artifact name - based on the target name. - - Returns: - An ArtifactNamePatternInfo provider - """ - _check_is_nonempty_string(category_name, "category_name", "artifact_name_pattern") - _check_is_none_or_right_type(prefix, "", "prefix", "artifact_name_pattern") - _check_is_none_or_right_type(extension, "", "extension", "artifact_name_pattern") - return ArtifactNamePatternInfo( - category_name = category_name, - prefix = prefix, - extension = extension, - type_name = "artifact_name_pattern", - ) +load( + "@rules_cc//cc:cc_toolchain_config_lib.bzl", + _action_config = "action_config", + _artifact_name_pattern = "artifact_name_pattern", + _env_entry = "env_entry", + _env_set = "env_set", + _feature = "feature", + _feature_set = "feature_set", + _flag_group = "flag_group", + _flag_set = "flag_set", + _make_variable = "make_variable", + _tool = "tool", + _tool_path = "tool_path", + _with_feature_set = "with_feature_set", +) + +action_config = _action_config +artifact_name_pattern = _artifact_name_pattern +env_entry = _env_entry +env_set = _env_set +feature = _feature +feature_set = _feature_set +flag_group = _flag_group +flag_set = _flag_set +make_variable = _make_variable +tool = _tool +tool_path = _tool_path +with_feature_set = _with_feature_set diff --git a/tools/cpp/clang_deps_scanner_wrapper.sh.tpl b/tools/cpp/clang_deps_scanner_wrapper.sh.tpl deleted file mode 100644 index 0bff014aacf277..00000000000000 --- a/tools/cpp/clang_deps_scanner_wrapper.sh.tpl +++ /dev/null @@ -1,11 +0,0 @@ -#!/usr/bin/env bash -# -# Ship the environment to the C++ action -# -set -eu - -# Set-up the environment -%{env} - -# Call the C++ compiler -%{deps_scanner} -format=p1689 -- %{cc} "$@" >"$DEPS_SCANNER_OUTPUT_FILE" diff --git a/tools/cpp/clang_installation_error.bat.tpl b/tools/cpp/clang_installation_error.bat.tpl deleted file mode 100644 index 13668ae6536aa0..00000000000000 --- a/tools/cpp/clang_installation_error.bat.tpl +++ /dev/null @@ -1,24 +0,0 @@ -:: Copyright 2019 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. - -@echo OFF - -echo. 1>&2 -echo The target you are compiling requires the Clang compiler. 1>&2 -echo Bazel couldn't find a valid Clang installation on your machine. 1>&2 -%{clang_error_message} -echo Please check your installation following https://bazel.build/docs/windows#using 1>&2 -echo. 1>&2 - -exit /b 1 diff --git a/tools/cpp/compiler_flag.bzl b/tools/cpp/compiler_flag.bzl index dac11222111b30..420b5091667b17 100644 --- a/tools/cpp/compiler_flag.bzl +++ b/tools/cpp/compiler_flag.bzl @@ -1,10 +1,10 @@ -# Copyright 2018 The Bazel Authors. All rights reserved. +# Copyright 2024 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 +# 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, @@ -12,18 +12,6 @@ # See the License for the specific language governing permissions and # limitations under the License. -"""Rule that allows select() to differentiate between compilers.""" +load("@rules_cc//cc:defs.bzl", _compiler_flag="compiler_flag") -load("//tools/cpp:toolchain_utils.bzl", "find_cpp_toolchain", "use_cpp_toolchain") - -def _compiler_flag_impl(ctx): - toolchain = find_cpp_toolchain(ctx) - return [config_common.FeatureFlagInfo(value = toolchain.compiler)] - -compiler_flag = rule( - implementation = _compiler_flag_impl, - attrs = { - "_cc_toolchain": attr.label(default = Label("//tools/cpp:current_cc_toolchain")), - }, - toolchains = use_cpp_toolchain(), -) +compiler_flag = _compiler_flag diff --git a/tools/cpp/empty.cc b/tools/cpp/empty.cc deleted file mode 100644 index 4cda5c6457453a..00000000000000 --- a/tools/cpp/empty.cc +++ /dev/null @@ -1,15 +0,0 @@ -// Copyright 2017 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. - -int main() {} diff --git a/tools/cpp/empty_cc_toolchain_config.bzl b/tools/cpp/empty_cc_toolchain_config.bzl deleted file mode 100644 index 5d42d06c9b39e5..00000000000000 --- a/tools/cpp/empty_cc_toolchain_config.bzl +++ /dev/null @@ -1,42 +0,0 @@ -# Copyright 2019 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. - -"""A fake C++ toolchain configuration rule""" - -def _impl(ctx): - out = ctx.actions.declare_file(ctx.label.name) - ctx.actions.write(out, "Fake executable") - return [ - cc_common.create_cc_toolchain_config_info( - ctx = ctx, - toolchain_identifier = "local_linux", - host_system_name = "local", - target_system_name = "local", - target_cpu = "local", - target_libc = "local", - compiler = "compiler", - abi_version = "local", - abi_libc_version = "local", - ), - DefaultInfo( - executable = out, - ), - ] - -cc_toolchain_config = rule( - implementation = _impl, - attrs = {}, - provides = [CcToolchainConfigInfo], - executable = True, -) diff --git a/tools/cpp/gcc_deps_scanner_wrapper.sh.tpl b/tools/cpp/gcc_deps_scanner_wrapper.sh.tpl deleted file mode 100644 index 94364932b3ce74..00000000000000 --- a/tools/cpp/gcc_deps_scanner_wrapper.sh.tpl +++ /dev/null @@ -1,12 +0,0 @@ -#!/bin/bash -# -# Ship the environment to the C++ action -# -set -eu - -# Set-up the environment -%{env} - -# Call the C++ compiler - -%{cc} -E -x c++ -fmodules-ts -fdeps-file=out.tmp -fdeps-format=p1689r5 "$@" >"$DEPS_SCANNER_OUTPUT_FILE" diff --git a/tools/cpp/generate_system_module_map.sh b/tools/cpp/generate_system_module_map.sh deleted file mode 100755 index deb52c2f6b6548..00000000000000 --- a/tools/cpp/generate_system_module_map.sh +++ /dev/null @@ -1,35 +0,0 @@ -#!/bin/bash -# Copyright 2020 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. - -set -eu - -echo 'module "crosstool" [system] {' - -if [[ "$OSTYPE" == darwin* ]]; then - for dir in $@; do - find "$dir" -type f \( -name "*.h" -o -name "*.def" -o -path "*/c++/*" \) \ - | LANG=C sort -u | while read -r header; do - echo " textual header \"${header}\"" - done - done -else - for dir in $@; do - find -L "${dir}" -type f 2>/dev/null | LANG=C sort -u | while read -r header; do - echo " textual header \"${header}\"" - done - done -fi - -echo "}" diff --git a/tools/cpp/grep-includes.sh b/tools/cpp/grep-includes.sh deleted file mode 100755 index ee51361cabc17b..00000000000000 --- a/tools/cpp/grep-includes.sh +++ /dev/null @@ -1,19 +0,0 @@ -#!/bin/bash -# -# Copyright 2018 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. -# -# TODO(bazel-team): Support include scanning and grep-includes in Bazel -echo "grep-includes is not supported by Bazel" -exit 1 diff --git a/tools/cpp/lib_cc_configure.bzl b/tools/cpp/lib_cc_configure.bzl index 67ee9ca5c6c639..b6bce5e22483d5 100644 --- a/tools/cpp/lib_cc_configure.bzl +++ b/tools/cpp/lib_cc_configure.bzl @@ -1,258 +1,17 @@ -# pylint: disable=g-bad-file-header -# Copyright 2016 The Bazel Authors. All rights reserved. +# Copyright 2024 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 +# 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. -"""Base library for configuring the C++ toolchain.""" -def resolve_labels(repository_ctx, labels): - """Resolves a collection of labels to their paths. +load("@rules_cc//cc/toolchains:toolchain_config_utils.bzl", _escape_string="escape_string") - Label resolution can cause the evaluation of Starlark functions to restart. - For functions with side-effects (like the auto-configuration functions, which - inspect the system and touch the file system), such restarts are costly. - We cannot avoid the restarts, but we can minimize their penalty by resolving - all labels upfront. - - Among other things, doing less work on restarts can cut analysis times by - several seconds and may also prevent tickling kernel conditions that cause - build failures. See https://github.com/bazelbuild/bazel/issues/5196 for - more details. - - Args: - repository_ctx: The context with which to resolve the labels. - labels: Labels to be resolved expressed as a list of strings. - - Returns: - A dictionary with the labels as keys and their paths as values. - """ - return dict([(label, repository_ctx.path(Label(label))) for label in labels]) - -def escape_string(arg): - """Escape percent sign (%) in the string so it can appear in the Crosstool.""" - if arg != None: - return str(arg).replace("%", "%%") - else: - return None - -def split_escaped(string, delimiter): - """Split string on the delimiter unless %-escaped. - - Examples: - Basic usage: - split_escaped("a:b:c", ":") -> [ "a", "b", "c" ] - - Delimiter that is not supposed to be splitten on has to be %-escaped: - split_escaped("a%:b", ":") -> [ "a:b" ] - - Literal % can be represented by escaping it as %%: - split_escaped("a%%b", ":") -> [ "a%b" ] - - Consecutive delimiters produce empty strings: - split_escaped("a::b", ":") -> [ "a", "", "", "b" ] - - Args: - string: The string to be split. - delimiter: Non-empty string not containing %-sign to be used as a - delimiter. - - Returns: - A list of substrings. - """ - if delimiter == "": - fail("Delimiter cannot be empty") - if delimiter.find("%") != -1: - fail("Delimiter cannot contain %-sign") - - i = 0 - result = [] - accumulator = [] - length = len(string) - delimiter_length = len(delimiter) - - if not string: - return [] - - # Iterate over the length of string since Starlark doesn't have while loops - for _ in range(length): - if i >= length: - break - if i + 2 <= length and string[i:i + 2] == "%%": - accumulator.append("%") - i += 2 - elif (i + 1 + delimiter_length <= length and - string[i:i + 1 + delimiter_length] == "%" + delimiter): - accumulator.append(delimiter) - i += 1 + delimiter_length - elif i + delimiter_length <= length and string[i:i + delimiter_length] == delimiter: - result.append("".join(accumulator)) - accumulator = [] - i += delimiter_length - else: - accumulator.append(string[i]) - i += 1 - - # Append the last group still in accumulator - result.append("".join(accumulator)) - return result - -def auto_configure_fail(msg): - """Output failure message when auto configuration fails.""" - red = "\033[0;31m" - no_color = "\033[0m" - fail("\n%sAuto-Configuration Error:%s %s\n" % (red, no_color, msg)) - -def auto_configure_warning(msg): - """Output warning message during auto configuration.""" - yellow = "\033[1;33m" - no_color = "\033[0m" - print("\n%sAuto-Configuration Warning:%s %s\n" % (yellow, no_color, msg)) - -def get_env_var(repository_ctx, name, default = None, enable_warning = True): - """Find an environment variable in system path. Doesn't %-escape the value!""" - if name in repository_ctx.os.environ: - return repository_ctx.os.environ[name] - if default != None: - if enable_warning: - auto_configure_warning("'%s' environment variable is not set, using '%s' as default" % (name, default)) - return default - auto_configure_fail("'%s' environment variable is not set" % name) - -def which(repository_ctx, cmd, default = None): - """A wrapper around repository_ctx.which() to provide a fallback value. Doesn't %-escape the value!""" - result = repository_ctx.which(cmd) - return default if result == None else str(result) - -def which_cmd(repository_ctx, cmd, default = None): - """Find cmd in PATH using repository_ctx.which() and fail if cannot find it. Doesn't %-escape the cmd!""" - result = repository_ctx.which(cmd) - if result != None: - return str(result) - path = get_env_var(repository_ctx, "PATH") - if default != None: - auto_configure_warning("Cannot find %s in PATH, using '%s' as default.\nPATH=%s" % (cmd, default, path)) - return default - auto_configure_fail("Cannot find %s in PATH, please make sure %s is installed and add its directory in PATH.\nPATH=%s" % (cmd, cmd, path)) - return str(result) - -def execute( - repository_ctx, - command, - environment = None, - expect_failure = False, - expect_empty_output = False): - """Execute a command, return stdout if succeed and throw an error if it fails. Doesn't %-escape the result!""" - if environment: - result = repository_ctx.execute(command, environment = environment) - else: - result = repository_ctx.execute(command) - if expect_failure != (result.return_code != 0): - if expect_failure: - auto_configure_fail( - "expected failure, command %s, stderr: (%s)" % ( - command, - result.stderr, - ), - ) - else: - auto_configure_fail( - "non-zero exit code: %d, command %s, stderr: (%s)" % ( - result.return_code, - command, - result.stderr, - ), - ) - stripped_stdout = result.stdout.strip() - if expect_empty_output != (not stripped_stdout): - if expect_empty_output: - auto_configure_fail( - "non-empty output from command %s, stdout: (%s), stderr: (%s)" % (command, result.stdout, result.stderr), - ) - else: - auto_configure_fail( - "empty output from command %s, stderr: (%s)" % (command, result.stderr), - ) - return stripped_stdout - -def get_cpu_value(repository_ctx): - """Compute the cpu_value based on the OS name. Doesn't %-escape the result!""" - os_name = repository_ctx.os.name - arch = repository_ctx.os.arch - if os_name.startswith("mac os"): - # Check if we are on x86_64 or arm64 and return the corresponding cpu value. - return "darwin_" + ("arm64" if arch == "aarch64" else "x86_64") - if os_name.find("freebsd") != -1: - return "freebsd" - if os_name.find("openbsd") != -1: - return "openbsd" - if os_name.find("windows") != -1: - if arch == "aarch64": - return "arm64_windows" - else: - return "x64_windows" - - if arch in ["power", "ppc64le", "ppc", "ppc64"]: - return "ppc" - if arch in ["s390x"]: - return "s390x" - if arch in ["mips64"]: - return "mips64" - if arch in ["riscv64"]: - return "riscv64" - if arch in ["arm", "armv7l"]: - return "arm" - if arch in ["aarch64"]: - return "aarch64" - return "k8" if arch in ["amd64", "x86_64", "x64"] else "piii" - -def is_cc_configure_debug(repository_ctx): - """Returns True if CC_CONFIGURE_DEBUG is set to 1.""" - env = repository_ctx.os.environ - return "CC_CONFIGURE_DEBUG" in env and env["CC_CONFIGURE_DEBUG"] == "1" - -def build_flags(flags): - """Convert `flags` to a string of flag fields.""" - return "\n".join([" flag: '" + flag + "'" for flag in flags]) - -def get_starlark_list(values): - """Convert a list of string into a string that can be passed to a rule attribute.""" - if not values: - return "" - return "\"" + "\",\n \"".join(values) + "\"" - -def auto_configure_warning_maybe(repository_ctx, msg): - """Output warning message when CC_CONFIGURE_DEBUG is enabled.""" - if is_cc_configure_debug(repository_ctx): - auto_configure_warning(msg) - -def write_builtin_include_directory_paths(repository_ctx, cc, directories, file_suffix = ""): - """Generate output file named 'builtin_include_directory_paths' in the root of the repository.""" - if get_env_var(repository_ctx, "BAZEL_IGNORE_SYSTEM_HEADERS_VERSIONS", "0", False) == "1": - repository_ctx.file( - "builtin_include_directory_paths" + file_suffix, - """This file is generated by cc_configure and normally contains builtin include directories -that C++ compiler reported. But because BAZEL_IGNORE_SYSTEM_HEADERS_VERSIONS was set to 1, -header include directory paths are intentionally not put there. -""", - ) - else: - repository_ctx.file( - "builtin_include_directory_paths" + file_suffix, - """This file is generated by cc_configure and contains builtin include directories -that %s reported. This file is a dependency of every compilation action and -changes to it will be reflected in the action cache key. When some of these -paths change, Bazel will make sure to rerun the action, even though none of -declared action inputs or the action commandline changes. - -%s -""" % (cc, "\n".join(directories)), - ) +escape_string = _escape_string diff --git a/tools/cpp/link_dynamic_library.sh b/tools/cpp/link_dynamic_library.sh deleted file mode 100755 index c71d49830ef7be..00000000000000 --- a/tools/cpp/link_dynamic_library.sh +++ /dev/null @@ -1,113 +0,0 @@ -#!/bin/bash -# -# Copyright 2016 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. - -# This script handles interface library generation for dynamic library -# link action. -# -# Bazel can be configured to generate external interface library script -# to generate interface libraries in CppLinkAction for dynamic libraries. -# This is not needed on Windows (as the "interface" libraries are -# generated by default). This script therefore handles the cases when -# external script is provided, or when no script should be used. - -set -eu - -E_LINKER_COMMAND_NOT_FOUND=12 -E_INTERFACE_BUILDER_NOT_FOUND=13 - - -SUFFIX=".rewritten" - -other_args="" - -if [[ "$#" -eq 1 ]]; then - if [[ "$1" != @* ]]; then - echo "Parameter file must start with @" 1>&2; - exit "$E_LINKER_COMMAND_NOT_FOUND" - fi - - filename=$(echo "$1" | cut -c2-) - first_five_lines=$(head -n 5 $filename) - - # Should generate interface library switch (); if the value is "no", - # following 3 args are ignored (but must be present) - GENERATE_INTERFACE_LIBRARY=$(echo "$first_five_lines" | head -n1 | tail -n1) - # Tool which can generate interface library from dynamic library file - INTERFACE_LIBRARY_BUILDER=$(echo "$first_five_lines" | head -n2 | tail -n1) - # Dynamic library from which we want to generate interface library - DYNAMIC_LIBRARY=$(echo "$first_five_lines" | head -n3 | tail -n1) - # Resulting interface library - INTERFACE_LIBRARY=$(echo "$first_five_lines" | head -n4 | tail -n1) - # The command used to generate the dynamic library - LINKER_COMMAND=$(echo "$first_five_lines" | head -n5 | tail -n1) - - rest_of_lines=$(tail -n +6 $filename) - new_param_file="${filename}${SUFFIX}" - echo "$rest_of_lines" > $new_param_file - other_args="@$new_param_file" - - if [[ ! -e "$LINKER_COMMAND" ]]; then - echo "Linker command ($LINKER_COMMAND) not found." 1>&2; - exit "$E_LINKER_COMMAND_NOT_FOUND" - fi - - if [[ "no" == "$GENERATE_INTERFACE_LIBRARY" ]]; then - INTERFACE_GENERATION=: - else - if [[ ! -e "$INTERFACE_LIBRARY_BUILDER" ]]; then - echo "Interface library builder ($INTERFACE_LIBRARY_BUILDER) - not found." 1>&2; - exit "$E_INTERFACE_BUILDER_NOT_FOUND" - fi - INTERFACE_GENERATION="${INTERFACE_LIBRARY_BUILDER} ${DYNAMIC_LIBRARY} - ${INTERFACE_LIBRARY}" - fi - - ${LINKER_COMMAND} "$other_args" && ${INTERFACE_GENERATION} -else - # TODO(b/113358321): Remove this branch once projects are migrated to not - # splitting the linking command line. - # Should generate interface library switch (); if the value is "no", - # following 3 args are ignored (but must be present) - GENERATE_INTERFACE_LIBRARY="$1" - # Tool which can generate interface library from dynamic library file - INTERFACE_LIBRARY_BUILDER="$2" - # Dynamic library from which we want to generate interface library - DYNAMIC_LIBRARY="$3" - # Resulting interface library - INTERFACE_LIBRARY="$4" - # The command used to generate the dynamic library - LINKER_COMMAND="$5" - shift 5 - if [[ ! -e "$LINKER_COMMAND" ]]; then - echo "Linker command ($LINKER_COMMAND) not found." 1>&2; - exit "$E_LINKER_COMMAND_NOT_FOUND" - fi - - if [[ "no" == "$GENERATE_INTERFACE_LIBRARY" ]]; then - INTERFACE_GENERATION=: - else - if [[ ! -e "$INTERFACE_LIBRARY_BUILDER" ]]; then - echo "Interface library builder ($INTERFACE_LIBRARY_BUILDER) - not found." 1>&2; - exit "$E_INTERFACE_BUILDER_NOT_FOUND" - fi - INTERFACE_GENERATION="${INTERFACE_LIBRARY_BUILDER} ${DYNAMIC_LIBRARY} - ${INTERFACE_LIBRARY}" - fi - - ${LINKER_COMMAND} "$@" && ${INTERFACE_GENERATION} -fi diff --git a/tools/cpp/linux_cc_wrapper.sh.tpl b/tools/cpp/linux_cc_wrapper.sh.tpl deleted file mode 100644 index 629741e55d181d..00000000000000 --- a/tools/cpp/linux_cc_wrapper.sh.tpl +++ /dev/null @@ -1,54 +0,0 @@ -#!/bin/bash -# -# Copyright 2015 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. -# -# Ship the environment to the C++ action -# -set -eu - -OUTPUT= - -function parse_option() { - local -r opt="$1" - if [[ "${OUTPUT}" = "1" ]]; then - OUTPUT=$opt - elif [[ "$opt" = "-o" ]]; then - # output is coming - OUTPUT=1 - fi -} - -# let parse the option list -for i in "$@"; do - if [[ "$i" = @* && -r "${i:1}" ]]; then - while IFS= read -r opt - do - parse_option "$opt" - done < "${i:1}" || exit 1 - else - parse_option "$i" - fi -done - -# Set-up the environment -%{env} - -# Call the C++ compiler -%{cc} "$@" - -# Generate an empty file if header processing succeeded. -if [[ "${OUTPUT}" == *.h.processed ]]; then - echo -n > "${OUTPUT}" -fi diff --git a/tools/cpp/msvc_deps_scanner_wrapper.bat.tpl b/tools/cpp/msvc_deps_scanner_wrapper.bat.tpl deleted file mode 100644 index 2c6200f88d38d5..00000000000000 --- a/tools/cpp/msvc_deps_scanner_wrapper.bat.tpl +++ /dev/null @@ -1,16 +0,0 @@ -:: Copyright 2024 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. - -@echo OFF -"%{cc}" /scanDependencies- /TP %* >%DEPS_SCANNER_OUTPUT_FILE% diff --git a/tools/cpp/msys_gcc_installation_error.bat b/tools/cpp/msys_gcc_installation_error.bat deleted file mode 100644 index 25c35534f97533..00000000000000 --- a/tools/cpp/msys_gcc_installation_error.bat +++ /dev/null @@ -1,23 +0,0 @@ -:: Copyright 2018 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. - -@echo OFF - -echo. 1>&2 -echo The target you are compiling requires MSYS gcc / MINGW gcc. 1>&2 -echo Bazel couldn't find gcc installation on your machine. 1>&2 -echo Please install MSYS gcc / MINGW gcc and set BAZEL_SH environment variable 1>&2 -echo. 1>&2 - -exit /b 1 diff --git a/tools/cpp/osx_cc_wrapper.sh.tpl b/tools/cpp/osx_cc_wrapper.sh.tpl deleted file mode 100644 index e40a98bb1a601d..00000000000000 --- a/tools/cpp/osx_cc_wrapper.sh.tpl +++ /dev/null @@ -1,138 +0,0 @@ -#!/bin/bash -# -# Copyright 2015 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. -# -# OS X relpath is not really working. This is a wrapper script around gcc -# to simulate relpath behavior. -# -# This wrapper uses install_name_tool to replace all paths in the binary -# (bazel-out/.../path/to/original/library.so) by the paths relative to -# the binary. It parses the command line to behave as rpath is supposed -# to work. -# -# See https://blogs.oracle.com/dipol/entry/dynamic_libraries_rpath_and_mac -# on how to set those paths for Mach-O binaries. -# -set -eu - -LIBS= -LIB_PATHS= -LIB_DIRS= -RPATHS= -OUTPUT= - -function parse_option() { - local -r opt="$1" - if [[ "${OUTPUT}" = "1" ]]; then - OUTPUT=$opt - elif [[ "$opt" =~ ^-l(.*)$ ]]; then - LIBS="${BASH_REMATCH[1]} $LIBS" - elif [[ "$opt" =~ ^(.*)\.so$ ]]; then - LIB_PATHS="${opt} $LIB_PATHS" - elif [[ "$opt" =~ ^(.*)\.dylib$ ]]; then - LIB_PATHS="${opt} $LIB_PATHS" - elif [[ "$opt" =~ ^-L(.*)$ ]]; then - LIB_DIRS="${BASH_REMATCH[1]} $LIB_DIRS" - elif [[ "$opt" =~ ^\@loader_path/(.*)$ ]]; then - RPATHS="${BASH_REMATCH[1]} ${RPATHS}" - elif [[ "$opt" = "-o" ]]; then - # output is coming - OUTPUT=1 - fi -} - -# let parse the option list -for i in "$@"; do - if [[ "$i" = @* && -r "${i:1}" ]]; then - while IFS= read -r opt - do - parse_option "$opt" - done < "${i:1}" || exit 1 - else - parse_option "$i" - fi -done - -# Set-up the environment -%{env} - -# Call the C++ compiler -%{cc} "$@" - -# Generate an empty file if header processing succeeded. -if [[ "${OUTPUT}" == *.h.processed ]]; then - echo -n > "${OUTPUT}" -fi - -function get_library_path() { - for libdir in ${LIB_DIRS}; do - if [ -f ${libdir}/lib$1.so ]; then - echo "${libdir}/lib$1.so" - elif [ -f ${libdir}/lib$1.dylib ]; then - echo "${libdir}/lib$1.dylib" - fi - done -} - -# A convenient method to return the actual path even for non symlinks -# and multi-level symlinks. -function get_realpath() { - local previous="$1" - local next=$(readlink "${previous}") - while [ -n "${next}" ]; do - previous="${next}" - next=$(readlink "${previous}") - done - echo "${previous}" -} - -# Get the path of a lib inside a tool -function get_otool_path() { - # the lib path is the path of the original lib relative to the workspace - get_realpath $1 | sed 's|^.*/bazel-out/|bazel-out/|' -} - -function call_install_name() { - /usr/bin/xcrun install_name_tool -change $(get_otool_path "$1") \ - "@loader_path/$2/$3" "${OUTPUT}" -} - -# Do replacements in the output -for rpath in ${RPATHS}; do - for lib in ${LIBS}; do - unset libname - if [ -f "$(dirname ${OUTPUT})/${rpath}/lib${lib}.so" ]; then - libname="lib${lib}.so" - elif [ -f "$(dirname ${OUTPUT})/${rpath}/lib${lib}.dylib" ]; then - libname="lib${lib}.dylib" - fi - # ${libname-} --> return $libname if defined, or undefined otherwise. This is to make - # this set -e friendly - if [[ -n "${libname-}" ]]; then - libpath=$(get_library_path ${lib}) - if [ -n "${libpath}" ]; then - call_install_name "${libpath}" "${rpath}" "${libname}" - fi - fi - done - for libpath in ${LIB_PATHS}; do - if [ -f "$libpath" ]; then - libname=$(basename "$libpath") - if [ -f "$(dirname ${OUTPUT})/${rpath}/${libname}" ]; then - call_install_name "${libpath}" "${rpath}" "${libname}" - fi - fi - done -done diff --git a/tools/cpp/toolchain_utils.bzl b/tools/cpp/toolchain_utils.bzl index 9bf5bc4ecc980a..8fd27dca6858bb 100644 --- a/tools/cpp/toolchain_utils.bzl +++ b/tools/cpp/toolchain_utils.bzl @@ -1,11 +1,10 @@ -# pylint: disable=g-bad-file-header -# Copyright 2016 The Bazel Authors. All rights reserved. +# Copyright 2024 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 +# 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, @@ -13,70 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -""" -Utilities to help work with c++ toolchains. -""" +load("@rules_cc//cc:find_cc_toolchain.bzl", "find_cc_toolchain", "use_cc_toolchain") -CPP_TOOLCHAIN_TYPE = "@bazel_tools//tools/cpp:toolchain_type" - -def find_cpp_toolchain(ctx, *, mandatory = True): - """ - Finds the c++ toolchain. - - If the c++ toolchain is in use, returns it. Otherwise, returns a c++ - toolchain derived from legacy toolchain selection, constructed from - the CppConfiguration. - - Args: - ctx: The rule context for which to find a toolchain. - mandatory: If this is set to False, this function will return None rather - than fail if no toolchain is found. To use this parameter, the calling - rule should have a `_cc_toolchain` label attribute with default - `@bazel_tools//tools/cpp:optional_current_cc_toolchain`. - - Returns: - A CcToolchainProvider, or None if the c++ toolchain is declared as - optional, mandatory is False and no toolchain has been found. - """ - - # Check the incompatible flag for toolchain resolution. - if hasattr(cc_common, "is_cc_toolchain_resolution_enabled_do_not_use") and cc_common.is_cc_toolchain_resolution_enabled_do_not_use(ctx = ctx): - if not CPP_TOOLCHAIN_TYPE in ctx.toolchains: - fail("In order to use find_cpp_toolchain, you must include the '%s' in the toolchains argument to your rule." % CPP_TOOLCHAIN_TYPE) - toolchain_info = ctx.toolchains[CPP_TOOLCHAIN_TYPE] - if toolchain_info == None: - if not mandatory: - return None - - # No cpp toolchain was found, so report an error. - fail("Unable to find a CC toolchain using toolchain resolution. Target: %s, Platform: %s, Exec platform: %s" % - (ctx.label, ctx.fragments.platform.platform, ctx.fragments.platform.host_platform)) - if hasattr(toolchain_info, "cc_provider_in_toolchain") and hasattr(toolchain_info, "cc"): - return toolchain_info.cc - return toolchain_info - - # Fall back to the legacy implicit attribute lookup. - if hasattr(ctx.attr, "_cc_toolchain"): - return ctx.attr._cc_toolchain[cc_common.CcToolchainInfo] - - # We didn't find anything. - fail("In order to use find_cpp_toolchain, you must define the '_cc_toolchain' attribute on your rule or aspect.") - -def use_cpp_toolchain(mandatory = False): - """ - Helper to depend on the c++ toolchain. - - Usage: - ``` - my_rule = rule( - toolchains = [other toolchain types] + use_cpp_toolchain(), - ) - ``` - - Args: - mandatory: Whether or not it should be an error if the toolchain cannot be resolved. - - Returns: - A list that can be used as the value for `rule.toolchains`. - """ - return [config_common.toolchain_type(CPP_TOOLCHAIN_TYPE, mandatory = mandatory)] +find_cpp_toolchain = find_cc_toolchain +use_cpp_toolchain = use_cc_toolchain diff --git a/tools/cpp/unix_cc_configure.bzl b/tools/cpp/unix_cc_configure.bzl deleted file mode 100644 index 0e796a1504783e..00000000000000 --- a/tools/cpp/unix_cc_configure.bzl +++ /dev/null @@ -1,757 +0,0 @@ -# pylint: disable=g-bad-file-header -# Copyright 2016 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. -"""Configuring the C++ toolchain on Unix platforms.""" - -load( - "@bazel_tools//tools/cpp:lib_cc_configure.bzl", - "auto_configure_fail", - "auto_configure_warning", - "auto_configure_warning_maybe", - "escape_string", - "execute", - "get_env_var", - "get_starlark_list", - "resolve_labels", - "split_escaped", - "which", - "write_builtin_include_directory_paths", -) - -def _uniq(iterable): - """Remove duplicates from a list.""" - - unique_elements = {element: None for element in iterable} - return unique_elements.keys() - -def _generate_system_module_map(repository_ctx, dirs, script_path): - return execute(repository_ctx, [script_path] + dirs) - -def _prepare_include_path(repo_ctx, path): - """Resolve include path before outputting it into the crosstool. - - Args: - repo_ctx: repository_ctx object. - path: an include path to be resolved. - - Returns: - Resolved include path. Resulting path is absolute if it is outside the - repository and relative otherwise. - """ - - repo_root = str(repo_ctx.path(".")) - - # We're on UNIX, so the path delimiter is '/'. - repo_root += "/" - path = str(repo_ctx.path(path)) - if path.startswith(repo_root): - return path[len(repo_root):] - return path - -def _get_value(it): - """Convert `it` in serialized protobuf format.""" - if type(it) == "int": - return str(it) - elif type(it) == "bool": - return "true" if it else "false" - else: - return "\"%s\"" % it - -def _find_tool(repository_ctx, tool, overriden_tools): - """Find a tool for repository, taking overridden tools into account.""" - if tool in overriden_tools: - return overriden_tools[tool] - return which(repository_ctx, tool, "/usr/bin/" + tool) - -def _get_tool_paths(repository_ctx, overriden_tools): - """Compute the %-escaped path to the various tools""" - return dict({ - k: escape_string(_find_tool(repository_ctx, k, overriden_tools)) - for k in [ - "ar", - "ld", - "llvm-cov", - "llvm-profdata", - "cpp", - "gcc", - "dwp", - "gcov", - "nm", - "objcopy", - "objdump", - "strip", - "c++filt", - ] - }.items()) - -def _escaped_cplus_include_paths(repository_ctx): - """Use ${CPLUS_INCLUDE_PATH} to compute the %-escaped list of flags for cxxflag.""" - if "CPLUS_INCLUDE_PATH" in repository_ctx.os.environ: - result = [] - for p in repository_ctx.os.environ["CPLUS_INCLUDE_PATH"].split(":"): - p = escape_string(str(repository_ctx.path(p))) # Normalize the path - result.append("-I" + p) - return result - else: - return [] - -_INC_DIR_MARKER_BEGIN = "#include <...>" - -# OSX add " (framework directory)" at the end of line, strip it. -_OSX_FRAMEWORK_SUFFIX = " (framework directory)" -_OSX_FRAMEWORK_SUFFIX_LEN = len(_OSX_FRAMEWORK_SUFFIX) - -def _cxx_inc_convert(path): - """Convert path returned by cc -E xc++ in a complete path. Doesn't %-escape the path!""" - path = path.strip() - if path.endswith(_OSX_FRAMEWORK_SUFFIX): - path = path[:-_OSX_FRAMEWORK_SUFFIX_LEN].strip() - return path - -def _get_cxx_include_directories(repository_ctx, print_resource_dir_supported, cc, lang_flag, additional_flags = []): - """Compute the list of C++ include directories.""" - result = repository_ctx.execute([cc, "-E", lang_flag, "-", "-v"] + additional_flags) - index1 = result.stderr.find(_INC_DIR_MARKER_BEGIN) - if index1 == -1: - return [] - index1 = result.stderr.find("\n", index1) - if index1 == -1: - return [] - index2 = result.stderr.rfind("\n ") - if index2 == -1 or index2 < index1: - return [] - index2 = result.stderr.find("\n", index2 + 1) - if index2 == -1: - inc_dirs = result.stderr[index1 + 1:] - else: - inc_dirs = result.stderr[index1 + 1:index2].strip() - - inc_directories = [ - _prepare_include_path(repository_ctx, _cxx_inc_convert(p)) - for p in inc_dirs.split("\n") - ] - - if print_resource_dir_supported: - resource_dir = repository_ctx.execute( - [cc, "-print-resource-dir"] + additional_flags, - ).stdout.strip() + "/share" - inc_directories.append(_prepare_include_path(repository_ctx, resource_dir)) - - return inc_directories - -def _is_compiler_option_supported(repository_ctx, cc, option): - """Checks that `option` is supported by the C compiler. Doesn't %-escape the option.""" - result = repository_ctx.execute([ - cc, - option, - "-o", - "/dev/null", - "-c", - str(repository_ctx.path("tools/cpp/empty.cc")), - ]) - return result.stderr.find(option) == -1 - -def _is_linker_option_supported(repository_ctx, cc, force_linker_flags, option, pattern): - """Checks that `option` is supported by the C linker. Doesn't %-escape the option.""" - result = repository_ctx.execute([cc] + force_linker_flags + [ - option, - "-o", - "/dev/null", - str(repository_ctx.path("tools/cpp/empty.cc")), - ]) - return result.stderr.find(pattern) == -1 - -def _find_linker_path(repository_ctx, cc, linker, is_clang): - """Checks if a given linker is supported by the C compiler. - - Args: - repository_ctx: repository_ctx. - cc: path to the C compiler. - linker: linker to find - is_clang: whether the compiler is known to be clang - - Returns: - String to put as value to -fuse-ld= flag, or None if linker couldn't be found. - """ - result = repository_ctx.execute([ - cc, - str(repository_ctx.path("tools/cpp/empty.cc")), - "-o", - "/dev/null", - # Some macOS clang versions don't fail when setting -fuse-ld=gold, adding - # these lines to force it to. This also means that we will not detect - # gold when only a very old (year 2010 and older) is present. - "-Wl,--start-lib", - "-Wl,--end-lib", - "-fuse-ld=" + linker, - "-v", - ]) - if result.return_code != 0: - return None - - if not is_clang: - return linker - - # Extract linker path from: - # /usr/bin/clang ... - # "/usr/bin/ld.lld" -pie -z ... - linker_command = result.stderr.splitlines()[-1] - return linker_command.strip().split(" ")[0].strip("\"'") - -def _add_compiler_option_if_supported(repository_ctx, cc, option): - """Returns `[option]` if supported, `[]` otherwise. Doesn't %-escape the option.""" - return [option] if _is_compiler_option_supported(repository_ctx, cc, option) else [] - -def _add_linker_option_if_supported(repository_ctx, cc, force_linker_flags, option, pattern): - """Returns `[option]` if supported, `[]` otherwise. Doesn't %-escape the option.""" - return [option] if _is_linker_option_supported(repository_ctx, cc, force_linker_flags, option, pattern) else [] - -def _get_no_canonical_prefixes_opt(repository_ctx, cc): - # If the compiler sometimes rewrites paths in the .d files without symlinks - # (ie when they're shorter), it confuses Bazel's logic for verifying all - # #included header files are listed as inputs to the action. - - # The '-fno-canonical-system-headers' should be enough, but clang does not - # support it, so we also try '-no-canonical-prefixes' if first option does - # not work. - opt = _add_compiler_option_if_supported( - repository_ctx, - cc, - "-fno-canonical-system-headers", - ) - if len(opt) == 0: - return _add_compiler_option_if_supported( - repository_ctx, - cc, - "-no-canonical-prefixes", - ) - return opt - -def get_env(repository_ctx): - """Convert the environment in a list of export if in Homebrew. Doesn't %-escape the result!""" - env = repository_ctx.os.environ - if "HOMEBREW_RUBY_PATH" in env: - return "\n".join([ - "export %s='%s'" % (k, env[k].replace("'", "'\\''")) - for k in env - if k != "_" and k.find(".") == -1 - ]) - else: - return "" - -def _coverage_flags(repository_ctx, darwin): - use_llvm_cov = "1" == get_env_var( - repository_ctx, - "BAZEL_USE_LLVM_NATIVE_COVERAGE", - default = "0", - enable_warning = False, - ) - if darwin or use_llvm_cov: - compile_flags = '"-fprofile-instr-generate", "-fcoverage-mapping"' - link_flags = '"-fprofile-instr-generate"' - else: - # gcc requires --coverage being passed for compilation and linking - # https://gcc.gnu.org/onlinedocs/gcc/Instrumentation-Options.html#Instrumentation-Options - compile_flags = '"--coverage"' - link_flags = '"--coverage"' - return compile_flags, link_flags - -def _is_clang(repository_ctx, cc): - return "clang" in repository_ctx.execute([cc, "-v"]).stderr - -def _is_gcc(repository_ctx, cc): - # GCC's version output uses the basename of argv[0] as the program name: - # https://gcc.gnu.org/git/?p=gcc.git;a=blob;f=gcc/gcc.cc;h=158461167951c1b9540322fb19be6a89d6da07fc;hb=HEAD#l8728 - cc_stdout = repository_ctx.execute([cc, "--version"]).stdout - return cc_stdout.startswith("gcc ") or cc_stdout.startswith("gcc-") - -def _get_compiler_name(repository_ctx, cc): - if _is_clang(repository_ctx, cc): - return "clang" - if _is_gcc(repository_ctx, cc): - return "gcc" - return "compiler" - -def _find_generic(repository_ctx, name, env_name, overriden_tools, warn = False, silent = False): - """Find a generic C++ toolchain tool. Doesn't %-escape the result.""" - - if name in overriden_tools: - return overriden_tools[name] - - result = name - env_value = repository_ctx.os.environ.get(env_name) - env_value_with_paren = "" - if env_value != None: - env_value = env_value.strip() - if env_value: - result = env_value - env_value_with_paren = " (%s)" % env_value - if result.startswith("/"): - # Absolute path, maybe we should make this supported by our which function. - return result - result = repository_ctx.which(result) - if result == None: - msg = ("Cannot find %s or %s%s; either correct your path or set the %s" + - " environment variable") % (name, env_name, env_value_with_paren, env_name) - if warn: - if not silent: - auto_configure_warning(msg) - else: - auto_configure_fail(msg) - return result - -def find_cc(repository_ctx, overriden_tools): - cc = _find_generic(repository_ctx, "gcc", "CC", overriden_tools) - if _is_clang(repository_ctx, cc): - # If clang is run through a symlink with -no-canonical-prefixes, it does - # not find its own include directory, which includes the headers for - # libc++. Resolving the potential symlink here prevents this. - result = repository_ctx.execute(["readlink", "-f", cc]) - if result.return_code == 0: - return result.stdout.strip() - return cc - -def configure_unix_toolchain(repository_ctx, cpu_value, overriden_tools): - """Configure C++ toolchain on Unix platforms.""" - paths = resolve_labels(repository_ctx, [ - "@bazel_tools//tools/cpp:BUILD.tpl", - "@bazel_tools//tools/cpp:generate_system_module_map.sh", - "@bazel_tools//tools/cpp:armeabi_cc_toolchain_config.bzl", - "@bazel_tools//tools/cpp:unix_cc_toolchain_config.bzl", - "@bazel_tools//tools/cpp:linux_cc_wrapper.sh.tpl", - "@bazel_tools//tools/cpp:validate_static_library.sh.tpl", - "@bazel_tools//tools/cpp:osx_cc_wrapper.sh.tpl", - "@bazel_tools//tools/cpp:clang_deps_scanner_wrapper.sh.tpl", - "@bazel_tools//tools/cpp:gcc_deps_scanner_wrapper.sh.tpl", - ]) - - repository_ctx.symlink( - paths["@bazel_tools//tools/cpp:unix_cc_toolchain_config.bzl"], - "cc_toolchain_config.bzl", - ) - - repository_ctx.symlink( - paths["@bazel_tools//tools/cpp:armeabi_cc_toolchain_config.bzl"], - "armeabi_cc_toolchain_config.bzl", - ) - - repository_ctx.file("tools/cpp/empty.cc", "int main() {}") - darwin = cpu_value.startswith("darwin") - bsd = cpu_value == "freebsd" or cpu_value == "openbsd" - - cc = find_cc(repository_ctx, overriden_tools) - is_clang = _is_clang(repository_ctx, cc) - overriden_tools = dict(overriden_tools) - overriden_tools["gcc"] = cc - overriden_tools["gcov"] = _find_generic( - repository_ctx, - "gcov", - "GCOV", - overriden_tools, - warn = True, - silent = True, - ) - overriden_tools["llvm-cov"] = _find_generic( - repository_ctx, - "llvm-cov", - "BAZEL_LLVM_COV", - overriden_tools, - warn = True, - silent = True, - ) - overriden_tools["llvm-profdata"] = _find_generic( - repository_ctx, - "llvm-profdata", - "BAZEL_LLVM_PROFDATA", - overriden_tools, - warn = True, - silent = True, - ) - overriden_tools["ar"] = _find_generic( - repository_ctx, - "ar", - "AR", - overriden_tools, - warn = True, - silent = True, - ) - if darwin: - overriden_tools["gcc"] = "cc_wrapper.sh" - overriden_tools["ar"] = _find_generic(repository_ctx, "libtool", "LIBTOOL", overriden_tools) - - auto_configure_warning_maybe(repository_ctx, "CC used: " + str(cc)) - tool_paths = _get_tool_paths(repository_ctx, overriden_tools) - tool_paths["cpp-module-deps-scanner"] = "deps_scanner_wrapper.sh" - - # The parse_header tool needs to be a wrapper around the compiler as it has - # to touch the output file. - tool_paths["parse_headers"] = "cc_wrapper.sh" - cc_toolchain_identifier = escape_string(get_env_var( - repository_ctx, - "CC_TOOLCHAIN_NAME", - "local", - False, - )) - - if "nm" in tool_paths and "c++filt" in tool_paths: - repository_ctx.template( - "validate_static_library.sh", - paths["@bazel_tools//tools/cpp:validate_static_library.sh.tpl"], - { - "%{nm}": escape_string(str(repository_ctx.path(tool_paths["nm"]))), - # Certain weak symbols are otherwise listed with type T in the output of nm on macOS. - "%{nm_extra_args}": "--no-weak" if darwin else "", - "%{c++filt}": escape_string(str(repository_ctx.path(tool_paths["c++filt"]))), - }, - ) - tool_paths["validate_static_library"] = "validate_static_library.sh" - - cc_wrapper_src = ( - "@bazel_tools//tools/cpp:osx_cc_wrapper.sh.tpl" if darwin else "@bazel_tools//tools/cpp:linux_cc_wrapper.sh.tpl" - ) - repository_ctx.template( - "cc_wrapper.sh", - paths[cc_wrapper_src], - { - "%{cc}": escape_string(str(cc)), - "%{env}": escape_string(get_env(repository_ctx)), - }, - ) - deps_scanner_wrapper_src = ( - "@bazel_tools//tools/cpp:clang_deps_scanner_wrapper.sh.tpl" if is_clang else "@bazel_tools//tools/cpp:gcc_deps_scanner_wrapper.sh.tpl" - ) - deps_scanner = "cpp-module-deps-scanner_not_found" - if is_clang: - cc_str = str(cc) - path_arr = cc_str.split("/")[:-1] - path_arr.append("clang-scan-deps") - deps_scanner = "/".join(path_arr) - repository_ctx.template( - "deps_scanner_wrapper.sh", - paths[deps_scanner_wrapper_src], - { - "%{cc}": escape_string(str(cc)), - "%{deps_scanner}": escape_string(deps_scanner), - "%{env}": escape_string(get_env(repository_ctx)), - }, - ) - - conly_opts = split_escaped(get_env_var( - repository_ctx, - "BAZEL_CONLYOPTS", - "", - False, - ), ":") - - cxx_opts = split_escaped(get_env_var( - repository_ctx, - "BAZEL_CXXOPTS", - "-std=c++17", - False, - ), ":") - - gold_or_lld_linker_path = ( - _find_linker_path(repository_ctx, cc, "lld", is_clang) or - _find_linker_path(repository_ctx, cc, "gold", is_clang) - ) - cc_path = repository_ctx.path(cc) - if not str(cc_path).startswith(str(repository_ctx.path(".")) + "/"): - # cc is outside the repository, set -B - bin_search_flags = ["-B" + escape_string(str(cc_path.dirname))] - else: - # cc is inside the repository, don't set -B. - bin_search_flags = [] - if not gold_or_lld_linker_path: - ld_path = repository_ctx.path(tool_paths["ld"]) - if ld_path.dirname != cc_path.dirname: - bin_search_flags.append("-B" + str(ld_path.dirname)) - force_linker_flags = [] - if gold_or_lld_linker_path: - force_linker_flags.append("-fuse-ld=" + gold_or_lld_linker_path) - - # TODO: It's unclear why these flags aren't added on macOS. - if bin_search_flags and not darwin: - force_linker_flags.extend(bin_search_flags) - use_libcpp = darwin or bsd - is_as_needed_supported = _is_linker_option_supported( - repository_ctx, - cc, - force_linker_flags, - "-Wl,-no-as-needed", - "-no-as-needed", - ) - is_push_state_supported = _is_linker_option_supported( - repository_ctx, - cc, - force_linker_flags, - "-Wl,--push-state", - "--push-state", - ) - if use_libcpp: - bazel_default_libs = ["-lc++", "-lm"] - else: - bazel_default_libs = ["-lstdc++", "-lm"] - if is_as_needed_supported and is_push_state_supported: - # Do not link against C++ standard libraries unless they are actually - # used. - # We assume that --push-state support implies --pop-state support. - bazel_linklibs_elements = [ - arg - for lib in bazel_default_libs - for arg in ["-Wl,--push-state,-as-needed", lib, "-Wl,--pop-state"] - ] - else: - bazel_linklibs_elements = bazel_default_libs - bazel_linklibs = ":".join(bazel_linklibs_elements) - bazel_linkopts = "" - - link_opts = split_escaped(get_env_var( - repository_ctx, - "BAZEL_LINKOPTS", - bazel_linkopts, - False, - ), ":") - link_libs = split_escaped(get_env_var( - repository_ctx, - "BAZEL_LINKLIBS", - bazel_linklibs, - False, - ), ":") - coverage_compile_flags, coverage_link_flags = _coverage_flags(repository_ctx, darwin) - print_resource_dir_supported = _is_compiler_option_supported( - repository_ctx, - cc, - "-print-resource-dir", - ) - no_canonical_prefixes_opt = _get_no_canonical_prefixes_opt(repository_ctx, cc) - builtin_include_directories = _uniq( - _get_cxx_include_directories(repository_ctx, print_resource_dir_supported, cc, "-xc", conly_opts) + - _get_cxx_include_directories(repository_ctx, print_resource_dir_supported, cc, "-xc++", cxx_opts) + - _get_cxx_include_directories( - repository_ctx, - print_resource_dir_supported, - cc, - "-xc++", - cxx_opts + ["-stdlib=libc++"], - ) + - _get_cxx_include_directories( - repository_ctx, - print_resource_dir_supported, - cc, - "-xc", - no_canonical_prefixes_opt, - ) + - _get_cxx_include_directories( - repository_ctx, - print_resource_dir_supported, - cc, - "-xc++", - cxx_opts + no_canonical_prefixes_opt, - ) + - _get_cxx_include_directories( - repository_ctx, - print_resource_dir_supported, - cc, - "-xc++", - cxx_opts + no_canonical_prefixes_opt + ["-stdlib=libc++"], - ) + - # Always included in case the user has Xcode + the CLT installed, both - # paths can be used interchangeably - ["/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk"], - ) - - generate_modulemap = is_clang - if generate_modulemap: - repository_ctx.file("module.modulemap", _generate_system_module_map( - repository_ctx, - builtin_include_directories, - paths["@bazel_tools//tools/cpp:generate_system_module_map.sh"], - )) - extra_flags_per_feature = {} - if is_clang: - # Only supported by LLVM 14 and later, but required with C++20 and - # layering_check as C++ modules are the default. - # https://github.com/llvm/llvm-project/commit/0556138624edf48621dd49a463dbe12e7101f17d - result = repository_ctx.execute([ - cc, - "-Xclang", - "-fno-cxx-modules", - "-o", - "/dev/null", - "-c", - str(repository_ctx.path("tools/cpp/empty.cc")), - ]) - if "-fno-cxx-modules" not in result.stderr: - extra_flags_per_feature["use_module_maps"] = ["-Xclang", "-fno-cxx-modules"] - - write_builtin_include_directory_paths(repository_ctx, cc, builtin_include_directories) - repository_ctx.template( - "BUILD", - paths["@bazel_tools//tools/cpp:BUILD.tpl"], - { - "%{cc_toolchain_identifier}": cc_toolchain_identifier, - "%{name}": cpu_value, - "%{modulemap}": ("\":module.modulemap\"" if generate_modulemap else "None"), - "%{cc_compiler_deps}": get_starlark_list([ - ":builtin_include_directory_paths", - ":cc_wrapper", - ":deps_scanner_wrapper", - ] + ( - [":validate_static_library"] if "validate_static_library" in tool_paths else [] - )), - "%{compiler}": escape_string(get_env_var( - repository_ctx, - "BAZEL_COMPILER", - _get_compiler_name(repository_ctx, cc), - False, - )), - "%{abi_version}": escape_string(get_env_var( - repository_ctx, - "ABI_VERSION", - "local", - False, - )), - "%{abi_libc_version}": escape_string(get_env_var( - repository_ctx, - "ABI_LIBC_VERSION", - "local", - False, - )), - "%{host_system_name}": escape_string(get_env_var( - repository_ctx, - "BAZEL_HOST_SYSTEM", - "local", - False, - )), - "%{target_libc}": "macosx" if darwin else escape_string(get_env_var( - repository_ctx, - "BAZEL_TARGET_LIBC", - "local", - False, - )), - "%{target_cpu}": escape_string(get_env_var( - repository_ctx, - "BAZEL_TARGET_CPU", - cpu_value, - False, - )), - "%{target_system_name}": escape_string(get_env_var( - repository_ctx, - "BAZEL_TARGET_SYSTEM", - "local", - False, - )), - "%{tool_paths}": ",\n ".join( - ['"%s": "%s"' % (k, v) for k, v in tool_paths.items() if v != None], - ), - "%{cxx_builtin_include_directories}": get_starlark_list(builtin_include_directories), - "%{compile_flags}": get_starlark_list( - [ - "-fstack-protector", - # All warnings are enabled. - "-Wall", - # Enable a few more warnings that aren't part of -Wall. - ] + (( - _add_compiler_option_if_supported(repository_ctx, cc, "-Wthread-safety") + - _add_compiler_option_if_supported(repository_ctx, cc, "-Wself-assign") - )) + ( - # Disable problematic warnings. - _add_compiler_option_if_supported(repository_ctx, cc, "-Wunused-but-set-parameter") + - # has false positives - _add_compiler_option_if_supported(repository_ctx, cc, "-Wno-free-nonheap-object") + - # Enable coloring even if there's no attached terminal. Bazel removes the - # escape sequences if --nocolor is specified. - _add_compiler_option_if_supported(repository_ctx, cc, "-fcolor-diagnostics") - ) + [ - # Keep stack frames for debugging, even in opt mode. - "-fno-omit-frame-pointer", - ], - ), - "%{cxx_flags}": get_starlark_list(cxx_opts + _escaped_cplus_include_paths(repository_ctx)), - "%{conly_flags}": get_starlark_list(conly_opts), - "%{link_flags}": get_starlark_list(force_linker_flags + ( - ["-Wl,-no-as-needed"] if is_as_needed_supported else [] - ) + _add_linker_option_if_supported( - repository_ctx, - cc, - force_linker_flags, - "-Wl,-z,relro,-z,now", - "-z", - ) + ( - [ - "-headerpad_max_install_names", - ] if darwin else [ - # Gold linker only? Can we enable this by default? - # "-Wl,--warn-execstack", - # "-Wl,--detect-odr-violations" - ] + _add_compiler_option_if_supported( - # Have gcc return the exit code from ld. - repository_ctx, - cc, - "-pass-exit-codes", - ) - ) + link_opts), - "%{link_libs}": get_starlark_list(link_libs), - "%{opt_compile_flags}": get_starlark_list( - [ - # No debug symbols. - # Maybe we should enable https://gcc.gnu.org/wiki/DebugFission for opt or - # even generally? However, that can't happen here, as it requires special - # handling in Bazel. - "-g0", - - # Conservative choice for -O - # -O3 can increase binary size and even slow down the resulting binaries. - # Profile first and / or use FDO if you need better performance than this. - "-O2", - - # Security hardening on by default. - # Conservative choice; -D_FORTIFY_SOURCE=2 may be unsafe in some cases. - "-D_FORTIFY_SOURCE=1", - - # Disable assertions - "-DNDEBUG", - - # Removal of unused code and data at link time (can this increase binary - # size in some cases?). - "-ffunction-sections", - "-fdata-sections", - ], - ), - "%{opt_link_flags}": get_starlark_list( - ["-Wl,-dead_strip"] if darwin else _add_linker_option_if_supported( - repository_ctx, - cc, - force_linker_flags, - "-Wl,--gc-sections", - "-gc-sections", - ), - ), - "%{unfiltered_compile_flags}": get_starlark_list( - _get_no_canonical_prefixes_opt(repository_ctx, cc) + [ - # Make C++ compilation deterministic. Use linkstamping instead of these - # compiler symbols. - "-Wno-builtin-macro-redefined", - "-D__DATE__=\\\"redacted\\\"", - "-D__TIMESTAMP__=\\\"redacted\\\"", - "-D__TIME__=\\\"redacted\\\"", - ], - ), - "%{dbg_compile_flags}": get_starlark_list(["-g"]), - "%{coverage_compile_flags}": coverage_compile_flags, - "%{coverage_link_flags}": coverage_link_flags, - "%{supports_start_end_lib}": "True" if gold_or_lld_linker_path else "False", - "%{extra_flags_per_feature}": repr(extra_flags_per_feature), - }, - ) diff --git a/tools/cpp/unix_cc_toolchain_config.bzl b/tools/cpp/unix_cc_toolchain_config.bzl deleted file mode 100644 index d466eafc4074a0..00000000000000 --- a/tools/cpp/unix_cc_toolchain_config.bzl +++ /dev/null @@ -1,1939 +0,0 @@ -# Copyright 2019 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. - -"""A Starlark cc_toolchain configuration rule""" - -load("@bazel_tools//tools/build_defs/cc:action_names.bzl", "ACTION_NAMES") -load( - "@bazel_tools//tools/cpp:cc_toolchain_config_lib.bzl", - "action_config", - "artifact_name_pattern", - "env_entry", - "env_set", - "feature", - "feature_set", - "flag_group", - "flag_set", - "tool", - "tool_path", - "variable_with_value", - "with_feature_set", -) - -def _target_os_version(ctx): - platform_type = ctx.fragments.apple.single_arch_platform.platform_type - xcode_config = ctx.attr._xcode_config[apple_common.XcodeVersionConfig] - return xcode_config.minimum_os_for_platform_type(platform_type) - -def layering_check_features(compiler, extra_flags_per_feature, is_macos): - if compiler != "clang": - return [] - return [ - feature( - name = "use_module_maps", - requires = [feature_set(features = ["module_maps"])], - flag_sets = [ - flag_set( - actions = [ - ACTION_NAMES.c_compile, - ACTION_NAMES.cpp_compile, - ACTION_NAMES.cpp_header_parsing, - ACTION_NAMES.cpp_module_compile, - ], - flag_groups = [ - flag_group( - # macOS requires -Xclang because of a bug in Apple Clang - flags = (["-Xclang"] if is_macos else []) + [ - "-fmodule-name=%{module_name}", - ] + (["-Xclang"] if is_macos else []) + [ - "-fmodule-map-file=%{module_map_file}", - ] + extra_flags_per_feature.get("use_module_maps", []), - ), - ], - ), - ], - ), - - # Tell blaze we support module maps in general, so they will be generated - # for all c/c++ rules. - # Note: not all C++ rules support module maps; thus, do not imply this - # feature from other features - instead, require it. - feature(name = "module_maps", enabled = True), - feature( - name = "layering_check", - implies = ["use_module_maps"], - flag_sets = [ - flag_set( - actions = [ - ACTION_NAMES.c_compile, - ACTION_NAMES.cpp_compile, - ACTION_NAMES.cpp_header_parsing, - ACTION_NAMES.cpp_module_compile, - ], - flag_groups = [ - flag_group(flags = [ - "-fmodules-strict-decluse", - "-Wprivate-header", - ]), - flag_group( - iterate_over = "dependent_module_map_files", - flags = (["-Xclang"] if is_macos else []) + [ - "-fmodule-map-file=%{dependent_module_map_files}", - ], - ), - ], - ), - ], - ), - ] - -def parse_headers_support(parse_headers_tool_path): - if not parse_headers_tool_path: - return [], [] - action_configs = [ - action_config( - action_name = ACTION_NAMES.cpp_header_parsing, - tools = [ - tool(path = parse_headers_tool_path), - ], - flag_sets = [ - flag_set( - flag_groups = [ - flag_group( - flags = [ - # Note: This treats all headers as C++ headers, which may lead to - # parsing failures for C headers that are not valid C++. - # For such headers, use features = ["-parse_headers"] to selectively - # disable parsing. - "-xc++-header", - "-fsyntax-only", - ], - ), - ], - ), - ], - implies = [ - # Copied from the legacy feature definition in CppActionConfigs.java. - "legacy_compile_flags", - "user_compile_flags", - "sysroot", - "unfiltered_compile_flags", - "compiler_input_flags", - "compiler_output_flags", - ], - ), - ] - features = [ - feature(name = "parse_headers"), - ] - return action_configs, features - -all_compile_actions = [ - ACTION_NAMES.c_compile, - ACTION_NAMES.cpp_compile, - ACTION_NAMES.linkstamp_compile, - ACTION_NAMES.assemble, - ACTION_NAMES.preprocess_assemble, - ACTION_NAMES.cpp_header_parsing, - ACTION_NAMES.cpp_module_compile, - ACTION_NAMES.cpp_module_codegen, - ACTION_NAMES.cpp_module_deps_scanning, - ACTION_NAMES.cpp20_module_compile, - ACTION_NAMES.cpp20_module_codegen, - ACTION_NAMES.clif_match, - ACTION_NAMES.lto_backend, -] - -all_cpp_compile_actions = [ - ACTION_NAMES.cpp_compile, - ACTION_NAMES.linkstamp_compile, - ACTION_NAMES.cpp_header_parsing, - ACTION_NAMES.cpp_module_compile, - ACTION_NAMES.cpp_module_codegen, - ACTION_NAMES.cpp_module_deps_scanning, - ACTION_NAMES.cpp20_module_compile, - ACTION_NAMES.cpp20_module_codegen, - ACTION_NAMES.clif_match, -] - -preprocessor_compile_actions = [ - ACTION_NAMES.c_compile, - ACTION_NAMES.cpp_compile, - ACTION_NAMES.linkstamp_compile, - ACTION_NAMES.preprocess_assemble, - ACTION_NAMES.cpp_header_parsing, - ACTION_NAMES.cpp_module_compile, - ACTION_NAMES.cpp_module_deps_scanning, - ACTION_NAMES.cpp20_module_compile, - ACTION_NAMES.clif_match, -] - -codegen_compile_actions = [ - ACTION_NAMES.c_compile, - ACTION_NAMES.cpp_compile, - ACTION_NAMES.linkstamp_compile, - ACTION_NAMES.assemble, - ACTION_NAMES.preprocess_assemble, - ACTION_NAMES.cpp_module_codegen, - ACTION_NAMES.cpp20_module_codegen, - ACTION_NAMES.lto_backend, -] - -all_link_actions = [ - ACTION_NAMES.cpp_link_executable, - ACTION_NAMES.cpp_link_dynamic_library, - ACTION_NAMES.cpp_link_nodeps_dynamic_library, -] - -lto_index_actions = [ - ACTION_NAMES.lto_index_for_executable, - ACTION_NAMES.lto_index_for_dynamic_library, - ACTION_NAMES.lto_index_for_nodeps_dynamic_library, -] - -def _sanitizer_feature(name = "", specific_compile_flags = [], specific_link_flags = []): - return feature( - name = name, - flag_sets = [ - flag_set( - actions = all_compile_actions, - flag_groups = [ - flag_group(flags = [ - "-fno-omit-frame-pointer", - "-fno-sanitize-recover=all", - ] + specific_compile_flags), - ], - with_features = [ - with_feature_set(features = [name]), - ], - ), - flag_set( - actions = all_link_actions, - flag_groups = [ - flag_group(flags = specific_link_flags), - ], - with_features = [ - with_feature_set(features = [name]), - ], - ), - ], - ) - -def _impl(ctx): - is_linux = ctx.attr.target_libc != "macosx" - - tool_paths = [ - tool_path(name = name, path = path) - for name, path in ctx.attr.tool_paths.items() - ] - action_configs = [] - - llvm_cov = ctx.attr.tool_paths.get("llvm-cov") - if llvm_cov: - llvm_cov_action = action_config( - action_name = ACTION_NAMES.llvm_cov, - tools = [ - tool( - path = llvm_cov, - ), - ], - ) - action_configs.append(llvm_cov_action) - - objcopy = ctx.attr.tool_paths.get("objcopy") - if objcopy: - objcopy_action = action_config( - action_name = ACTION_NAMES.objcopy_embed_data, - tools = [ - tool( - path = objcopy, - ), - ], - ) - action_configs.append(objcopy_action) - - validate_static_library = ctx.attr.tool_paths.get("validate_static_library") - if validate_static_library: - validate_static_library_action = action_config( - action_name = ACTION_NAMES.validate_static_library, - tools = [ - tool( - path = validate_static_library, - ), - ], - ) - action_configs.append(validate_static_library_action) - - symbol_check = feature( - name = "symbol_check", - implies = [ACTION_NAMES.validate_static_library], - ) - else: - symbol_check = None - - deps_scanner = "cpp-module-deps-scanner_not_found" - if "cpp-module-deps-scanner" in ctx.attr.tool_paths: - deps_scanner = ctx.attr.tool_paths["cpp-module-deps-scanner"] - cc = ctx.attr.tool_paths.get("gcc") - compile_implies = [ - # keep same with c++-compile - "legacy_compile_flags", - "user_compile_flags", - "sysroot", - "unfiltered_compile_flags", - "compiler_input_flags", - "compiler_output_flags", - ] - cpp_module_scan_deps = action_config( - action_name = ACTION_NAMES.cpp_module_deps_scanning, - tools = [ - tool( - path = deps_scanner, - ), - ], - implies = compile_implies, - ) - action_configs.append(cpp_module_scan_deps) - - cpp20_module_compile = action_config( - action_name = ACTION_NAMES.cpp20_module_compile, - tools = [ - tool( - path = cc, - ), - ], - flag_sets = [ - flag_set( - flag_groups = [ - flag_group( - flags = [ - "-x", - "c++-module" if ctx.attr.compiler == "clang" else "c++", - ], - ), - ], - ), - ], - implies = compile_implies, - ) - action_configs.append(cpp20_module_compile) - - cpp20_module_codegen = action_config( - action_name = ACTION_NAMES.cpp20_module_codegen, - tools = [ - tool( - path = cc, - ), - ], - implies = compile_implies, - ) - action_configs.append(cpp20_module_codegen) - - supports_pic_feature = feature( - name = "supports_pic", - enabled = True, - ) - supports_start_end_lib_feature = feature( - name = "supports_start_end_lib", - enabled = True, - ) - - gcc_quoting_for_param_files_feature = feature( - name = "gcc_quoting_for_param_files", - enabled = True, - ) - - static_link_cpp_runtimes_feature = feature( - name = "static_link_cpp_runtimes", - enabled = False, - ) - - default_compile_flags_feature = feature( - name = "default_compile_flags", - enabled = True, - flag_sets = [ - flag_set( - actions = all_compile_actions, - flag_groups = [ - flag_group( - # Security hardening requires optimization. - # We need to undef it as some distributions now have it enabled by default. - flags = ["-U_FORTIFY_SOURCE"], - ), - ], - with_features = [ - with_feature_set( - not_features = ["thin_lto"], - ), - ], - ), - flag_set( - actions = all_compile_actions, - flag_groups = ([ - flag_group( - flags = ctx.attr.compile_flags, - ), - ] if ctx.attr.compile_flags else []), - ), - flag_set( - actions = all_compile_actions, - flag_groups = ([ - flag_group( - flags = ctx.attr.dbg_compile_flags, - ), - ] if ctx.attr.dbg_compile_flags else []), - with_features = [with_feature_set(features = ["dbg"])], - ), - flag_set( - actions = all_compile_actions, - flag_groups = ([ - flag_group( - flags = ctx.attr.opt_compile_flags, - ), - ] if ctx.attr.opt_compile_flags else []), - with_features = [with_feature_set(features = ["opt"])], - ), - flag_set( - actions = [ACTION_NAMES.c_compile], - flag_groups = ([ - flag_group( - flags = ctx.attr.conly_flags, - ), - ] if ctx.attr.conly_flags else []), - ), - flag_set( - actions = all_cpp_compile_actions + [ACTION_NAMES.lto_backend], - flag_groups = ([ - flag_group( - flags = ctx.attr.cxx_flags, - ), - ] if ctx.attr.cxx_flags else []), - ), - ], - ) - - default_link_flags_feature = feature( - name = "default_link_flags", - enabled = True, - flag_sets = [ - flag_set( - actions = all_link_actions + lto_index_actions, - flag_groups = ([ - flag_group( - flags = ctx.attr.link_flags, - ), - ] if ctx.attr.link_flags else []), - ), - flag_set( - actions = all_link_actions + lto_index_actions, - flag_groups = ([ - flag_group( - flags = ctx.attr.opt_link_flags, - ), - ] if ctx.attr.opt_link_flags else []), - with_features = [with_feature_set(features = ["opt"])], - ), - ], - env_sets = [ - env_set( - actions = all_link_actions + lto_index_actions + [ACTION_NAMES.cpp_link_static_library], - env_entries = ([ - env_entry( - # Required for hermetic links on macOS - key = "ZERO_AR_DATE", - value = "1", - ), - ]), - ), - ], - ) - - dbg_feature = feature(name = "dbg") - - opt_feature = feature(name = "opt") - - sysroot_feature = feature( - name = "sysroot", - enabled = True, - flag_sets = [ - flag_set( - actions = [ - ACTION_NAMES.preprocess_assemble, - ACTION_NAMES.linkstamp_compile, - ACTION_NAMES.c_compile, - ACTION_NAMES.cpp_compile, - ACTION_NAMES.cpp_header_parsing, - ACTION_NAMES.cpp_module_compile, - ACTION_NAMES.cpp_module_codegen, - ACTION_NAMES.cpp_module_deps_scanning, - ACTION_NAMES.cpp20_module_compile, - ACTION_NAMES.cpp20_module_codegen, - ACTION_NAMES.lto_backend, - ACTION_NAMES.clif_match, - ] + all_link_actions + lto_index_actions, - flag_groups = [ - flag_group( - flags = ["--sysroot=%{sysroot}"], - expand_if_available = "sysroot", - ), - ], - ), - ], - ) - - compiler_input_flags_feature = feature( - name = "compiler_input_flags", - enabled = True, - flag_sets = [ - flag_set( - actions = [ - ACTION_NAMES.assemble, - ACTION_NAMES.preprocess_assemble, - ACTION_NAMES.linkstamp_compile, - ACTION_NAMES.c_compile, - ACTION_NAMES.cpp_compile, - ACTION_NAMES.cpp_header_parsing, - ACTION_NAMES.cpp_module_compile, - ACTION_NAMES.cpp_module_codegen, - ACTION_NAMES.cpp_module_deps_scanning, - ACTION_NAMES.cpp20_module_compile, - ACTION_NAMES.cpp20_module_codegen, - ACTION_NAMES.objc_compile, - ACTION_NAMES.objcpp_compile, - ACTION_NAMES.lto_backend, - ], - flag_groups = [ - flag_group( - flags = ["-c", "%{source_file}"], - expand_if_available = "source_file", - ), - ], - ), - ], - ) - - compiler_output_flags_feature = feature( - name = "compiler_output_flags", - enabled = True, - flag_sets = [ - flag_set( - actions = [ - ACTION_NAMES.assemble, - ACTION_NAMES.preprocess_assemble, - ACTION_NAMES.linkstamp_compile, - ACTION_NAMES.c_compile, - ACTION_NAMES.cpp_compile, - ACTION_NAMES.cpp_header_parsing, - ACTION_NAMES.cpp_module_compile, - ACTION_NAMES.cpp_module_codegen, - ACTION_NAMES.cpp_module_deps_scanning, - ACTION_NAMES.cpp20_module_compile, - ACTION_NAMES.cpp20_module_codegen, - ACTION_NAMES.objc_compile, - ACTION_NAMES.objcpp_compile, - ACTION_NAMES.lto_backend, - ], - flag_groups = [ - flag_group( - flags = ["-S"], - expand_if_available = "output_assembly_file", - ), - flag_group( - flags = ["-E"], - expand_if_available = "output_preprocess_file", - ), - flag_group( - flags = ["-o", "%{output_file}"], - expand_if_available = "output_file", - ), - ], - ), - ], - ) - - fdo_optimize_feature = feature( - name = "fdo_optimize", - flag_sets = [ - flag_set( - actions = [ACTION_NAMES.c_compile, ACTION_NAMES.cpp_compile], - flag_groups = [ - flag_group( - flags = [ - "-fprofile-use=%{fdo_profile_path}", - "-fprofile-correction", - ], - expand_if_available = "fdo_profile_path", - ), - ], - ), - ], - provides = ["profile"], - ) - - supports_dynamic_linker_feature = feature(name = "supports_dynamic_linker", enabled = True) - - user_compile_flags_feature = feature( - name = "user_compile_flags", - enabled = True, - flag_sets = [ - flag_set( - actions = all_compile_actions, - flag_groups = [ - flag_group( - flags = ["%{user_compile_flags}"], - iterate_over = "user_compile_flags", - expand_if_available = "user_compile_flags", - ), - ], - ), - ], - ) - - unfiltered_compile_flags_feature = feature( - name = "unfiltered_compile_flags", - enabled = True, - flag_sets = [ - flag_set( - actions = all_compile_actions, - flag_groups = ([ - flag_group( - flags = ctx.attr.unfiltered_compile_flags, - ), - ] if ctx.attr.unfiltered_compile_flags else []), - ), - ], - ) - - library_search_directories_feature = feature( - name = "library_search_directories", - flag_sets = [ - flag_set( - actions = all_link_actions + lto_index_actions, - flag_groups = [ - flag_group( - flags = ["-L%{library_search_directories}"], - iterate_over = "library_search_directories", - expand_if_available = "library_search_directories", - ), - ], - ), - ], - ) - - static_libgcc_feature = feature( - name = "static_libgcc", - enabled = True, - flag_sets = [ - flag_set( - actions = [ - ACTION_NAMES.cpp_link_executable, - ACTION_NAMES.cpp_link_dynamic_library, - ACTION_NAMES.lto_index_for_executable, - ACTION_NAMES.lto_index_for_dynamic_library, - ], - flag_groups = [flag_group(flags = ["-static-libgcc"])], - with_features = [ - with_feature_set(features = ["static_link_cpp_runtimes"]), - ], - ), - ], - ) - - pic_feature = feature( - name = "pic", - enabled = True, - flag_sets = [ - flag_set( - actions = [ - ACTION_NAMES.assemble, - ACTION_NAMES.preprocess_assemble, - ACTION_NAMES.linkstamp_compile, - ACTION_NAMES.c_compile, - ACTION_NAMES.cpp_compile, - ACTION_NAMES.cpp_module_codegen, - ACTION_NAMES.cpp_module_compile, - ACTION_NAMES.cpp20_module_compile, - ACTION_NAMES.cpp20_module_codegen, - ], - flag_groups = [ - flag_group(flags = ["-fPIC"], expand_if_available = "pic"), - ], - ), - ], - ) - - per_object_debug_info_feature = feature( - name = "per_object_debug_info", - enabled = True, - flag_sets = [ - flag_set( - actions = [ - ACTION_NAMES.assemble, - ACTION_NAMES.preprocess_assemble, - ACTION_NAMES.c_compile, - ACTION_NAMES.cpp_compile, - ACTION_NAMES.cpp_module_codegen, - ACTION_NAMES.cpp20_module_codegen, - ], - flag_groups = [ - flag_group( - flags = ["-gsplit-dwarf", "-g"], - expand_if_available = "per_object_debug_info_file", - ), - ], - ), - ], - ) - - preprocessor_defines_feature = feature( - name = "preprocessor_defines", - enabled = True, - flag_sets = [ - flag_set( - actions = [ - ACTION_NAMES.preprocess_assemble, - ACTION_NAMES.linkstamp_compile, - ACTION_NAMES.c_compile, - ACTION_NAMES.cpp_compile, - ACTION_NAMES.cpp_header_parsing, - ACTION_NAMES.cpp_module_compile, - ACTION_NAMES.cpp_module_deps_scanning, - ACTION_NAMES.cpp20_module_compile, - ACTION_NAMES.cpp20_module_codegen, - ACTION_NAMES.clif_match, - ], - flag_groups = [ - flag_group( - flags = ["-D%{preprocessor_defines}"], - iterate_over = "preprocessor_defines", - ), - ], - ), - ], - ) - - cs_fdo_optimize_feature = feature( - name = "cs_fdo_optimize", - flag_sets = [ - flag_set( - actions = [ACTION_NAMES.lto_backend], - flag_groups = [ - flag_group( - flags = [ - "-fprofile-use=%{fdo_profile_path}", - "-Wno-profile-instr-unprofiled", - "-Wno-profile-instr-out-of-date", - "-fprofile-correction", - ], - expand_if_available = "fdo_profile_path", - ), - ], - ), - ], - provides = ["csprofile"], - ) - - autofdo_feature = feature( - name = "autofdo", - flag_sets = [ - flag_set( - actions = [ACTION_NAMES.c_compile, ACTION_NAMES.cpp_compile], - flag_groups = [ - flag_group( - flags = [ - "-fauto-profile=%{fdo_profile_path}", - "-fprofile-correction", - ], - expand_if_available = "fdo_profile_path", - ), - ], - ), - ], - provides = ["profile"], - ) - - if is_linux: - runtime_library_search_directories_feature = feature( - name = "runtime_library_search_directories", - flag_sets = [ - flag_set( - actions = all_link_actions + lto_index_actions, - flag_groups = [ - flag_group( - iterate_over = "runtime_library_search_directories", - flag_groups = [ - flag_group( - flags = [ - "-Xlinker", - "-rpath", - "-Xlinker", - "$EXEC_ORIGIN/%{runtime_library_search_directories}", - ], - expand_if_true = "is_cc_test", - ), - flag_group( - flags = [ - "-Xlinker", - "-rpath", - "-Xlinker", - "$ORIGIN/%{runtime_library_search_directories}", - ], - expand_if_false = "is_cc_test", - ), - ], - expand_if_available = - "runtime_library_search_directories", - ), - ], - with_features = [ - with_feature_set(features = ["static_link_cpp_runtimes"]), - ], - ), - flag_set( - actions = all_link_actions + lto_index_actions, - flag_groups = [ - flag_group( - iterate_over = "runtime_library_search_directories", - flag_groups = [ - flag_group( - flags = [ - "-Xlinker", - "-rpath", - "-Xlinker", - "$ORIGIN/%{runtime_library_search_directories}", - ], - ), - ], - expand_if_available = - "runtime_library_search_directories", - ), - ], - with_features = [ - with_feature_set( - not_features = ["static_link_cpp_runtimes"], - ), - ], - ), - ], - ) - set_install_name_feature = feature( - name = "set_soname", - flag_sets = [ - flag_set( - actions = [ - ACTION_NAMES.cpp_link_dynamic_library, - ACTION_NAMES.cpp_link_nodeps_dynamic_library, - ], - flag_groups = [ - flag_group( - flags = [ - "-Wl,-soname,%{runtime_solib_name}", - ], - expand_if_available = "runtime_solib_name", - ), - ], - ), - ], - ) - else: - runtime_library_search_directories_feature = feature( - name = "runtime_library_search_directories", - flag_sets = [ - flag_set( - actions = all_link_actions + lto_index_actions, - flag_groups = [ - flag_group( - iterate_over = "runtime_library_search_directories", - flag_groups = [ - flag_group( - flags = [ - "-Xlinker", - "-rpath", - "-Xlinker", - "@loader_path/%{runtime_library_search_directories}", - ], - ), - ], - expand_if_available = "runtime_library_search_directories", - ), - ], - ), - ], - ) - set_install_name_feature = feature( - name = "set_install_name", - enabled = ctx.fragments.cpp.do_not_use_macos_set_install_name, - flag_sets = [ - flag_set( - actions = [ - ACTION_NAMES.cpp_link_dynamic_library, - ACTION_NAMES.cpp_link_nodeps_dynamic_library, - ], - flag_groups = [ - flag_group( - flags = [ - "-Wl,-install_name,@rpath/%{runtime_solib_name}", - ], - expand_if_available = "runtime_solib_name", - ), - ], - ), - ], - ) - - fission_support_feature = feature( - name = "fission_support", - flag_sets = [ - flag_set( - actions = all_link_actions + lto_index_actions, - flag_groups = [ - flag_group( - flags = ["-Wl,--gdb-index"], - expand_if_available = "is_using_fission", - ), - ], - ), - ], - ) - - shared_flag_feature = feature( - name = "shared_flag", - flag_sets = [ - flag_set( - actions = [ - ACTION_NAMES.cpp_link_dynamic_library, - ACTION_NAMES.cpp_link_nodeps_dynamic_library, - ACTION_NAMES.lto_index_for_dynamic_library, - ACTION_NAMES.lto_index_for_nodeps_dynamic_library, - ], - flag_groups = [flag_group(flags = ["-shared"])], - ), - ], - ) - - random_seed_feature = feature( - name = "random_seed", - enabled = True, - flag_sets = [ - flag_set( - actions = [ - ACTION_NAMES.c_compile, - ACTION_NAMES.cpp_compile, - ACTION_NAMES.cpp_module_codegen, - ACTION_NAMES.cpp_module_compile, - ACTION_NAMES.cpp_module_deps_scanning, - ACTION_NAMES.cpp20_module_compile, - ACTION_NAMES.cpp20_module_codegen, - ], - flag_groups = [ - flag_group( - flags = ["-frandom-seed=%{output_file}"], - expand_if_available = "output_file", - ), - ], - ), - ], - ) - - includes_feature = feature( - name = "includes", - enabled = True, - flag_sets = [ - flag_set( - actions = [ - ACTION_NAMES.preprocess_assemble, - ACTION_NAMES.linkstamp_compile, - ACTION_NAMES.c_compile, - ACTION_NAMES.cpp_compile, - ACTION_NAMES.cpp_header_parsing, - ACTION_NAMES.cpp_module_compile, - ACTION_NAMES.cpp_module_deps_scanning, - ACTION_NAMES.cpp20_module_compile, - ACTION_NAMES.clif_match, - ACTION_NAMES.objc_compile, - ACTION_NAMES.objcpp_compile, - ], - flag_groups = [ - flag_group( - flags = ["-include", "%{includes}"], - iterate_over = "includes", - expand_if_available = "includes", - ), - ], - ), - ], - ) - - fdo_instrument_feature = feature( - name = "fdo_instrument", - flag_sets = [ - flag_set( - actions = [ - ACTION_NAMES.c_compile, - ACTION_NAMES.cpp_compile, - ] + all_link_actions + lto_index_actions, - flag_groups = [ - flag_group( - flags = [ - "-fprofile-generate=%{fdo_instrument_path}", - "-fno-data-sections", - ], - expand_if_available = "fdo_instrument_path", - ), - ], - ), - ], - provides = ["profile"], - ) - - cs_fdo_instrument_feature = feature( - name = "cs_fdo_instrument", - flag_sets = [ - flag_set( - actions = [ - ACTION_NAMES.c_compile, - ACTION_NAMES.cpp_compile, - ACTION_NAMES.lto_backend, - ] + all_link_actions + lto_index_actions, - flag_groups = [ - flag_group( - flags = [ - "-fcs-profile-generate=%{cs_fdo_instrument_path}", - ], - expand_if_available = "cs_fdo_instrument_path", - ), - ], - ), - ], - provides = ["csprofile"], - ) - - include_paths_feature = feature( - name = "include_paths", - enabled = True, - flag_sets = [ - flag_set( - actions = [ - ACTION_NAMES.preprocess_assemble, - ACTION_NAMES.linkstamp_compile, - ACTION_NAMES.c_compile, - ACTION_NAMES.cpp_compile, - ACTION_NAMES.cpp_header_parsing, - ACTION_NAMES.cpp_module_compile, - ACTION_NAMES.cpp_module_deps_scanning, - ACTION_NAMES.cpp20_module_compile, - ACTION_NAMES.clif_match, - ACTION_NAMES.objc_compile, - ACTION_NAMES.objcpp_compile, - ], - flag_groups = [ - flag_group( - flags = ["-iquote", "%{quote_include_paths}"], - iterate_over = "quote_include_paths", - ), - flag_group( - flags = ["-I%{include_paths}"], - iterate_over = "include_paths", - ), - flag_group( - flags = ["-isystem", "%{system_include_paths}"], - iterate_over = "system_include_paths", - ), - ], - ), - ], - ) - - external_include_paths_feature = feature( - name = "external_include_paths", - flag_sets = [ - flag_set( - actions = [ - ACTION_NAMES.preprocess_assemble, - ACTION_NAMES.linkstamp_compile, - ACTION_NAMES.c_compile, - ACTION_NAMES.cpp_compile, - ACTION_NAMES.cpp_header_parsing, - ACTION_NAMES.cpp_module_compile, - ACTION_NAMES.cpp_module_deps_scanning, - ACTION_NAMES.cpp20_module_compile, - ACTION_NAMES.cpp20_module_codegen, - ACTION_NAMES.clif_match, - ACTION_NAMES.objc_compile, - ACTION_NAMES.objcpp_compile, - ], - flag_groups = [ - flag_group( - flags = ["-isystem", "%{external_include_paths}"], - iterate_over = "external_include_paths", - expand_if_available = "external_include_paths", - ), - ], - ), - ], - ) - - strip_debug_symbols_feature = feature( - name = "strip_debug_symbols", - flag_sets = [ - flag_set( - actions = all_link_actions + lto_index_actions, - flag_groups = [ - flag_group( - flags = ["-Wl,-S"], - expand_if_available = "strip_debug_symbols", - ), - ], - ), - ], - ) - - build_interface_libraries_feature = feature( - name = "build_interface_libraries", - flag_sets = [ - flag_set( - actions = [ - ACTION_NAMES.cpp_link_dynamic_library, - ACTION_NAMES.cpp_link_nodeps_dynamic_library, - ACTION_NAMES.lto_index_for_dynamic_library, - ACTION_NAMES.lto_index_for_nodeps_dynamic_library, - ], - flag_groups = [ - flag_group( - flags = [ - "%{generate_interface_library}", - "%{interface_library_builder_path}", - "%{interface_library_input_path}", - "%{interface_library_output_path}", - ], - expand_if_available = "generate_interface_library", - ), - ], - with_features = [ - with_feature_set( - features = ["supports_interface_shared_libraries"], - ), - ], - ), - ], - ) - - libraries_to_link_common_flag_groups = [ - flag_group( - flags = ["-Wl,-whole-archive"], - expand_if_true = - "libraries_to_link.is_whole_archive", - expand_if_equal = variable_with_value( - name = "libraries_to_link.type", - value = "static_library", - ), - ), - flag_group( - flags = ["%{libraries_to_link.object_files}"], - iterate_over = "libraries_to_link.object_files", - expand_if_equal = variable_with_value( - name = "libraries_to_link.type", - value = "object_file_group", - ), - ), - flag_group( - flags = ["%{libraries_to_link.name}"], - expand_if_equal = variable_with_value( - name = "libraries_to_link.type", - value = "object_file", - ), - ), - flag_group( - flags = ["%{libraries_to_link.name}"], - expand_if_equal = variable_with_value( - name = "libraries_to_link.type", - value = "interface_library", - ), - ), - flag_group( - flags = ["%{libraries_to_link.name}"], - expand_if_equal = variable_with_value( - name = "libraries_to_link.type", - value = "static_library", - ), - ), - flag_group( - flags = ["-l%{libraries_to_link.name}"], - expand_if_equal = variable_with_value( - name = "libraries_to_link.type", - value = "dynamic_library", - ), - ), - flag_group( - flags = ["-l:%{libraries_to_link.name}"], - expand_if_equal = variable_with_value( - name = "libraries_to_link.type", - value = "versioned_dynamic_library", - ), - ), - flag_group( - flags = ["-Wl,-no-whole-archive"], - expand_if_true = "libraries_to_link.is_whole_archive", - expand_if_equal = variable_with_value( - name = "libraries_to_link.type", - value = "static_library", - ), - ), - ] - - libraries_to_link_feature = feature( - name = "libraries_to_link", - flag_sets = [ - flag_set( - actions = [ - ACTION_NAMES.cpp_link_executable, - ACTION_NAMES.cpp_link_dynamic_library, - ] + lto_index_actions, - flag_groups = [ - flag_group( - iterate_over = "libraries_to_link", - flag_groups = [ - flag_group( - flags = ["-Wl,--start-lib"], - expand_if_equal = variable_with_value( - name = "libraries_to_link.type", - value = "object_file_group", - ), - ), - ] + libraries_to_link_common_flag_groups + [ - flag_group( - flags = ["-Wl,--end-lib"], - expand_if_equal = variable_with_value( - name = "libraries_to_link.type", - value = "object_file_group", - ), - ), - ], - expand_if_available = "libraries_to_link", - ), - flag_group( - flags = ["-Wl,@%{thinlto_param_file}"], - expand_if_true = "thinlto_param_file", - ), - ], - ), - # Object file groups may contain symbols that aren't referenced in the same target that - # produces the object files and must thus not be wrapped in --start-lib/--end-lib when - # linking a nodeps dynamic library. - flag_set( - actions = [ACTION_NAMES.cpp_link_nodeps_dynamic_library], - flag_groups = [ - flag_group( - iterate_over = "libraries_to_link", - flag_groups = libraries_to_link_common_flag_groups, - ), - flag_group( - flags = ["-Wl,@%{thinlto_param_file}"], - expand_if_true = "thinlto_param_file", - ), - ], - ), - ], - ) - - user_link_flags_feature = feature( - name = "user_link_flags", - flag_sets = [ - flag_set( - actions = all_link_actions + lto_index_actions, - flag_groups = [ - flag_group( - flags = ["%{user_link_flags}"], - iterate_over = "user_link_flags", - expand_if_available = "user_link_flags", - ), - ], - ), - ], - ) - - default_link_libs_feature = feature( - name = "default_link_libs", - enabled = True, - flag_sets = [ - flag_set( - actions = all_link_actions + lto_index_actions, - flag_groups = [flag_group(flags = ctx.attr.link_libs)] if ctx.attr.link_libs else [], - ), - ], - ) - - fdo_prefetch_hints_feature = feature( - name = "fdo_prefetch_hints", - flag_sets = [ - flag_set( - actions = [ - ACTION_NAMES.c_compile, - ACTION_NAMES.cpp_compile, - ACTION_NAMES.lto_backend, - ], - flag_groups = [ - flag_group( - flags = [ - "-mllvm", - "-prefetch-hints-file=%{fdo_prefetch_hints_path}", - ], - expand_if_available = "fdo_prefetch_hints_path", - ), - ], - ), - ], - ) - - linkstamps_feature = feature( - name = "linkstamps", - flag_sets = [ - flag_set( - actions = all_link_actions + lto_index_actions, - flag_groups = [ - flag_group( - flags = ["%{linkstamp_paths}"], - iterate_over = "linkstamp_paths", - expand_if_available = "linkstamp_paths", - ), - ], - ), - ], - ) - - libtool_feature = feature( - name = "libtool", - enabled = not is_linux, - ) - - archiver_flags_feature = feature( - name = "archiver_flags", - flag_sets = [ - flag_set( - actions = [ACTION_NAMES.cpp_link_static_library], - flag_groups = [ - flag_group( - flags = [ - "rcsD" if is_linux else "rcs", - "%{output_execpath}", - ], - expand_if_available = "output_execpath", - ), - ], - with_features = [ - with_feature_set( - not_features = ["libtool"], - ), - ], - ), - flag_set( - actions = [ACTION_NAMES.cpp_link_static_library], - flag_groups = [ - flag_group( - flags = [ - "-static", - "-o", - "%{output_execpath}", - ], - expand_if_available = "output_execpath", - ), - ], - with_features = [ - with_feature_set( - features = ["libtool"], - ), - ], - ), - flag_set( - actions = [ACTION_NAMES.cpp_link_static_library], - flag_groups = [ - flag_group( - iterate_over = "libraries_to_link", - flag_groups = [ - flag_group( - flags = ["%{libraries_to_link.name}"], - expand_if_equal = variable_with_value( - name = "libraries_to_link.type", - value = "object_file", - ), - ), - flag_group( - flags = ["%{libraries_to_link.object_files}"], - iterate_over = "libraries_to_link.object_files", - expand_if_equal = variable_with_value( - name = "libraries_to_link.type", - value = "object_file_group", - ), - ), - ], - expand_if_available = "libraries_to_link", - ), - ], - ), - flag_set( - actions = [ACTION_NAMES.cpp_link_static_library], - flag_groups = ([ - flag_group( - flags = ctx.attr.archive_flags, - ), - ] if ctx.attr.archive_flags else []), - ), - flag_set( - actions = [ACTION_NAMES.cpp_link_static_library], - flag_groups = [ - flag_group( - flags = ["%{user_archiver_flags}"], - iterate_over = "user_archiver_flags", - expand_if_available = "user_archiver_flags", - ), - ], - ), - ], - ) - - force_pic_flags_feature = feature( - name = "force_pic_flags", - flag_sets = [ - flag_set( - actions = [ - ACTION_NAMES.cpp_link_executable, - ACTION_NAMES.lto_index_for_executable, - ], - flag_groups = [ - flag_group( - flags = ["-pie"], - expand_if_available = "force_pic", - ), - ], - ), - ], - ) - - dependency_file_feature = feature( - name = "dependency_file", - enabled = True, - flag_sets = [ - flag_set( - actions = [ - ACTION_NAMES.assemble, - ACTION_NAMES.preprocess_assemble, - ACTION_NAMES.c_compile, - ACTION_NAMES.cpp_compile, - ACTION_NAMES.cpp_module_compile, - ACTION_NAMES.objc_compile, - ACTION_NAMES.objcpp_compile, - ACTION_NAMES.cpp_header_parsing, - ACTION_NAMES.cpp_module_deps_scanning, - ACTION_NAMES.cpp20_module_compile, - ACTION_NAMES.clif_match, - ], - flag_groups = [ - flag_group( - flags = ["-MD", "-MF", "%{dependency_file}"], - expand_if_available = "dependency_file", - ), - ], - ), - ], - ) - - serialized_diagnostics_file_feature = feature( - name = "serialized_diagnostics_file", - flag_sets = [ - flag_set( - actions = [ - ACTION_NAMES.assemble, - ACTION_NAMES.preprocess_assemble, - ACTION_NAMES.c_compile, - ACTION_NAMES.cpp_compile, - ACTION_NAMES.cpp_module_compile, - ACTION_NAMES.objc_compile, - ACTION_NAMES.objcpp_compile, - ACTION_NAMES.cpp_header_parsing, - ACTION_NAMES.cpp_module_deps_scanning, - ACTION_NAMES.clif_match, - ], - flag_groups = [ - flag_group( - flags = ["--serialize-diagnostics", "%{serialized_diagnostics_file}"], - expand_if_available = "serialized_diagnostics_file", - ), - ], - ), - ], - ) - - dynamic_library_linker_tool_feature = feature( - name = "dynamic_library_linker_tool", - flag_sets = [ - flag_set( - actions = [ - ACTION_NAMES.cpp_link_dynamic_library, - ACTION_NAMES.cpp_link_nodeps_dynamic_library, - ACTION_NAMES.lto_index_for_dynamic_library, - ACTION_NAMES.lto_index_for_nodeps_dynamic_library, - ], - flag_groups = [ - flag_group( - flags = [" + cppLinkDynamicLibraryToolPath + "], - expand_if_available = "generate_interface_library", - ), - ], - with_features = [ - with_feature_set( - features = ["supports_interface_shared_libraries"], - ), - ], - ), - ], - ) - - generate_linkmap_feature = feature( - name = "generate_linkmap", - flag_sets = [ - flag_set( - actions = [ - ACTION_NAMES.cpp_link_executable, - ], - flag_groups = [ - flag_group( - flags = [ - "-Wl,-Map=%{output_execpath}.map" if is_linux else "-Wl,-map,%{output_execpath}.map", - ], - expand_if_available = "output_execpath", - ), - ], - ), - ], - ) - - output_execpath_flags_feature = feature( - name = "output_execpath_flags", - flag_sets = [ - flag_set( - actions = all_link_actions + lto_index_actions, - flag_groups = [ - flag_group( - flags = ["-o", "%{output_execpath}"], - expand_if_available = "output_execpath", - ), - ], - ), - ], - ) - - # Note that we also set --coverage for c++-link-nodeps-dynamic-library. The - # generated code contains references to gcov symbols, and the dynamic linker - # can't resolve them unless the library is linked against gcov. - coverage_feature = feature( - name = "coverage", - provides = ["profile"], - flag_sets = [ - flag_set( - actions = [ - ACTION_NAMES.preprocess_assemble, - ACTION_NAMES.c_compile, - ACTION_NAMES.cpp_compile, - ACTION_NAMES.cpp_header_parsing, - ACTION_NAMES.cpp_module_compile, - ], - flag_groups = ([ - flag_group(flags = ctx.attr.coverage_compile_flags), - ] if ctx.attr.coverage_compile_flags else []), - ), - flag_set( - actions = all_link_actions + lto_index_actions, - flag_groups = ([ - flag_group(flags = ctx.attr.coverage_link_flags), - ] if ctx.attr.coverage_link_flags else []), - ), - ], - ) - - thinlto_feature = feature( - name = "thin_lto", - flag_sets = [ - flag_set( - actions = [ - ACTION_NAMES.c_compile, - ACTION_NAMES.cpp_compile, - ] + all_link_actions + lto_index_actions, - flag_groups = [ - flag_group(flags = ["-flto=thin"]), - flag_group( - expand_if_available = "lto_indexing_bitcode_file", - flags = [ - "-Xclang", - "-fthin-link-bitcode=%{lto_indexing_bitcode_file}", - ], - ), - ], - ), - flag_set( - actions = [ACTION_NAMES.linkstamp_compile], - flag_groups = [flag_group(flags = ["-DBUILD_LTO_TYPE=thin"])], - ), - flag_set( - actions = lto_index_actions, - flag_groups = [ - flag_group(flags = [ - "-flto=thin", - "-Wl,-plugin-opt,thinlto-index-only%{thinlto_optional_params_file}", - "-Wl,-plugin-opt,thinlto-emit-imports-files", - "-Wl,-plugin-opt,thinlto-prefix-replace=%{thinlto_prefix_replace}", - ]), - flag_group( - expand_if_available = "thinlto_object_suffix_replace", - flags = [ - "-Wl,-plugin-opt,thinlto-object-suffix-replace=%{thinlto_object_suffix_replace}", - ], - ), - flag_group( - expand_if_available = "thinlto_merged_object_file", - flags = [ - "-Wl,-plugin-opt,obj-path=%{thinlto_merged_object_file}", - ], - ), - ], - ), - flag_set( - actions = [ACTION_NAMES.lto_backend], - flag_groups = [ - flag_group(flags = [ - "-c", - "-fthinlto-index=%{thinlto_index}", - "-o", - "%{thinlto_output_object_file}", - "-x", - "ir", - "%{thinlto_input_bitcode_file}", - ]), - ], - ), - ], - ) - - treat_warnings_as_errors_feature = feature( - name = "treat_warnings_as_errors", - flag_sets = [ - flag_set( - actions = [ACTION_NAMES.c_compile, ACTION_NAMES.cpp_compile], - flag_groups = [flag_group(flags = ["-Werror"])], - ), - flag_set( - actions = all_link_actions, - flag_groups = [flag_group( - flags = ["-Wl,-fatal-warnings"] if is_linux else ["-Wl,-fatal_warnings"], - )], - ), - ], - ) - - archive_param_file_feature = feature( - name = "archive_param_file", - enabled = True, - ) - - asan_feature = _sanitizer_feature( - name = "asan", - specific_compile_flags = [ - "-fsanitize=address", - "-fno-common", - ], - specific_link_flags = [ - "-fsanitize=address", - ], - ) - - tsan_feature = _sanitizer_feature( - name = "tsan", - specific_compile_flags = [ - "-fsanitize=thread", - ], - specific_link_flags = [ - "-fsanitize=thread", - ], - ) - - ubsan_feature = _sanitizer_feature( - name = "ubsan", - specific_compile_flags = [ - "-fsanitize=undefined", - ], - specific_link_flags = [ - "-fsanitize=undefined", - ], - ) - - # If you have Xcode + the CLT installed the version defaults can be - # too old for some standard C apis such as thread locals - macos_minimum_os_feature = feature( - name = "macos_minimum_os", - enabled = True, - flag_sets = [ - flag_set( - actions = all_compile_actions + all_link_actions, - flag_groups = [flag_group(flags = ["-mmacosx-version-min={}".format(_target_os_version(ctx))])], - ), - ], - ) - - # Kept for backwards compatibility with the crosstool that moved. Without - # linking the objc runtime binaries don't link CoreFoundation for free, - # which breaks abseil. - macos_default_link_flags_feature = feature( - name = "macos_default_link_flags", - enabled = True, - flag_sets = [ - flag_set( - actions = all_link_actions, - flag_groups = [flag_group(flags = [ - "-no-canonical-prefixes", - "-fobjc-link-runtime", - ])], - ), - ], - ) - - # Tell bazel we support C++ modules now - cpp_modules_feature = feature( - name = "cpp_modules", - # set default value to False - # to enable the feature - # use --features=cpp_modules - # or add cpp_modules to features attr - enabled = False, - ) - - cpp_module_modmap_file_feature = feature( - name = "cpp_module_modmap_file", - flag_sets = [ - flag_set( - actions = [ - ACTION_NAMES.cpp_compile, - ACTION_NAMES.cpp20_module_compile, - ACTION_NAMES.cpp20_module_codegen, - ], - flag_groups = [ - flag_group( - flags = ["@%{cpp_module_modmap_file}" if ctx.attr.compiler == "clang" else "-fmodule-mapper=%{cpp_module_modmap_file}"], - expand_if_available = "cpp_module_modmap_file", - ), - ], - ), - ], - enabled = True, - ) - if ctx.attr.compiler == "clang": - flag_groups = [ - flag_group( - flags = ["-fmodule-output=%{cpp_module_output_file}"], - expand_if_available = "cpp_module_output_file", - ), - ] - else: - flag_groups = [] - cpp20_module_compile_flags_feature = feature( - name = "cpp20_module_compile_flags", - flag_sets = [ - flag_set( - actions = [ - ACTION_NAMES.cpp20_module_compile, - ], - flag_groups = flag_groups, - ), - ], - enabled = True, - ) - - # TODO(#8303): Mac crosstool should also declare every feature. - if is_linux: - # Linux artifact name patterns are the default. - artifact_name_patterns = [] - features = [ - cpp_modules_feature, - cpp_module_modmap_file_feature, - cpp20_module_compile_flags_feature, - dependency_file_feature, - serialized_diagnostics_file_feature, - random_seed_feature, - pic_feature, - per_object_debug_info_feature, - preprocessor_defines_feature, - includes_feature, - include_paths_feature, - external_include_paths_feature, - fdo_instrument_feature, - cs_fdo_instrument_feature, - cs_fdo_optimize_feature, - thinlto_feature, - fdo_prefetch_hints_feature, - autofdo_feature, - build_interface_libraries_feature, - dynamic_library_linker_tool_feature, - generate_linkmap_feature, - shared_flag_feature, - linkstamps_feature, - output_execpath_flags_feature, - runtime_library_search_directories_feature, - library_search_directories_feature, - libtool_feature, - archiver_flags_feature, - force_pic_flags_feature, - fission_support_feature, - strip_debug_symbols_feature, - coverage_feature, - supports_pic_feature, - asan_feature, - tsan_feature, - ubsan_feature, - gcc_quoting_for_param_files_feature, - static_link_cpp_runtimes_feature, - ] + ( - [ - supports_start_end_lib_feature, - ] if ctx.attr.supports_start_end_lib else [] - ) + [ - default_compile_flags_feature, - default_link_flags_feature, - libraries_to_link_feature, - user_link_flags_feature, - default_link_libs_feature, - static_libgcc_feature, - fdo_optimize_feature, - supports_dynamic_linker_feature, - dbg_feature, - opt_feature, - user_compile_flags_feature, - sysroot_feature, - compiler_input_flags_feature, - compiler_output_flags_feature, - unfiltered_compile_flags_feature, - treat_warnings_as_errors_feature, - archive_param_file_feature, - set_install_name_feature, - ] + layering_check_features(ctx.attr.compiler, ctx.attr.extra_flags_per_feature, is_macos = False) - else: - # macOS artifact name patterns differ from the defaults only for dynamic - # libraries. - artifact_name_patterns = [ - artifact_name_pattern( - category_name = "dynamic_library", - prefix = "lib", - extension = ".dylib", - ), - ] - features = [ - cpp_modules_feature, - cpp_module_modmap_file_feature, - cpp20_module_compile_flags_feature, - macos_minimum_os_feature, - macos_default_link_flags_feature, - dependency_file_feature, - runtime_library_search_directories_feature, - set_install_name_feature, - libtool_feature, - archiver_flags_feature, - asan_feature, - tsan_feature, - ubsan_feature, - gcc_quoting_for_param_files_feature, - static_link_cpp_runtimes_feature, - ] + ( - [ - supports_start_end_lib_feature, - ] if ctx.attr.supports_start_end_lib else [] - ) + [ - coverage_feature, - default_compile_flags_feature, - default_link_flags_feature, - user_link_flags_feature, - default_link_libs_feature, - external_include_paths_feature, - fdo_optimize_feature, - dbg_feature, - opt_feature, - user_compile_flags_feature, - sysroot_feature, - compiler_input_flags_feature, - compiler_output_flags_feature, - unfiltered_compile_flags_feature, - treat_warnings_as_errors_feature, - archive_param_file_feature, - generate_linkmap_feature, - ] + layering_check_features(ctx.attr.compiler, ctx.attr.extra_flags_per_feature, is_macos = True) - - parse_headers_action_configs, parse_headers_features = parse_headers_support( - parse_headers_tool_path = ctx.attr.tool_paths.get("parse_headers"), - ) - action_configs += parse_headers_action_configs - features += parse_headers_features - - if symbol_check: - features.append(symbol_check) - - return cc_common.create_cc_toolchain_config_info( - ctx = ctx, - features = features, - action_configs = action_configs, - artifact_name_patterns = artifact_name_patterns, - cxx_builtin_include_directories = ctx.attr.cxx_builtin_include_directories, - toolchain_identifier = ctx.attr.toolchain_identifier, - host_system_name = ctx.attr.host_system_name, - target_system_name = ctx.attr.target_system_name, - target_cpu = ctx.attr.cpu, - target_libc = ctx.attr.target_libc, - compiler = ctx.attr.compiler, - abi_version = ctx.attr.abi_version, - abi_libc_version = ctx.attr.abi_libc_version, - tool_paths = tool_paths, - builtin_sysroot = ctx.attr.builtin_sysroot, - ) - -cc_toolchain_config = rule( - implementation = _impl, - attrs = { - "cpu": attr.string(mandatory = True), - "compiler": attr.string(mandatory = True), - "toolchain_identifier": attr.string(mandatory = True), - "host_system_name": attr.string(mandatory = True), - "target_system_name": attr.string(mandatory = True), - "target_libc": attr.string(mandatory = True), - "abi_version": attr.string(mandatory = True), - "abi_libc_version": attr.string(mandatory = True), - "cxx_builtin_include_directories": attr.string_list(), - "tool_paths": attr.string_dict(), - "compile_flags": attr.string_list(), - "dbg_compile_flags": attr.string_list(), - "opt_compile_flags": attr.string_list(), - "conly_flags": attr.string_list(), - "cxx_flags": attr.string_list(), - "link_flags": attr.string_list(), - "archive_flags": attr.string_list(), - "link_libs": attr.string_list(), - "opt_link_flags": attr.string_list(), - "unfiltered_compile_flags": attr.string_list(), - "coverage_compile_flags": attr.string_list(), - "coverage_link_flags": attr.string_list(), - "supports_start_end_lib": attr.bool(), - "builtin_sysroot": attr.string(), - "extra_flags_per_feature": attr.string_list_dict(), - "_xcode_config": attr.label(default = configuration_field( - fragment = "apple", - name = "xcode_config_label", - )), - }, - fragments = ["apple", "cpp"], - provides = [CcToolchainConfigInfo], -) diff --git a/tools/cpp/validate_static_library.sh.tpl b/tools/cpp/validate_static_library.sh.tpl deleted file mode 100755 index d769408465a3ce..00000000000000 --- a/tools/cpp/validate_static_library.sh.tpl +++ /dev/null @@ -1,44 +0,0 @@ -#!/usr/bin/env bash -# -# Copyright 2023 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. -set -euo pipefail - -# Find all duplicate symbols in the given static library: -# 1. Use nm to list all global symbols in the library in POSIX format: -# libstatic.a[my_object.o]: my_function T 1234 abcd -# 2. Use sed to transform the output to a format that can be sorted by symbol -# name and is readable by humans: -# my_object.o: T my_function -# By using the `t` and `d` commands, lines for symbols of type U (undefined) -# as well as V and W (weak) and their local lowercase variants are removed. -# 3. Use sort to sort the lines by symbol name. -# 4. Use uniq to only keep the lines corresponding to duplicate symbols. -# 5. Use c++filt to demangle the symbol names. -# c++filt is applied to the duplicated symbols instead of using the -C flag -# of nm because it is not in POSIX and demangled names may not be unique -# (https://gcc.gnu.org/bugzilla/show_bug.cgi?id=35201). -DUPLICATE_SYMBOLS=$( - "%{nm}" -A -g -P %{nm_extra_args} "$1" | - sed -E -e 's/.*\[([^][]+)\]: (.+) ([A-TX-Z]) [a-f0-9]+ [a-f0-9]+/\1: \3 \2/g' -e t -e d | - LC_ALL=C sort -k 3 | - LC_ALL=C uniq -D -f 2 | - "%{c++filt}") -if [[ -n "$DUPLICATE_SYMBOLS" ]]; then - >&2 echo "Duplicate symbols found in $1:" - >&2 echo "$DUPLICATE_SYMBOLS" - exit 1 -else - touch "$2" -fi diff --git a/tools/cpp/vc_installation_error.bat.tpl b/tools/cpp/vc_installation_error.bat.tpl deleted file mode 100644 index 228542224177c8..00000000000000 --- a/tools/cpp/vc_installation_error.bat.tpl +++ /dev/null @@ -1,24 +0,0 @@ -:: Copyright 2017 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. - -@echo OFF - -echo. 1>&2 -echo The target you are compiling requires Visual C++ build tools. 1>&2 -echo Bazel couldn't find a valid Visual C++ build tools installation on your machine. 1>&2 -%{vc_error_message} -echo Please check your installation following https://bazel.build/docs/windows#using 1>&2 -echo. 1>&2 - -exit /b 1 diff --git a/tools/cpp/windows_cc_configure.bzl b/tools/cpp/windows_cc_configure.bzl index 870564b041d2a7..0ae44db4dcd49c 100644 --- a/tools/cpp/windows_cc_configure.bzl +++ b/tools/cpp/windows_cc_configure.bzl @@ -1,864 +1,18 @@ -# pylint: disable=g-bad-file-header -# Copyright 2016 The Bazel Authors. All rights reserved. +# Copyright 2024 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 +# 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. -"""Configuring the C++ toolchain on Windows.""" -load( - "@bazel_tools//tools/cpp:lib_cc_configure.bzl", - "auto_configure_fail", - "auto_configure_warning", - "auto_configure_warning_maybe", - "escape_string", - "execute", - "resolve_labels", - "write_builtin_include_directory_paths", -) +load("@rules_cc//cc/toolchains:toolchain_config_utils.bzl", _find_vc_path="find_vc_path", _setup_vc_env_vars="setup_vc_env_vars") -_targets_archs = {"x64": "amd64", "x86": "amd64_x86", "arm": "amd64_arm", "arm64": "amd64_arm64"} -_targets_lib_folder = {"x86": "", "arm": "arm", "arm64": "arm64"} - -def _lookup_env_var(env, name, default = None): - """Lookup environment variable case-insensitve. - - If a matching (case-insensitive) entry is found in the env dict both - the key and the value are returned. The returned key might differ from - name in casing. - - If a matching key was found its value is returned otherwise - the default is returned. - - Return a (key, value) tuple""" - for key, value in env.items(): - if name.lower() == key.lower(): - return (key, value) - return (name, default) - -def _get_env_var(repository_ctx, name, default = None): - """Returns a value from an environment variable.""" - return _lookup_env_var(repository_ctx.os.environ, name, default)[1] - -def _get_path_env_var(repository_ctx, name): - """Returns a path from an environment variable. - - Removes quotes, replaces '/' with '\', and strips trailing '\'s.""" - value = _get_env_var(repository_ctx, name) - if value != None: - if value[0] == "\"": - if len(value) == 1 or value[-1] != "\"": - auto_configure_fail("'%s' environment variable has no trailing quote" % name) - value = value[1:-1] - if "/" in value: - value = value.replace("/", "\\") - if value[-1] == "\\": - value = value.rstrip("\\") - return value - -def _get_temp_env(repository_ctx): - """Returns the value of TMP, or TEMP, or if both undefined then C:\\Windows.""" - tmp = _get_path_env_var(repository_ctx, "TMP") - if not tmp: - tmp = _get_path_env_var(repository_ctx, "TEMP") - if not tmp: - tmp = "C:\\Windows\\Temp" - auto_configure_warning( - "neither 'TMP' nor 'TEMP' environment variables are set, using '%s' as default" % tmp, - ) - return tmp - -def _get_escaped_windows_msys_starlark_content(repository_ctx, use_mingw = False): - """Return the content of msys cc toolchain rule.""" - msys_root = "" - bazel_sh = _get_path_env_var(repository_ctx, "BAZEL_SH") - if bazel_sh: - bazel_sh = bazel_sh.replace("\\", "/").lower() - tokens = bazel_sh.rsplit("/", 1) - if tokens[0].endswith("/usr/bin"): - msys_root = tokens[0][:len(tokens[0]) - len("usr/bin")] - elif tokens[0].endswith("/bin"): - msys_root = tokens[0][:len(tokens[0]) - len("bin")] - - prefix = "mingw64" if use_mingw else "usr" - tool_path_prefix = escape_string(msys_root) + prefix - tool_bin_path = tool_path_prefix + "/bin" - tool_path = {} - - for tool in ["ar", "cpp", "dwp", "gcc", "gcov", "ld", "nm", "objcopy", "objdump", "strip"]: - if msys_root: - tool_path[tool] = tool_bin_path + "/" + tool - else: - tool_path[tool] = "msys_gcc_installation_error.bat" - tool_paths = ",\n ".join(['"%s": "%s"' % (k, v) for k, v in tool_path.items()]) - include_directories = (' "%s/",\n ' % tool_path_prefix) if msys_root else "" - return tool_paths, tool_bin_path, include_directories - -def _get_system_root(repository_ctx): - """Get System root path on Windows, default is C:\\Windows. Doesn't %-escape the result.""" - systemroot = _get_path_env_var(repository_ctx, "SYSTEMROOT") - if not systemroot: - systemroot = "C:\\Windows" - auto_configure_warning_maybe( - repository_ctx, - "SYSTEMROOT is not set, using default SYSTEMROOT=C:\\Windows", - ) - return escape_string(systemroot) - -def _add_system_root(repository_ctx, env): - """Running VCVARSALL.BAT and VCVARSQUERYREGISTRY.BAT need %SYSTEMROOT%\\\\system32 in PATH.""" - env_key, env_value = _lookup_env_var(env, "PATH", default = "") - env[env_key] = env_value + ";" + _get_system_root(repository_ctx) + "\\system32" - return env - -def find_vc_path(repository_ctx): - """Find Visual C++ build tools install path. Doesn't %-escape the result.""" - - # 1. Check if BAZEL_VC or BAZEL_VS is already set by user. - bazel_vc = _get_path_env_var(repository_ctx, "BAZEL_VC") - if bazel_vc: - if repository_ctx.path(bazel_vc).exists: - return bazel_vc - else: - auto_configure_warning_maybe( - repository_ctx, - "%BAZEL_VC% is set to non-existent path, ignoring.", - ) - - bazel_vs = _get_path_env_var(repository_ctx, "BAZEL_VS") - if bazel_vs: - if repository_ctx.path(bazel_vs).exists: - bazel_vc = bazel_vs + "\\VC" - if repository_ctx.path(bazel_vc).exists: - return bazel_vc - else: - auto_configure_warning_maybe( - repository_ctx, - "No 'VC' directory found under %BAZEL_VS%, ignoring.", - ) - else: - auto_configure_warning_maybe( - repository_ctx, - "%BAZEL_VS% is set to non-existent path, ignoring.", - ) - - auto_configure_warning_maybe( - repository_ctx, - "Neither %BAZEL_VC% nor %BAZEL_VS% are set, start looking for the latest Visual C++" + - " installed.", - ) - - # 2. Use vswhere to locate all Visual Studio installations - program_files_dir = _get_path_env_var(repository_ctx, "PROGRAMFILES(X86)") - if not program_files_dir: - program_files_dir = "C:\\Program Files (x86)" - auto_configure_warning_maybe( - repository_ctx, - "'PROGRAMFILES(X86)' environment variable is not set, using '%s' as default" % program_files_dir, - ) - - vswhere_binary = program_files_dir + "\\Microsoft Visual Studio\\Installer\\vswhere.exe" - if repository_ctx.path(vswhere_binary).exists: - result = repository_ctx.execute([vswhere_binary, "-requires", "Microsoft.VisualStudio.Component.VC.Tools.x86.x64", "-property", "installationPath", "-latest"]) - auto_configure_warning_maybe(repository_ctx, "vswhere query result:\n\nSTDOUT(start)\n%s\nSTDOUT(end)\nSTDERR(start):\n%s\nSTDERR(end)\n" % - (result.stdout, result.stderr)) - installation_path = result.stdout.strip() - if not result.stderr and installation_path: - vc_dir = installation_path + "\\VC" - auto_configure_warning_maybe(repository_ctx, "Visual C++ build tools found at %s" % vc_dir) - return vc_dir - - # 3. Check if VS%VS_VERSION%COMNTOOLS is set, if true then try to find and use - # vcvarsqueryregistry.bat / VsDevCmd.bat to detect VC++. - auto_configure_warning_maybe(repository_ctx, "Looking for VS%VERSION%COMNTOOLS environment variables, " + - "eg. VS140COMNTOOLS") - for vscommontools_env, script in [ - ("VS160COMNTOOLS", "VsDevCmd.bat"), - ("VS150COMNTOOLS", "VsDevCmd.bat"), - ("VS140COMNTOOLS", "vcvarsqueryregistry.bat"), - ("VS120COMNTOOLS", "vcvarsqueryregistry.bat"), - ("VS110COMNTOOLS", "vcvarsqueryregistry.bat"), - ("VS100COMNTOOLS", "vcvarsqueryregistry.bat"), - ("VS90COMNTOOLS", "vcvarsqueryregistry.bat"), - ]: - path = _get_path_env_var(repository_ctx, vscommontools_env) - if path == None: - continue - script = path + "\\" + script - if not repository_ctx.path(script).exists: - continue - repository_ctx.file( - "get_vc_dir.bat", - "@echo off\n" + - "call \"" + script + "\" > NUL\n" + - "echo %VCINSTALLDIR%", - True, - ) - env = _add_system_root(repository_ctx, repository_ctx.os.environ) - vc_dir = execute(repository_ctx, ["./get_vc_dir.bat"], environment = env) - - auto_configure_warning_maybe(repository_ctx, "Visual C++ build tools found at %s" % vc_dir) - return vc_dir - - # 4. User might have purged all environment variables. If so, look for Visual C++ in registry. - # Works for Visual Studio 2017 and older. (Does not work for Visual Studio 2019 Preview.) - auto_configure_warning_maybe(repository_ctx, "Looking for Visual C++ through registry") - reg_binary = _get_system_root(repository_ctx) + "\\system32\\reg.exe" - vc_dir = None - for key, suffix in (("VC7", ""), ("VS7", "\\VC")): - for version in ["15.0", "14.0", "12.0", "11.0", "10.0", "9.0", "8.0"]: - if vc_dir: - break - result = repository_ctx.execute([reg_binary, "query", "HKEY_LOCAL_MACHINE\\SOFTWARE\\Wow6432Node\\Microsoft\\VisualStudio\\SxS\\" + key, "/v", version]) - auto_configure_warning_maybe(repository_ctx, "registry query result for VC %s:\n\nSTDOUT(start)\n%s\nSTDOUT(end)\nSTDERR(start):\n%s\nSTDERR(end)\n" % - (version, result.stdout, result.stderr)) - if not result.stderr: - for line in result.stdout.split("\n"): - line = line.strip() - if line.startswith(version) and line.find("REG_SZ") != -1: - vc_dir = line[line.find("REG_SZ") + len("REG_SZ"):].strip() + suffix - if vc_dir: - auto_configure_warning_maybe(repository_ctx, "Visual C++ build tools found at %s" % vc_dir) - return vc_dir - - # 5. Check default directories for VC installation - auto_configure_warning_maybe(repository_ctx, "Looking for default Visual C++ installation directory") - for path in [ - "Microsoft Visual Studio\\%s\\%s\\VC" % (year, edition) - for year in (2022, 2019, 2017) - for edition in ("Preview", "BuildTools", "Community", "Professional", "Enterprise") - ] + [ - "Microsoft Visual Studio 14.0\\VC", - ]: - path = program_files_dir + "\\" + path - if repository_ctx.path(path).exists: - vc_dir = path - break - - if not vc_dir: - auto_configure_warning_maybe(repository_ctx, "Visual C++ build tools not found.") - return None - auto_configure_warning_maybe(repository_ctx, "Visual C++ build tools found at %s" % vc_dir) - return vc_dir - -def _is_vs_2017_or_newer(repository_ctx, vc_path): - """Check if the installed VS version is Visual Studio 2017 or newer.""" - - # For VS 2017 and later, a `Tools` directory should exist under `BAZEL_VC` - return repository_ctx.path(vc_path).get_child("Tools").exists - -def _is_msbuildtools(vc_path): - """Check if the installed VC version is from MSBuildTools.""" - - # In MSBuildTools (usually container setup), the location of VC is like: - # C:\BuildTools\MSBuild\Microsoft\VC - return vc_path.find("BuildTools") != -1 and vc_path.find("MSBuild") != -1 - -def _find_vcvars_bat_script(repository_ctx, vc_path): - """Find batch script to set up environment variables for VC. Doesn't %-escape the result.""" - if _is_vs_2017_or_newer(repository_ctx, vc_path): - vcvars_script = vc_path + "\\Auxiliary\\Build\\VCVARSALL.BAT" - else: - vcvars_script = vc_path + "\\VCVARSALL.BAT" - - if not repository_ctx.path(vcvars_script).exists: - return None - - return vcvars_script - -def _is_support_vcvars_ver(vc_full_version): - """-vcvars_ver option is supported from version 14.11.25503 (VS 2017 version 15.3).""" - version = [int(i) for i in vc_full_version.split(".")] - min_version = [14, 11, 25503] - return version >= min_version - -def _is_support_winsdk_selection(repository_ctx, vc_path): - """Windows SDK selection is supported with VC 2017 / 2019 or with full VS 2015 installation.""" - if _is_vs_2017_or_newer(repository_ctx, vc_path): - return True - - # By checking the source code of VCVARSALL.BAT in VC 2015, we know that - # when devenv.exe or wdexpress.exe exists, VCVARSALL.BAT supports Windows SDK selection. - vc_common_ide = repository_ctx.path(vc_path).dirname.get_child("Common7", "IDE") - for tool in ["devenv.exe", "wdexpress.exe"]: - if vc_common_ide.get_child(tool).exists: - return True - return False - -def _get_vc_env_vars(repository_ctx, vc_path, msvc_vars_x64, target_arch): - """Derive the environment variables set of a given target architecture from the environment variables of the x64 target. - - This is done to avoid running VCVARSALL.BAT script for every target architecture. - - Args: - repository_ctx: the repository_ctx object - vc_path: Visual C++ root directory - msvc_vars_x64: values of MSVC toolchain including the environment variables for x64 target architecture - target_arch: the target architecture to get its environment variables - - Returns: - dictionary of envvars - """ - env = {} - if _is_vs_2017_or_newer(repository_ctx, vc_path): - lib = msvc_vars_x64["%{msvc_env_lib_x64}"] - full_version = _get_vc_full_version(repository_ctx, vc_path) - tools_path = "%s\\Tools\\MSVC\\%s\\bin\\HostX64\\%s" % (vc_path, full_version, target_arch) - - # For native windows(10) on arm64 builds host toolchain runs in an emulated x86 environment - if not repository_ctx.path(tools_path).exists: - tools_path = "%s\\Tools\\MSVC\\%s\\bin\\HostX86\\%s" % (vc_path, full_version, target_arch) - else: - lib = msvc_vars_x64["%{msvc_env_lib_x64}"].replace("amd64", _targets_lib_folder[target_arch]) - tools_path = vc_path + "\\bin\\" + _targets_archs[target_arch] - - env["INCLUDE"] = msvc_vars_x64["%{msvc_env_include_x64}"] - env["LIB"] = lib.replace("x64", target_arch) - env["PATH"] = escape_string(tools_path.replace("\\", "\\\\")) + ";" + msvc_vars_x64["%{msvc_env_path_x64}"] - return env - -def setup_vc_env_vars(repository_ctx, vc_path, envvars = [], allow_empty = False, escape = True): - """Get environment variables set by VCVARSALL.BAT script. Doesn't %-escape the result! - - Args: - repository_ctx: the repository_ctx object - vc_path: Visual C++ root directory - envvars: list of envvars to retrieve; default is ["PATH", "INCLUDE", "LIB", "WINDOWSSDKDIR"] - allow_empty: allow unset envvars; if False then report errors for those - escape: if True, escape "\" as "\\" and "%" as "%%" in the envvar values - - Returns: - dictionary of the envvars - """ - if not envvars: - envvars = ["PATH", "INCLUDE", "LIB", "WINDOWSSDKDIR"] - - vcvars_script = _find_vcvars_bat_script(repository_ctx, vc_path) - if not vcvars_script: - auto_configure_fail("Cannot find VCVARSALL.BAT script under %s" % vc_path) - - # Getting Windows SDK version set by user. - # Only supports VC 2017 & 2019 and VC 2015 with full VS installation. - winsdk_version = _get_winsdk_full_version(repository_ctx) - if winsdk_version and not _is_support_winsdk_selection(repository_ctx, vc_path): - auto_configure_warning(("BAZEL_WINSDK_FULL_VERSION=%s is ignored, " + - "because standalone Visual C++ Build Tools 2015 doesn't support specifying Windows " + - "SDK version, please install the full VS 2015 or use VC 2017/2019.") % winsdk_version) - winsdk_version = "" - - # Get VC version set by user. Only supports VC 2017 & 2019. - vcvars_ver = "" - if _is_vs_2017_or_newer(repository_ctx, vc_path): - full_version = _get_vc_full_version(repository_ctx, vc_path) - - # Because VCVARSALL.BAT is from the latest VC installed, so we check if the latest - # version supports -vcvars_ver or not. - if _is_support_vcvars_ver(_get_latest_subversion(repository_ctx, vc_path)): - vcvars_ver = "-vcvars_ver=" + full_version - - cmd = "\"%s\" amd64 %s %s" % (vcvars_script, winsdk_version, vcvars_ver) - print_envvars = ",".join(["{k}=%{k}%".format(k = k) for k in envvars]) - repository_ctx.file( - "get_env.bat", - "@echo off\n" + - ("call %s > NUL \n" % cmd) + ("echo %s \n" % print_envvars), - True, - ) - env = _add_system_root(repository_ctx, {k: "" for k in envvars}) - envs = execute(repository_ctx, ["./get_env.bat"], environment = env).split(",") - env_map = {} - for env in envs: - key, value = env.split("=", 1) - env_map[key] = escape_string(value.replace("\\", "\\\\")) if escape else value - - if not allow_empty: - _check_env_vars(env_map, cmd, expected = envvars) - return env_map - -def _check_env_vars(env_map, cmd, expected): - for env in expected: - if not env_map.get(env): - auto_configure_fail( - "Setting up VC environment variables failed, %s is not set by the following command:\n %s" % (env, cmd), - ) - -def _get_latest_subversion(repository_ctx, vc_path): - """Get the latest subversion of a VS 2017/2019 installation. - - For VS 2017 & 2019, there could be multiple versions of VC build tools. - The directories are like: - \\Tools\\MSVC\\14.10.24930\\bin\\HostX64\\x64 - \\Tools\\MSVC\\14.16.27023\\bin\\HostX64\\x64 - This function should return 14.16.27023 in this case.""" - versions = [path.basename for path in repository_ctx.path(vc_path + "\\Tools\\MSVC").readdir()] - if len(versions) < 1: - auto_configure_warning_maybe(repository_ctx, "Cannot find any VC installation under BAZEL_VC(%s)" % vc_path) - return None - - # Parse the version string into integers, then sort the integers to prevent textual sorting. - version_list = [] - for version in versions: - parts = [int(i) for i in version.split(".")] - version_list.append((parts, version)) - - version_list = sorted(version_list) - latest_version = version_list[-1][1] - - auto_configure_warning_maybe(repository_ctx, "Found the following VC versions:\n%s\n\nChoosing the latest version = %s" % ("\n".join(versions), latest_version)) - return latest_version - -def _get_vc_full_version(repository_ctx, vc_path): - """Return the value of BAZEL_VC_FULL_VERSION if defined, otherwise the latest version.""" - version = _get_env_var(repository_ctx, "BAZEL_VC_FULL_VERSION") - if version != None: - return version - return _get_latest_subversion(repository_ctx, vc_path) - -def _get_winsdk_full_version(repository_ctx): - """Return the value of BAZEL_WINSDK_FULL_VERSION if defined, otherwise an empty string.""" - return _get_env_var(repository_ctx, "BAZEL_WINSDK_FULL_VERSION", default = "") - -def _find_msvc_tools(repository_ctx, vc_path, target_arch = "x64"): - """Find the exact paths of the build tools in MSVC for the given target. Doesn't %-escape the result.""" - build_tools_paths = {} - tools = _get_target_tools(target_arch) - for tool_name in tools: - build_tools_paths[tool_name] = find_msvc_tool(repository_ctx, vc_path, tools[tool_name], target_arch) - return build_tools_paths - -def find_msvc_tool(repository_ctx, vc_path, tool, target_arch = "x64"): - """Find the exact path of a specific build tool in MSVC. Doesn't %-escape the result.""" - tool_path = None - if _is_vs_2017_or_newer(repository_ctx, vc_path) or _is_msbuildtools(vc_path): - full_version = _get_vc_full_version(repository_ctx, vc_path) - if full_version: - tool_path = "%s\\Tools\\MSVC\\%s\\bin\\HostX64\\%s\\%s" % (vc_path, full_version, target_arch, tool) - - # For native windows(10) on arm64 builds host toolchain runs in an emulated x86 environment - if not repository_ctx.path(tool_path).exists: - tool_path = "%s\\Tools\\MSVC\\%s\\bin\\HostX86\\%s\\%s" % (vc_path, full_version, target_arch, tool) - else: - # For VS 2015 and older version, the tools are under: - # C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\bin\amd64 - tool_path = vc_path + "\\bin\\" + _targets_archs[target_arch] + "\\" + tool - - if not tool_path or not repository_ctx.path(tool_path).exists: - return None - - return tool_path.replace("\\", "/") - -def _find_missing_vc_tools(repository_ctx, vc_path, target_arch = "x64"): - """Check if any required tool for the given target architecture is missing under given VC path.""" - missing_tools = [] - if not _find_vcvars_bat_script(repository_ctx, vc_path): - missing_tools.append("VCVARSALL.BAT") - - tools = _get_target_tools(target_arch) - for tool_name in tools: - if not find_msvc_tool(repository_ctx, vc_path, tools[tool_name], target_arch): - missing_tools.append(tools[tool_name]) - return missing_tools - -def _get_target_tools(target): - """Return a list of required tools names and their filenames for a certain target.""" - tools = { - "x64": {"CL": "cl.exe", "LINK": "link.exe", "LIB": "lib.exe", "DUMPBIN": "dumpbin.exe", "ML": "ml64.exe"}, - "x86": {"CL": "cl.exe", "LINK": "link.exe", "LIB": "lib.exe", "DUMPBIN": "dumpbin.exe", "ML": "ml.exe"}, - "arm": {"CL": "cl.exe", "LINK": "link.exe", "LIB": "lib.exe", "DUMPBIN": "dumpbin.exe"}, - "arm64": {"CL": "cl.exe", "LINK": "link.exe", "LIB": "lib.exe", "DUMPBIN": "dumpbin.exe"}, - } - if tools.get(target) == None: - auto_configure_fail("Target architecture %s is not recognized" % target) - - return tools.get(target) - -def _is_support_debug_fastlink(repository_ctx, linker): - """Run linker alone to see if it supports /DEBUG:FASTLINK.""" - if _use_clang_cl(repository_ctx): - # LLVM's lld-link.exe doesn't support /DEBUG:FASTLINK. - return False - result = execute(repository_ctx, [linker], expect_failure = True) - return result.find("/DEBUG[:{FASTLINK|FULL|NONE}]") != -1 - -def _is_support_parse_showincludes(repository_ctx, cl, env): - repository_ctx.file( - "main.cpp", - "#include \"bazel_showincludes.h\"\nint main(){}\n", - ) - repository_ctx.file( - "bazel_showincludes.h", - "\n", - ) - result = execute( - repository_ctx, - [cl, "/nologo", "/showIncludes", "/c", "main.cpp", "/out", "main.exe", "/Fo", "main.obj"], - # Attempt to force English language. This may fail if the language pack isn't installed. - environment = env | {"VSLANG": "1033"}, - ) - for file in ["main.cpp", "bazel_showincludes.h", "main.exe", "main.obj"]: - execute(repository_ctx, ["cmd", "/C", "del", file], expect_empty_output = True) - return any([ - line.startswith("Note: including file:") and line.endswith("bazel_showincludes.h") - for line in result.split("\n") - ]) - -def find_llvm_path(repository_ctx): - """Find LLVM install path.""" - - # 1. Check if BAZEL_LLVM is already set by user. - bazel_llvm = _get_path_env_var(repository_ctx, "BAZEL_LLVM") - if bazel_llvm: - return bazel_llvm - - auto_configure_warning_maybe(repository_ctx, "'BAZEL_LLVM' is not set, " + - "start looking for LLVM installation on machine.") - - # 2. Look for LLVM installation through registry. - auto_configure_warning_maybe(repository_ctx, "Looking for LLVM installation through registry") - reg_binary = _get_system_root(repository_ctx) + "\\system32\\reg.exe" - llvm_dir = None - result = repository_ctx.execute([reg_binary, "query", "HKEY_LOCAL_MACHINE\\SOFTWARE\\WOW6432Node\\LLVM\\LLVM"]) - auto_configure_warning_maybe(repository_ctx, "registry query result for LLVM:\n\nSTDOUT(start)\n%s\nSTDOUT(end)\nSTDERR(start):\n%s\nSTDERR(end)\n" % - (result.stdout, result.stderr)) - if not result.stderr: - for line in result.stdout.split("\n"): - line = line.strip() - if line.startswith("(Default)") and line.find("REG_SZ") != -1: - llvm_dir = line[line.find("REG_SZ") + len("REG_SZ"):].strip() - if llvm_dir: - auto_configure_warning_maybe(repository_ctx, "LLVM installation found at %s" % llvm_dir) - return llvm_dir - - # 3. Check default directories for LLVM installation - auto_configure_warning_maybe(repository_ctx, "Looking for default LLVM installation directory") - program_files_dir = _get_path_env_var(repository_ctx, "PROGRAMFILES") - if not program_files_dir: - program_files_dir = "C:\\Program Files" - auto_configure_warning_maybe( - repository_ctx, - "'PROGRAMFILES' environment variable is not set, using '%s' as default" % program_files_dir, - ) - path = program_files_dir + "\\LLVM" - if repository_ctx.path(path).exists: - llvm_dir = path - - if not llvm_dir: - auto_configure_warning_maybe(repository_ctx, "LLVM installation not found.") - return None - auto_configure_warning_maybe(repository_ctx, "LLVM installation found at %s" % llvm_dir) - return llvm_dir - -def find_llvm_tool(repository_ctx, llvm_path, tool): - """Find the exact path of a specific build tool in LLVM. Doesn't %-escape the result.""" - tool_path = llvm_path + "\\bin\\" + tool - - if not repository_ctx.path(tool_path).exists: - return None - - return tool_path.replace("\\", "/") - -def _use_clang_cl(repository_ctx): - """Returns True if USE_CLANG_CL is set to 1.""" - return _get_env_var(repository_ctx, "USE_CLANG_CL", default = "0") == "1" - -def _find_missing_llvm_tools(repository_ctx, llvm_path): - """Check if any required tool is missing under given LLVM path.""" - missing_tools = [] - for tool in ["clang-cl.exe", "lld-link.exe", "llvm-lib.exe"]: - if not find_llvm_tool(repository_ctx, llvm_path, tool): - missing_tools.append(tool) - - return missing_tools - -def _get_clang_version(repository_ctx, clang_cl): - result = repository_ctx.execute([clang_cl, "-v"]) - first_line = result.stderr.strip().splitlines()[0].strip() - - # The first line of stderr should look like "[vendor ]clang version X.X.X" - if result.return_code != 0 or first_line.find("clang version ") == -1: - auto_configure_fail("Failed to get clang version by running \"%s -v\"" % clang_cl) - return first_line.split(" ")[-1] - -def _get_clang_dir(repository_ctx, llvm_path, clang_version): - """Get the clang installation directory.""" - - # The clang_version string format is "X.X.X" - clang_dir = llvm_path + "\\lib\\clang\\" + clang_version - if repository_ctx.path(clang_dir).exists: - return clang_dir - - # Clang 16 changed the install path to use just the major number. - clang_major_version = clang_version.split(".")[0] - return llvm_path + "\\lib\\clang\\" + clang_major_version - -def _get_msys_mingw_vars(repository_ctx): - """Get the variables we need to populate the msys/mingw toolchains.""" - tool_paths, tool_bin_path, inc_dir_msys = _get_escaped_windows_msys_starlark_content(repository_ctx) - tool_paths_mingw, tool_bin_path_mingw, inc_dir_mingw = _get_escaped_windows_msys_starlark_content(repository_ctx, use_mingw = True) - write_builtin_include_directory_paths(repository_ctx, "mingw", [inc_dir_mingw], file_suffix = "_mingw") - msys_mingw_vars = { - "%{cxx_builtin_include_directories}": inc_dir_msys, - "%{mingw_cxx_builtin_include_directories}": inc_dir_mingw, - "%{tool_paths}": tool_paths, - "%{mingw_tool_paths}": tool_paths_mingw, - "%{tool_bin_path}": tool_bin_path, - "%{mingw_tool_bin_path}": tool_bin_path_mingw, - } - return msys_mingw_vars - -def _get_msvc_vars(repository_ctx, paths, target_arch = "x64", msvc_vars_x64 = None): - """Get the variables we need to populate the MSVC toolchains.""" - msvc_vars = dict() - vc_path = find_vc_path(repository_ctx) - missing_tools = None - - if not vc_path: - repository_ctx.template( - "vc_installation_error_" + target_arch + ".bat", - paths["@bazel_tools//tools/cpp:vc_installation_error.bat.tpl"], - {"%{vc_error_message}": ""}, - ) - else: - missing_tools = _find_missing_vc_tools(repository_ctx, vc_path, target_arch) - if missing_tools: - message = "\r\n".join([ - "echo. 1>&2", - "echo Visual C++ build tools seems to be installed at %s 1>&2" % vc_path, - "echo But Bazel can't find the following tools: 1>&2", - "echo %s 1>&2" % ", ".join(missing_tools), - "echo for %s target architecture 1>&2" % target_arch, - "echo. 1>&2", - ]) - repository_ctx.template( - "vc_installation_error_" + target_arch + ".bat", - paths["@bazel_tools//tools/cpp:vc_installation_error.bat.tpl"], - {"%{vc_error_message}": message}, - ) - - if not vc_path or missing_tools: - write_builtin_include_directory_paths(repository_ctx, "msvc", [], file_suffix = "_msvc") - msvc_vars = { - "%{msvc_env_tmp_" + target_arch + "}": "msvc_not_found", - "%{msvc_env_include_" + target_arch + "}": "msvc_not_found", - "%{msvc_cxx_builtin_include_directories_" + target_arch + "}": "", - "%{msvc_env_path_" + target_arch + "}": "msvc_not_found", - "%{msvc_env_lib_" + target_arch + "}": "msvc_not_found", - "%{msvc_cl_path_" + target_arch + "}": "vc_installation_error_" + target_arch + ".bat", - "%{msvc_ml_path_" + target_arch + "}": "vc_installation_error_" + target_arch + ".bat", - "%{msvc_link_path_" + target_arch + "}": "vc_installation_error_" + target_arch + ".bat", - "%{msvc_lib_path_" + target_arch + "}": "vc_installation_error_" + target_arch + ".bat", - "%{dbg_mode_debug_flag_" + target_arch + "}": "/DEBUG", - "%{fastbuild_mode_debug_flag_" + target_arch + "}": "/DEBUG", - "%{msvc_parse_showincludes_" + target_arch + "}": repr(False), - } - return msvc_vars - - if msvc_vars_x64: - env = _get_vc_env_vars(repository_ctx, vc_path, msvc_vars_x64, target_arch) - else: - env = setup_vc_env_vars(repository_ctx, vc_path) - escaped_tmp_dir = escape_string(_get_temp_env(repository_ctx).replace("\\", "\\\\")) - escaped_include_paths = escape_string(env["INCLUDE"]) - - build_tools = {} - llvm_path = "" - if _use_clang_cl(repository_ctx): - llvm_path = find_llvm_path(repository_ctx) - if not llvm_path: - auto_configure_fail("\nUSE_CLANG_CL is set to 1, but Bazel cannot find Clang installation on your system.\n" + - "Please install Clang via http://releases.llvm.org/download.html\n") - - build_tools["CL"] = find_llvm_tool(repository_ctx, llvm_path, "clang-cl.exe") - build_tools["ML"] = find_msvc_tool(repository_ctx, vc_path, "ml64.exe", "x64") - build_tools["LINK"] = find_llvm_tool(repository_ctx, llvm_path, "lld-link.exe") - if not build_tools["LINK"]: - build_tools["LINK"] = find_msvc_tool(repository_ctx, vc_path, "link.exe", "x64") - build_tools["LIB"] = find_llvm_tool(repository_ctx, llvm_path, "llvm-lib.exe") - if not build_tools["LIB"]: - build_tools["LIB"] = find_msvc_tool(repository_ctx, vc_path, "lib.exe", "x64") - else: - build_tools = _find_msvc_tools(repository_ctx, vc_path, target_arch) - - escaped_cxx_include_directories = [] - for path in escaped_include_paths.split(";"): - if path: - escaped_cxx_include_directories.append("\"%s\"" % path) - if llvm_path: - clang_version = _get_clang_version(repository_ctx, build_tools["CL"]) - clang_dir = _get_clang_dir(repository_ctx, llvm_path, clang_version) - clang_include_path = (clang_dir + "\\include").replace("\\", "\\\\") - escaped_cxx_include_directories.append("\"%s\"" % clang_include_path) - clang_lib_path = (clang_dir + "\\lib\\windows").replace("\\", "\\\\") - env["LIB"] = escape_string(env["LIB"]) + ";" + clang_lib_path - - support_debug_fastlink = _is_support_debug_fastlink(repository_ctx, build_tools["LINK"]) - write_builtin_include_directory_paths(repository_ctx, "msvc", escaped_cxx_include_directories, file_suffix = "_msvc") - - support_parse_showincludes = _is_support_parse_showincludes(repository_ctx, build_tools["CL"], env) - if not support_parse_showincludes: - auto_configure_warning(""" -Header pruning has been disabled since Bazel failed to recognize the output of /showIncludes. -This can result in unnecessary recompilation. -Fix this by installing the English language pack for the Visual Studio installation at {} and run 'bazel sync --configure'.""".format(vc_path)) - - msvc_vars = { - "%{msvc_env_tmp_" + target_arch + "}": escaped_tmp_dir, - "%{msvc_env_include_" + target_arch + "}": escaped_include_paths, - "%{msvc_cxx_builtin_include_directories_" + target_arch + "}": " " + ",\n ".join(escaped_cxx_include_directories), - "%{msvc_env_path_" + target_arch + "}": escape_string(env["PATH"]), - "%{msvc_env_lib_" + target_arch + "}": escape_string(env["LIB"]), - "%{msvc_cl_path_" + target_arch + "}": build_tools["CL"], - "%{msvc_ml_path_" + target_arch + "}": build_tools.get("ML", "msvc_arm_toolchain_does_not_support_ml"), - "%{msvc_link_path_" + target_arch + "}": build_tools["LINK"], - "%{msvc_lib_path_" + target_arch + "}": build_tools["LIB"], - "%{msvc_dumpbin_path_" + target_arch + "}": build_tools["DUMPBIN"], - "%{msvc_parse_showincludes_" + target_arch + "}": repr(support_parse_showincludes), - "%{dbg_mode_debug_flag_" + target_arch + "}": "/DEBUG:FULL" if support_debug_fastlink else "/DEBUG", - "%{fastbuild_mode_debug_flag_" + target_arch + "}": "/DEBUG:FASTLINK" if support_debug_fastlink else "/DEBUG", - } - return msvc_vars - -def _get_clang_cl_vars(repository_ctx, paths, msvc_vars, target_arch): - """Get the variables we need to populate the clang-cl toolchains.""" - llvm_path = find_llvm_path(repository_ctx) - error_script = None - if msvc_vars["%{msvc_cl_path_" + target_arch + "}"] == "vc_installation_error_{}.bat".format(target_arch): - error_script = "vc_installation_error_{}.bat".format(target_arch) - elif not llvm_path: - repository_ctx.template( - "clang_installation_error.bat", - paths["@bazel_tools//tools/cpp:clang_installation_error.bat.tpl"], - {"%{clang_error_message}": ""}, - ) - error_script = "clang_installation_error.bat" - else: - missing_tools = _find_missing_llvm_tools(repository_ctx, llvm_path) - if missing_tools: - message = "\r\n".join([ - "echo. 1>&2", - "echo LLVM/Clang seems to be installed at %s 1>&2" % llvm_path, - "echo But Bazel can't find the following tools: 1>&2", - "echo %s 1>&2" % ", ".join(missing_tools), - "echo. 1>&2", - ]) - repository_ctx.template( - "clang_installation_error.bat", - paths["@bazel_tools//tools/cpp:clang_installation_error.bat.tpl"], - {"%{clang_error_message}": message}, - ) - error_script = "clang_installation_error.bat" - - if error_script: - write_builtin_include_directory_paths(repository_ctx, "clang-cl", [], file_suffix = "_clangcl") - clang_cl_vars = { - "%{clang_cl_env_tmp_" + target_arch + "}": "clang_cl_not_found", - "%{clang_cl_env_path_" + target_arch + "}": "clang_cl_not_found", - "%{clang_cl_env_include_" + target_arch + "}": "clang_cl_not_found", - "%{clang_cl_env_lib_" + target_arch + "}": "clang_cl_not_found", - "%{clang_cl_cl_path_" + target_arch + "}": error_script, - "%{clang_cl_link_path_" + target_arch + "}": error_script, - "%{clang_cl_lib_path_" + target_arch + "}": error_script, - "%{clang_cl_ml_path_" + target_arch + "}": error_script, - "%{clang_cl_dbg_mode_debug_flag_" + target_arch + "}": "/DEBUG", - "%{clang_cl_fastbuild_mode_debug_flag_" + target_arch + "}": "/DEBUG", - "%{clang_cl_cxx_builtin_include_directories_" + target_arch + "}": "", - "%{clang_cl_parse_showincludes_" + target_arch + "}": repr(False), - } - return clang_cl_vars - - clang_cl_path = find_llvm_tool(repository_ctx, llvm_path, "clang-cl.exe") - lld_link_path = find_llvm_tool(repository_ctx, llvm_path, "lld-link.exe") - llvm_lib_path = find_llvm_tool(repository_ctx, llvm_path, "llvm-lib.exe") - - clang_version = _get_clang_version(repository_ctx, clang_cl_path) - clang_dir = _get_clang_dir(repository_ctx, llvm_path, clang_version) - clang_include_path = (clang_dir + "\\include").replace("\\", "\\\\") - clang_lib_path = (clang_dir + "\\lib\\windows").replace("\\", "\\\\") - - clang_cl_include_directories = msvc_vars["%{msvc_cxx_builtin_include_directories_" + target_arch + "}"] + (",\n \"%s\"" % clang_include_path) - write_builtin_include_directory_paths(repository_ctx, "clang-cl", [clang_cl_include_directories], file_suffix = "_clangcl") - clang_cl_vars = { - "%{clang_cl_env_tmp_" + target_arch + "}": msvc_vars["%{msvc_env_tmp_" + target_arch + "}"], - "%{clang_cl_env_path_" + target_arch + "}": msvc_vars["%{msvc_env_path_" + target_arch + "}"], - "%{clang_cl_env_include_" + target_arch + "}": msvc_vars["%{msvc_env_include_" + target_arch + "}"] + ";" + clang_include_path, - "%{clang_cl_env_lib_" + target_arch + "}": msvc_vars["%{msvc_env_lib_" + target_arch + "}"] + ";" + clang_lib_path, - "%{clang_cl_cxx_builtin_include_directories_" + target_arch + "}": clang_cl_include_directories, - "%{clang_cl_cl_path_" + target_arch + "}": clang_cl_path, - "%{clang_cl_link_path_" + target_arch + "}": lld_link_path, - "%{clang_cl_lib_path_" + target_arch + "}": llvm_lib_path, - # clang-cl does not support assembly files as input. - "%{clang_cl_ml_path_" + target_arch + "}": msvc_vars["%{msvc_ml_path_" + target_arch + "}"], - # LLVM's lld-link.exe doesn't support /DEBUG:FASTLINK. - "%{clang_cl_dbg_mode_debug_flag_" + target_arch + "}": "/DEBUG", - "%{clang_cl_fastbuild_mode_debug_flag_" + target_arch + "}": "/DEBUG", - # clang-cl always emits the English language version of the /showIncludes prefix. - "%{clang_cl_parse_showincludes_" + target_arch + "}": repr(True), - } - return clang_cl_vars - -def _get_msvc_deps_scanner_vars(repository_ctx, paths, template_vars, target_arch = "x64"): - repository_ctx.template( - "msvc_deps_scanner_wrapper_" + target_arch + ".bat", - paths["@bazel_tools//tools/cpp:msvc_deps_scanner_wrapper.bat.tpl"], - { - "%{cc}": template_vars["%{msvc_cl_path_" + target_arch + "}"], - }, - ) - - return { - "%{msvc_deps_scanner_wrapper_path_" + target_arch + "}": "msvc_deps_scanner_wrapper_" + target_arch + ".bat", - } - -def configure_windows_toolchain(repository_ctx): - """Configure C++ toolchain on Windows.""" - paths = resolve_labels(repository_ctx, [ - "@bazel_tools//tools/cpp:BUILD.windows.tpl", - "@bazel_tools//tools/cpp:windows_cc_toolchain_config.bzl", - "@bazel_tools//tools/cpp:armeabi_cc_toolchain_config.bzl", - "@bazel_tools//tools/cpp:vc_installation_error.bat.tpl", - "@bazel_tools//tools/cpp:msys_gcc_installation_error.bat", - "@bazel_tools//tools/cpp:clang_installation_error.bat.tpl", - "@bazel_tools//tools/cpp:msvc_deps_scanner_wrapper.bat.tpl", - ]) - - repository_ctx.symlink( - paths["@bazel_tools//tools/cpp:windows_cc_toolchain_config.bzl"], - "windows_cc_toolchain_config.bzl", - ) - repository_ctx.symlink( - paths["@bazel_tools//tools/cpp:armeabi_cc_toolchain_config.bzl"], - "armeabi_cc_toolchain_config.bzl", - ) - repository_ctx.symlink( - paths["@bazel_tools//tools/cpp:msys_gcc_installation_error.bat"], - "msys_gcc_installation_error.bat", - ) - - template_vars = dict() - msvc_vars_x64 = _get_msvc_vars(repository_ctx, paths, "x64") - template_vars.update(msvc_vars_x64) - template_vars.update(_get_clang_cl_vars(repository_ctx, paths, msvc_vars_x64, "x64")) - template_vars.update(_get_msys_mingw_vars(repository_ctx)) - template_vars.update(_get_msvc_vars(repository_ctx, paths, "x86", msvc_vars_x64)) - template_vars.update(_get_msvc_vars(repository_ctx, paths, "arm", msvc_vars_x64)) - msvc_vars_arm64 = _get_msvc_vars(repository_ctx, paths, "arm64", msvc_vars_x64) - template_vars.update(msvc_vars_arm64) - template_vars.update(_get_clang_cl_vars(repository_ctx, paths, msvc_vars_arm64, "arm64")) - - template_vars.update(_get_msvc_deps_scanner_vars(repository_ctx, paths, template_vars, "x64")) - template_vars.update(_get_msvc_deps_scanner_vars(repository_ctx, paths, template_vars, "x86")) - template_vars.update(_get_msvc_deps_scanner_vars(repository_ctx, paths, template_vars, "arm")) - template_vars.update(_get_msvc_deps_scanner_vars(repository_ctx, paths, template_vars, "arm64")) - repository_ctx.template( - "BUILD", - paths["@bazel_tools//tools/cpp:BUILD.windows.tpl"], - template_vars, - ) +find_vc_path = _find_vc_path +setup_vc_env_vars = _setup_vc_env_vars diff --git a/tools/cpp/windows_cc_toolchain_config.bzl b/tools/cpp/windows_cc_toolchain_config.bzl deleted file mode 100644 index ffac6e41ba2064..00000000000000 --- a/tools/cpp/windows_cc_toolchain_config.bzl +++ /dev/null @@ -1,1669 +0,0 @@ -# Copyright 2019 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. - -"""A Starlark cc_toolchain configuration rule for Windows""" - -load("@bazel_tools//tools/build_defs/cc:action_names.bzl", "ACTION_NAMES") -load( - "@bazel_tools//tools/cpp:cc_toolchain_config_lib.bzl", - "action_config", - "artifact_name_pattern", - "env_entry", - "env_set", - "feature", - "flag_group", - "flag_set", - "make_variable", - "tool", - "tool_path", - "variable_with_value", - "with_feature_set", -) - -all_compile_actions = [ - ACTION_NAMES.c_compile, - ACTION_NAMES.cpp_compile, - ACTION_NAMES.linkstamp_compile, - ACTION_NAMES.assemble, - ACTION_NAMES.preprocess_assemble, - ACTION_NAMES.cpp_header_parsing, - ACTION_NAMES.cpp_module_compile, - ACTION_NAMES.cpp_module_codegen, - ACTION_NAMES.cpp_module_deps_scanning, - ACTION_NAMES.cpp20_module_compile, - ACTION_NAMES.cpp20_module_codegen, - ACTION_NAMES.clif_match, - ACTION_NAMES.lto_backend, -] - -all_cpp_compile_actions = [ - ACTION_NAMES.cpp_compile, - ACTION_NAMES.linkstamp_compile, - ACTION_NAMES.cpp_header_parsing, - ACTION_NAMES.cpp_module_compile, - ACTION_NAMES.cpp_module_codegen, - ACTION_NAMES.cpp_module_deps_scanning, - ACTION_NAMES.cpp20_module_compile, - ACTION_NAMES.cpp20_module_codegen, - ACTION_NAMES.clif_match, -] - -preprocessor_compile_actions = [ - ACTION_NAMES.c_compile, - ACTION_NAMES.cpp_compile, - ACTION_NAMES.linkstamp_compile, - ACTION_NAMES.preprocess_assemble, - ACTION_NAMES.cpp_header_parsing, - ACTION_NAMES.cpp_module_compile, - ACTION_NAMES.cpp_module_deps_scanning, - ACTION_NAMES.cpp20_module_compile, - ACTION_NAMES.clif_match, -] - -codegen_compile_actions = [ - ACTION_NAMES.c_compile, - ACTION_NAMES.cpp_compile, - ACTION_NAMES.linkstamp_compile, - ACTION_NAMES.assemble, - ACTION_NAMES.preprocess_assemble, - ACTION_NAMES.cpp_module_codegen, - ACTION_NAMES.cpp20_module_codegen, - ACTION_NAMES.lto_backend, -] - -all_link_actions = [ - ACTION_NAMES.cpp_link_executable, - ACTION_NAMES.cpp_link_dynamic_library, - ACTION_NAMES.cpp_link_nodeps_dynamic_library, -] - -def _use_msvc_toolchain(ctx): - return ctx.attr.cpu in ["x64_windows", "arm64_windows"] and (ctx.attr.compiler == "msvc-cl" or ctx.attr.compiler == "clang-cl") - -def _impl(ctx): - if _use_msvc_toolchain(ctx): - artifact_name_patterns = [ - artifact_name_pattern( - category_name = "object_file", - prefix = "", - extension = ".obj", - ), - artifact_name_pattern( - category_name = "static_library", - prefix = "", - extension = ".lib", - ), - artifact_name_pattern( - category_name = "alwayslink_static_library", - prefix = "", - extension = ".lo.lib", - ), - artifact_name_pattern( - category_name = "executable", - prefix = "", - extension = ".exe", - ), - artifact_name_pattern( - category_name = "dynamic_library", - prefix = "", - extension = ".dll", - ), - artifact_name_pattern( - category_name = "interface_library", - prefix = "", - extension = ".if.lib", - ), - ] - else: - artifact_name_patterns = [ - artifact_name_pattern( - category_name = "executable", - prefix = "", - extension = ".exe", - ), - ] - - if _use_msvc_toolchain(ctx): - cpp_link_nodeps_dynamic_library_action = action_config( - action_name = ACTION_NAMES.cpp_link_nodeps_dynamic_library, - implies = [ - "nologo", - "shared_flag", - "linkstamps", - "output_execpath_flags", - "input_param_flags", - "user_link_flags", - "linker_subsystem_flag", - "linker_param_file", - "msvc_env", - "no_stripping", - "has_configured_linker_path", - "def_file", - ], - tools = [tool(path = ctx.attr.msvc_link_path)], - ) - - cpp_link_static_library_action = action_config( - action_name = ACTION_NAMES.cpp_link_static_library, - implies = [ - "nologo", - "archiver_flags", - "input_param_flags", - "linker_param_file", - "msvc_env", - ], - tools = [tool(path = ctx.attr.msvc_lib_path)], - ) - - assemble_action = action_config( - action_name = ACTION_NAMES.assemble, - implies = [ - "compiler_input_flags", - "compiler_output_flags", - "nologo", - "msvc_env", - "sysroot", - ], - tools = [tool(path = ctx.attr.msvc_ml_path)], - ) - - preprocess_assemble_action = action_config( - action_name = ACTION_NAMES.preprocess_assemble, - implies = [ - "compiler_input_flags", - "compiler_output_flags", - "nologo", - "msvc_env", - "sysroot", - ], - tools = [tool(path = ctx.attr.msvc_ml_path)], - ) - - c_compile_action = action_config( - action_name = ACTION_NAMES.c_compile, - implies = [ - "compiler_input_flags", - "compiler_output_flags", - "nologo", - "msvc_env", - "user_compile_flags", - "sysroot", - ], - tools = [tool(path = ctx.attr.msvc_cl_path)], - ) - - linkstamp_compile_action = action_config( - action_name = ACTION_NAMES.linkstamp_compile, - implies = [ - "compiler_input_flags", - "compiler_output_flags", - "default_compile_flags", - "nologo", - "msvc_env", - "user_compile_flags", - "sysroot", - "unfiltered_compile_flags", - ], - tools = [tool(path = ctx.attr.msvc_cl_path)], - ) - - cpp_compile_action = action_config( - action_name = ACTION_NAMES.cpp_compile, - implies = [ - "compiler_input_flags", - "compiler_output_flags", - "nologo", - "msvc_env", - "user_compile_flags", - "sysroot", - ], - tools = [tool(path = ctx.attr.msvc_cl_path)], - ) - - cpp_link_executable_action = action_config( - action_name = ACTION_NAMES.cpp_link_executable, - implies = [ - "nologo", - "linkstamps", - "output_execpath_flags", - "input_param_flags", - "user_link_flags", - "linker_subsystem_flag", - "linker_param_file", - "msvc_env", - "no_stripping", - ], - tools = [tool(path = ctx.attr.msvc_link_path)], - ) - - cpp_link_dynamic_library_action = action_config( - action_name = ACTION_NAMES.cpp_link_dynamic_library, - implies = [ - "nologo", - "shared_flag", - "linkstamps", - "output_execpath_flags", - "input_param_flags", - "user_link_flags", - "linker_subsystem_flag", - "linker_param_file", - "msvc_env", - "no_stripping", - "has_configured_linker_path", - "def_file", - ], - tools = [tool(path = ctx.attr.msvc_link_path)], - ) - - deps_scanner = "cpp-module-deps-scanner_not_found" - if "cpp-module-deps-scanner" in ctx.attr.tool_paths: - deps_scanner = ctx.attr.tool_paths["cpp-module-deps-scanner"] - cpp_module_scan_deps = action_config( - action_name = ACTION_NAMES.cpp_module_deps_scanning, - tools = [ - tool( - path = deps_scanner, - ), - ], - implies = [ - "compiler_input_flags", - "compiler_output_flags", - "nologo", - "msvc_env", - "user_compile_flags", - "sysroot", - ], - ) - - cpp20_module_compile = action_config( - action_name = ACTION_NAMES.cpp20_module_compile, - tools = [ - tool( - path = ctx.attr.msvc_cl_path, - ), - ], - flag_sets = [ - flag_set( - flag_groups = [ - flag_group( - flags = [ - "/TP", - "/interface", - ], - ), - ], - ), - ], - implies = [ - "compiler_input_flags", - "compiler_output_flags", - "nologo", - "msvc_env", - "user_compile_flags", - "sysroot", - ], - ) - - cpp20_module_codegen = action_config( - action_name = ACTION_NAMES.cpp20_module_codegen, - tools = [ - tool( - path = ctx.attr.msvc_cl_path, - ), - ], - implies = [ - "compiler_input_flags", - "compiler_output_flags", - "nologo", - "msvc_env", - "user_compile_flags", - "sysroot", - ], - ) - action_configs = [ - assemble_action, - preprocess_assemble_action, - c_compile_action, - linkstamp_compile_action, - cpp_compile_action, - cpp_link_executable_action, - cpp_link_dynamic_library_action, - cpp_link_nodeps_dynamic_library_action, - cpp_link_static_library_action, - cpp_module_scan_deps, - cpp20_module_compile, - cpp20_module_codegen, - ] - else: - action_configs = [] - - if _use_msvc_toolchain(ctx): - msvc_link_env_feature = feature( - name = "msvc_link_env", - env_sets = [ - env_set( - actions = all_link_actions + - [ACTION_NAMES.cpp_link_static_library], - env_entries = [env_entry(key = "LIB", value = ctx.attr.msvc_env_lib)], - ), - ], - ) - - shared_flag_feature = feature( - name = "shared_flag", - flag_sets = [ - flag_set( - actions = [ - ACTION_NAMES.cpp_link_dynamic_library, - ACTION_NAMES.cpp_link_nodeps_dynamic_library, - ], - flag_groups = [flag_group(flags = ["/DLL"])], - ), - ], - ) - - determinism_feature = feature( - name = "determinism", - enabled = True, - flag_sets = [ - flag_set( - actions = [ACTION_NAMES.c_compile, ACTION_NAMES.cpp_compile], - flag_groups = [ - flag_group( - flags = [ - "/wd4117", - "-D__DATE__=\"redacted\"", - "-D__TIMESTAMP__=\"redacted\"", - "-D__TIME__=\"redacted\"", - ] + (["-Wno-builtin-macro-redefined"] if ctx.attr.compiler == "clang-cl" else []), - ), - ], - ), - ], - ) - - sysroot_feature = feature( - name = "sysroot", - flag_sets = [ - flag_set( - actions = [ - ACTION_NAMES.assemble, - ACTION_NAMES.preprocess_assemble, - ACTION_NAMES.c_compile, - ACTION_NAMES.linkstamp_compile, - ACTION_NAMES.cpp_compile, - ACTION_NAMES.cpp_header_parsing, - ACTION_NAMES.cpp_module_compile, - ACTION_NAMES.cpp_module_codegen, - ACTION_NAMES.cpp_module_deps_scanning, - ACTION_NAMES.cpp20_module_compile, - ACTION_NAMES.cpp20_module_codegen, - ACTION_NAMES.cpp_link_executable, - ACTION_NAMES.cpp_link_dynamic_library, - ACTION_NAMES.cpp_link_nodeps_dynamic_library, - ], - flag_groups = [ - flag_group( - flags = ["--sysroot=%{sysroot}"], - iterate_over = "sysroot", - expand_if_available = "sysroot", - ), - ], - ), - ], - ) - - unfiltered_compile_flags_feature = feature( - name = "unfiltered_compile_flags", - enabled = True, - flag_sets = [ - flag_set( - actions = [ - ACTION_NAMES.preprocess_assemble, - ACTION_NAMES.c_compile, - ACTION_NAMES.linkstamp_compile, - ACTION_NAMES.cpp_compile, - ACTION_NAMES.cpp_header_parsing, - ACTION_NAMES.cpp_module_compile, - ACTION_NAMES.cpp_module_codegen, - ACTION_NAMES.cpp_module_deps_scanning, - ACTION_NAMES.cpp20_module_compile, - ACTION_NAMES.cpp20_module_codegen, - ], - flag_groups = [ - flag_group( - flags = ["%{unfiltered_compile_flags}"], - iterate_over = "unfiltered_compile_flags", - expand_if_available = "unfiltered_compile_flags", - ), - ], - ), - ], - ) - - archive_param_file_feature = feature( - name = "archive_param_file", - enabled = True, - ) - - compiler_param_file_feature = feature( - name = "compiler_param_file", - enabled = True, - ) - - copy_dynamic_libraries_to_binary_feature = feature( - name = "copy_dynamic_libraries_to_binary", - ) - - input_param_flags_feature = feature( - name = "input_param_flags", - flag_sets = [ - flag_set( - actions = [ - ACTION_NAMES.cpp_link_dynamic_library, - ACTION_NAMES.cpp_link_nodeps_dynamic_library, - ], - flag_groups = [ - flag_group( - flags = ["/IMPLIB:%{interface_library_output_path}"], - expand_if_available = "interface_library_output_path", - ), - ], - ), - flag_set( - actions = all_link_actions, - flag_groups = [ - flag_group( - flags = ["%{libopts}"], - iterate_over = "libopts", - expand_if_available = "libopts", - ), - ], - ), - flag_set( - actions = all_link_actions + - [ACTION_NAMES.cpp_link_static_library], - flag_groups = [ - flag_group( - iterate_over = "libraries_to_link", - flag_groups = [ - flag_group( - iterate_over = "libraries_to_link.object_files", - flag_groups = [flag_group(flags = ["%{libraries_to_link.object_files}"])], - expand_if_equal = variable_with_value( - name = "libraries_to_link.type", - value = "object_file_group", - ), - ), - flag_group( - flag_groups = [flag_group(flags = ["%{libraries_to_link.name}"])], - expand_if_equal = variable_with_value( - name = "libraries_to_link.type", - value = "object_file", - ), - ), - flag_group( - flag_groups = [flag_group(flags = ["%{libraries_to_link.name}"])], - expand_if_equal = variable_with_value( - name = "libraries_to_link.type", - value = "interface_library", - ), - ), - flag_group( - flag_groups = [ - flag_group( - flags = ["%{libraries_to_link.name}"], - expand_if_false = "libraries_to_link.is_whole_archive", - ), - flag_group( - flags = ["/WHOLEARCHIVE:%{libraries_to_link.name}"], - expand_if_true = "libraries_to_link.is_whole_archive", - ), - ], - expand_if_equal = variable_with_value( - name = "libraries_to_link.type", - value = "static_library", - ), - ), - ], - expand_if_available = "libraries_to_link", - ), - ], - ), - ], - ) - - fastbuild_feature = feature( - name = "fastbuild", - flag_sets = [ - flag_set( - actions = [ACTION_NAMES.c_compile, ACTION_NAMES.cpp_compile], - flag_groups = [flag_group(flags = ["/Od", "/Z7"])], - ), - flag_set( - actions = all_link_actions, - flag_groups = [ - flag_group( - flags = [ctx.attr.fastbuild_mode_debug_flag, "/INCREMENTAL:NO"], - ), - ], - ), - ], - implies = ["generate_pdb_file"], - ) - - user_compile_flags_feature = feature( - name = "user_compile_flags", - flag_sets = [ - flag_set( - actions = [ - ACTION_NAMES.preprocess_assemble, - ACTION_NAMES.c_compile, - ACTION_NAMES.linkstamp_compile, - ACTION_NAMES.cpp_compile, - ACTION_NAMES.cpp_header_parsing, - ACTION_NAMES.cpp_module_compile, - ACTION_NAMES.cpp_module_codegen, - ACTION_NAMES.cpp_module_deps_scanning, - ACTION_NAMES.cpp20_module_compile, - ACTION_NAMES.cpp20_module_codegen, - ], - flag_groups = [ - flag_group( - flags = ["%{user_compile_flags}"], - iterate_over = "user_compile_flags", - expand_if_available = "user_compile_flags", - ), - ], - ), - ], - ) - - archiver_flags_feature = feature( - name = "archiver_flags", - flag_sets = [ - flag_set( - actions = [ACTION_NAMES.cpp_link_static_library], - flag_groups = [ - flag_group( - flags = ["/OUT:%{output_execpath}"], - expand_if_available = "output_execpath", - ), - flag_group( - flags = ["%{user_archiver_flags}"], - iterate_over = "user_archiver_flags", - expand_if_available = "user_archiver_flags", - ), - flag_group( - flags = ctx.attr.archiver_flags, - ), - ], - ), - ], - ) - - default_link_flags_feature = feature( - name = "default_link_flags", - enabled = True, - flag_sets = [ - flag_set( - actions = all_link_actions, - flag_groups = [flag_group(flags = ctx.attr.default_link_flags)], - ), - ], - ) - - static_link_msvcrt_feature = feature( - name = "static_link_msvcrt", - flag_sets = [ - flag_set( - actions = [ACTION_NAMES.c_compile, ACTION_NAMES.cpp_compile], - flag_groups = [flag_group(flags = ["/MT"])], - with_features = [with_feature_set(not_features = ["dbg"])], - ), - flag_set( - actions = [ACTION_NAMES.c_compile, ACTION_NAMES.cpp_compile], - flag_groups = [flag_group(flags = ["/MTd"])], - with_features = [with_feature_set(features = ["dbg"])], - ), - flag_set( - actions = all_link_actions, - flag_groups = [flag_group(flags = ["/DEFAULTLIB:libcmt.lib"])], - with_features = [with_feature_set(not_features = ["dbg"])], - ), - flag_set( - actions = all_link_actions, - flag_groups = [flag_group(flags = ["/DEFAULTLIB:libcmtd.lib"])], - with_features = [with_feature_set(features = ["dbg"])], - ), - ], - ) - - dynamic_link_msvcrt_feature = feature( - name = "dynamic_link_msvcrt", - enabled = True, - flag_sets = [ - flag_set( - actions = [ACTION_NAMES.c_compile, ACTION_NAMES.cpp_compile], - flag_groups = [flag_group(flags = ["/MD"])], - with_features = [with_feature_set(not_features = ["dbg", "static_link_msvcrt"])], - ), - flag_set( - actions = [ACTION_NAMES.c_compile, ACTION_NAMES.cpp_compile], - flag_groups = [flag_group(flags = ["/MDd"])], - with_features = [with_feature_set(features = ["dbg"], not_features = ["static_link_msvcrt"])], - ), - flag_set( - actions = all_link_actions, - flag_groups = [flag_group(flags = ["/DEFAULTLIB:msvcrt.lib"])], - with_features = [with_feature_set(not_features = ["dbg", "static_link_msvcrt"])], - ), - flag_set( - actions = all_link_actions, - flag_groups = [flag_group(flags = ["/DEFAULTLIB:msvcrtd.lib"])], - with_features = [with_feature_set(features = ["dbg"], not_features = ["static_link_msvcrt"])], - ), - ], - ) - - dbg_feature = feature( - name = "dbg", - flag_sets = [ - flag_set( - actions = [ACTION_NAMES.c_compile, ACTION_NAMES.cpp_compile], - flag_groups = [flag_group(flags = ["/Od", "/Z7"])], - ), - flag_set( - actions = all_link_actions, - flag_groups = [ - flag_group( - flags = [ctx.attr.dbg_mode_debug_flag, "/INCREMENTAL:NO"], - ), - ], - ), - ], - implies = ["generate_pdb_file"], - ) - - opt_feature = feature( - name = "opt", - flag_sets = [ - flag_set( - actions = [ACTION_NAMES.c_compile, ACTION_NAMES.cpp_compile], - flag_groups = [flag_group(flags = ["/O2"])], - ), - ], - implies = ["frame_pointer"], - ) - - supports_interface_shared_libraries_feature = feature( - name = "supports_interface_shared_libraries", - enabled = True, - ) - - user_link_flags_feature = feature( - name = "user_link_flags", - flag_sets = [ - flag_set( - actions = all_link_actions, - flag_groups = [ - flag_group( - flags = ["%{user_link_flags}"], - iterate_over = "user_link_flags", - expand_if_available = "user_link_flags", - ), - ], - ), - ], - ) - - default_compile_flags_feature = feature( - name = "default_compile_flags", - enabled = True, - flag_sets = [ - flag_set( - actions = [ - ACTION_NAMES.assemble, - ACTION_NAMES.preprocess_assemble, - ACTION_NAMES.linkstamp_compile, - ACTION_NAMES.c_compile, - ACTION_NAMES.cpp_compile, - ACTION_NAMES.cpp_header_parsing, - ACTION_NAMES.cpp_module_compile, - ACTION_NAMES.cpp_module_codegen, - ACTION_NAMES.cpp_module_deps_scanning, - ACTION_NAMES.cpp20_module_compile, - ACTION_NAMES.cpp20_module_codegen, - ACTION_NAMES.lto_backend, - ACTION_NAMES.clif_match, - ], - flag_groups = [ - flag_group( - flags = [ - "/DCOMPILER_MSVC", - "/DNOMINMAX", - "/D_WIN32_WINNT=0x0601", - "/D_CRT_SECURE_NO_DEPRECATE", - "/D_CRT_SECURE_NO_WARNINGS", - "/bigobj", - "/Zm500", - "/EHsc", - "/wd4351", - "/wd4291", - "/wd4250", - "/wd4996", - ], - ), - ], - ), - ], - ) - - msvc_compile_env_feature = feature( - name = "msvc_compile_env", - env_sets = [ - env_set( - actions = [ - ACTION_NAMES.c_compile, - ACTION_NAMES.linkstamp_compile, - ACTION_NAMES.cpp_compile, - ACTION_NAMES.cpp_module_compile, - ACTION_NAMES.cpp_module_codegen, - ACTION_NAMES.cpp_header_parsing, - ACTION_NAMES.cpp_module_deps_scanning, - ACTION_NAMES.cpp20_module_compile, - ACTION_NAMES.cpp20_module_codegen, - ACTION_NAMES.assemble, - ACTION_NAMES.preprocess_assemble, - ], - env_entries = [env_entry(key = "INCLUDE", value = ctx.attr.msvc_env_include)], - ), - ], - ) - - preprocessor_defines_feature = feature( - name = "preprocessor_defines", - enabled = True, - flag_sets = [ - flag_set( - actions = [ - ACTION_NAMES.assemble, - ACTION_NAMES.preprocess_assemble, - ACTION_NAMES.c_compile, - ACTION_NAMES.linkstamp_compile, - ACTION_NAMES.cpp_compile, - ACTION_NAMES.cpp_header_parsing, - ACTION_NAMES.cpp_module_compile, - ACTION_NAMES.cpp_module_deps_scanning, - ACTION_NAMES.cpp20_module_compile, - ], - flag_groups = [ - flag_group( - flags = ["/D%{preprocessor_defines}"], - iterate_over = "preprocessor_defines", - ), - ], - ), - ], - ) - - generate_pdb_file_feature = feature( - name = "generate_pdb_file", - ) - - generate_linkmap_feature = feature( - name = "generate_linkmap", - flag_sets = [ - flag_set( - actions = [ - ACTION_NAMES.cpp_link_executable, - ], - flag_groups = [ - flag_group( - flags = [ - "/MAP:%{output_execpath}.map", - ], - expand_if_available = "output_execpath", - ), - ], - ), - ], - ) - - output_execpath_flags_feature = feature( - name = "output_execpath_flags", - flag_sets = [ - flag_set( - actions = all_link_actions, - flag_groups = [ - flag_group( - flags = ["/OUT:%{output_execpath}"], - expand_if_available = "output_execpath", - ), - ], - ), - ], - ) - - disable_assertions_feature = feature( - name = "disable_assertions", - enabled = True, - flag_sets = [ - flag_set( - actions = [ACTION_NAMES.c_compile, ACTION_NAMES.cpp_compile], - flag_groups = [flag_group(flags = ["/DNDEBUG"])], - with_features = [with_feature_set(features = ["opt"])], - ), - ], - ) - - has_configured_linker_path_feature = feature(name = "has_configured_linker_path") - - supports_dynamic_linker_feature = feature(name = "supports_dynamic_linker", enabled = True) - - no_stripping_feature = feature(name = "no_stripping") - - linker_param_file_feature = feature( - name = "linker_param_file", - flag_sets = [ - flag_set( - actions = all_link_actions + - [ACTION_NAMES.cpp_link_static_library], - flag_groups = [ - flag_group( - flags = ["@%{linker_param_file}"], - expand_if_available = "linker_param_file", - ), - ], - ), - ], - ) - - ignore_noisy_warnings_feature = feature( - name = "ignore_noisy_warnings", - enabled = True, - flag_sets = [ - flag_set( - actions = [ACTION_NAMES.cpp_link_static_library], - flag_groups = [flag_group(flags = ["/ignore:4221"])], - ), - ], - ) - - no_legacy_features_feature = feature(name = "no_legacy_features") - - parse_showincludes_feature = feature( - name = "parse_showincludes", - enabled = ctx.attr.supports_parse_showincludes, - flag_sets = [ - flag_set( - actions = [ - ACTION_NAMES.preprocess_assemble, - ACTION_NAMES.c_compile, - ACTION_NAMES.linkstamp_compile, - ACTION_NAMES.cpp_compile, - ACTION_NAMES.cpp_module_compile, - ACTION_NAMES.cpp_header_parsing, - ACTION_NAMES.cpp_module_deps_scanning, - ACTION_NAMES.cpp20_module_compile, - ], - flag_groups = [flag_group(flags = ["/showIncludes"])], - ), - ], - env_sets = [ - env_set( - actions = [ - ACTION_NAMES.preprocess_assemble, - ACTION_NAMES.c_compile, - ACTION_NAMES.linkstamp_compile, - ACTION_NAMES.cpp_compile, - ACTION_NAMES.cpp_module_compile, - ACTION_NAMES.cpp_header_parsing, - ], - # Force English (and thus a consistent locale) output so that Bazel can parse - # the /showIncludes output without having to guess the encoding. - env_entries = [env_entry(key = "VSLANG", value = "1033")], - ), - ], - ) - - # MSVC does not emit .d files. - no_dotd_file_feature = feature( - name = "no_dotd_file", - enabled = True, - ) - - treat_warnings_as_errors_feature = feature( - name = "treat_warnings_as_errors", - flag_sets = [ - flag_set( - actions = [ACTION_NAMES.c_compile, ACTION_NAMES.cpp_compile] + all_link_actions, - flag_groups = [flag_group(flags = ["/WX"])], - ), - ], - ) - - windows_export_all_symbols_feature = feature(name = "windows_export_all_symbols") - - no_windows_export_all_symbols_feature = feature(name = "no_windows_export_all_symbols") - - include_paths_feature = feature( - name = "include_paths", - enabled = True, - flag_sets = [ - flag_set( - actions = [ - ACTION_NAMES.assemble, - ACTION_NAMES.preprocess_assemble, - ACTION_NAMES.c_compile, - ACTION_NAMES.linkstamp_compile, - ACTION_NAMES.cpp_compile, - ACTION_NAMES.cpp_header_parsing, - ACTION_NAMES.cpp_module_compile, - ], - flag_groups = [ - flag_group( - flags = ["/I%{quote_include_paths}"], - iterate_over = "quote_include_paths", - ), - flag_group( - flags = ["/I%{include_paths}"], - iterate_over = "include_paths", - ), - flag_group( - flags = ["/I%{system_include_paths}"], - iterate_over = "system_include_paths", - ), - ], - ), - ], - ) - - external_include_paths_feature = feature( - name = "external_include_paths", - flag_sets = [ - flag_set( - actions = [ - ACTION_NAMES.preprocess_assemble, - ACTION_NAMES.linkstamp_compile, - ACTION_NAMES.c_compile, - ACTION_NAMES.cpp_compile, - ACTION_NAMES.cpp_header_parsing, - ACTION_NAMES.cpp_module_compile, - ACTION_NAMES.cpp_module_deps_scanning, - ACTION_NAMES.cpp20_module_compile, - ACTION_NAMES.clif_match, - ACTION_NAMES.objc_compile, - ACTION_NAMES.objcpp_compile, - ], - flag_groups = [ - flag_group( - flags = ["/external:I%{external_include_paths}"], - iterate_over = "external_include_paths", - expand_if_available = "external_include_paths", - ), - ], - ), - ], - ) - - linkstamps_feature = feature( - name = "linkstamps", - flag_sets = [ - flag_set( - actions = all_link_actions, - flag_groups = [ - flag_group( - flags = ["%{linkstamp_paths}"], - iterate_over = "linkstamp_paths", - expand_if_available = "linkstamp_paths", - ), - ], - ), - ], - ) - - targets_windows_feature = feature( - name = "targets_windows", - enabled = True, - implies = ["copy_dynamic_libraries_to_binary"], - ) - - linker_subsystem_flag_feature = feature( - name = "linker_subsystem_flag", - flag_sets = [ - flag_set( - actions = all_link_actions, - flag_groups = [flag_group(flags = ["/SUBSYSTEM:CONSOLE"])], - ), - ], - ) - - frame_pointer_feature = feature( - name = "frame_pointer", - flag_sets = [ - flag_set( - actions = [ACTION_NAMES.c_compile, ACTION_NAMES.cpp_compile], - flag_groups = [flag_group(flags = ["/Oy-"])], - ), - ], - ) - - compiler_output_flags_feature = feature( - name = "compiler_output_flags", - flag_sets = [ - flag_set( - actions = [ACTION_NAMES.assemble], - flag_groups = [ - flag_group( - flag_groups = [ - flag_group( - flags = ["/Fo%{output_file}", "/Zi"], - expand_if_available = "output_file", - expand_if_not_available = "output_assembly_file", - ), - ], - expand_if_not_available = "output_preprocess_file", - ), - ], - ), - flag_set( - actions = [ - ACTION_NAMES.preprocess_assemble, - ACTION_NAMES.c_compile, - ACTION_NAMES.linkstamp_compile, - ACTION_NAMES.cpp_compile, - ACTION_NAMES.cpp_header_parsing, - ACTION_NAMES.cpp_module_compile, - ACTION_NAMES.cpp_module_codegen, - ACTION_NAMES.cpp_module_deps_scanning, - ACTION_NAMES.cpp20_module_compile, - ACTION_NAMES.cpp20_module_codegen, - ], - flag_groups = [ - flag_group( - flag_groups = [ - flag_group( - flags = ["/Fo%{output_file}"], - expand_if_not_available = "output_preprocess_file", - ), - ], - expand_if_available = "output_file", - expand_if_not_available = "output_assembly_file", - ), - flag_group( - flag_groups = [ - flag_group( - flags = ["/Fa%{output_file}"], - expand_if_available = "output_assembly_file", - ), - ], - expand_if_available = "output_file", - ), - flag_group( - flag_groups = [ - flag_group( - flags = ["/P", "/Fi%{output_file}"], - expand_if_available = "output_preprocess_file", - ), - ], - expand_if_available = "output_file", - ), - ], - ), - ], - ) - - nologo_feature = feature( - name = "nologo", - flag_sets = [ - flag_set( - actions = [ - ACTION_NAMES.c_compile, - ACTION_NAMES.linkstamp_compile, - ACTION_NAMES.cpp_compile, - ACTION_NAMES.cpp_module_compile, - ACTION_NAMES.cpp_module_codegen, - ACTION_NAMES.cpp_header_parsing, - ACTION_NAMES.cpp_module_deps_scanning, - ACTION_NAMES.cpp20_module_compile, - ACTION_NAMES.cpp20_module_codegen, - ACTION_NAMES.assemble, - ACTION_NAMES.preprocess_assemble, - ACTION_NAMES.cpp_link_executable, - ACTION_NAMES.cpp_link_dynamic_library, - ACTION_NAMES.cpp_link_nodeps_dynamic_library, - ACTION_NAMES.cpp_link_static_library, - ], - flag_groups = [flag_group(flags = ["/nologo"])], - ), - ], - ) - - smaller_binary_feature = feature( - name = "smaller_binary", - enabled = True, - flag_sets = [ - flag_set( - actions = [ACTION_NAMES.c_compile, ACTION_NAMES.cpp_compile], - flag_groups = [flag_group(flags = ["/Gy", "/Gw"])], - with_features = [with_feature_set(features = ["opt"])], - ), - flag_set( - actions = all_link_actions, - flag_groups = [flag_group(flags = ["/OPT:ICF", "/OPT:REF"])], - with_features = [with_feature_set(features = ["opt"])], - ), - ], - ) - - remove_unreferenced_code_feature = feature( - name = "remove_unreferenced_code", - enabled = True, - flag_sets = [ - flag_set( - actions = [ACTION_NAMES.c_compile, ACTION_NAMES.cpp_compile], - flag_groups = [flag_group(flags = ["/Zc:inline"])], - ), - ], - ) - - compiler_input_flags_feature = feature( - name = "compiler_input_flags", - flag_sets = [ - flag_set( - actions = [ - ACTION_NAMES.assemble, - ACTION_NAMES.preprocess_assemble, - ACTION_NAMES.c_compile, - ACTION_NAMES.linkstamp_compile, - ACTION_NAMES.cpp_compile, - ACTION_NAMES.cpp_header_parsing, - ACTION_NAMES.cpp_module_compile, - ACTION_NAMES.cpp_module_codegen, - ACTION_NAMES.cpp_module_deps_scanning, - ACTION_NAMES.cpp20_module_compile, - ACTION_NAMES.cpp20_module_codegen, - ], - flag_groups = [ - flag_group( - flags = ["/c", "%{source_file}"], - expand_if_available = "source_file", - ), - ], - ), - ], - ) - - def_file_feature = feature( - name = "def_file", - flag_sets = [ - flag_set( - actions = all_link_actions, - flag_groups = [ - flag_group( - flags = ["/DEF:%{def_file_path}", "/ignore:4070"], - expand_if_available = "def_file_path", - ), - ], - ), - ], - ) - - msvc_env_feature = feature( - name = "msvc_env", - env_sets = [ - env_set( - actions = [ - ACTION_NAMES.c_compile, - ACTION_NAMES.linkstamp_compile, - ACTION_NAMES.cpp_compile, - ACTION_NAMES.cpp_module_compile, - ACTION_NAMES.cpp_module_codegen, - ACTION_NAMES.cpp_header_parsing, - ACTION_NAMES.cpp_module_deps_scanning, - ACTION_NAMES.cpp20_module_compile, - ACTION_NAMES.cpp20_module_codegen, - ACTION_NAMES.assemble, - ACTION_NAMES.preprocess_assemble, - ACTION_NAMES.cpp_link_executable, - ACTION_NAMES.cpp_link_dynamic_library, - ACTION_NAMES.cpp_link_nodeps_dynamic_library, - ACTION_NAMES.cpp_link_static_library, - ], - env_entries = [ - env_entry(key = "PATH", value = ctx.attr.msvc_env_path), - env_entry(key = "TMP", value = ctx.attr.msvc_env_tmp), - env_entry(key = "TEMP", value = ctx.attr.msvc_env_tmp), - ], - ), - ], - implies = ["msvc_compile_env", "msvc_link_env"], - ) - - symbol_check_feature = feature( - name = "symbol_check", - flag_sets = [ - flag_set( - actions = [ACTION_NAMES.cpp_link_static_library], - flag_groups = [flag_group(flags = ["/WX:4006"])], - ), - ], - ) - - features = [ - no_legacy_features_feature, - nologo_feature, - has_configured_linker_path_feature, - no_stripping_feature, - targets_windows_feature, - copy_dynamic_libraries_to_binary_feature, - default_compile_flags_feature, - msvc_env_feature, - msvc_compile_env_feature, - msvc_link_env_feature, - include_paths_feature, - external_include_paths_feature, - preprocessor_defines_feature, - parse_showincludes_feature, - no_dotd_file_feature, - generate_pdb_file_feature, - generate_linkmap_feature, - shared_flag_feature, - linkstamps_feature, - output_execpath_flags_feature, - archiver_flags_feature, - input_param_flags_feature, - linker_subsystem_flag_feature, - user_link_flags_feature, - default_link_flags_feature, - linker_param_file_feature, - static_link_msvcrt_feature, - dynamic_link_msvcrt_feature, - dbg_feature, - fastbuild_feature, - opt_feature, - frame_pointer_feature, - disable_assertions_feature, - determinism_feature, - treat_warnings_as_errors_feature, - smaller_binary_feature, - remove_unreferenced_code_feature, - ignore_noisy_warnings_feature, - user_compile_flags_feature, - sysroot_feature, - unfiltered_compile_flags_feature, - archive_param_file_feature, - compiler_param_file_feature, - compiler_output_flags_feature, - compiler_input_flags_feature, - def_file_feature, - windows_export_all_symbols_feature, - no_windows_export_all_symbols_feature, - supports_dynamic_linker_feature, - supports_interface_shared_libraries_feature, - symbol_check_feature, - ] - else: - targets_windows_feature = feature( - name = "targets_windows", - implies = ["copy_dynamic_libraries_to_binary"], - enabled = True, - ) - - copy_dynamic_libraries_to_binary_feature = feature(name = "copy_dynamic_libraries_to_binary") - - gcc_env_feature = feature( - name = "gcc_env", - enabled = True, - env_sets = [ - env_set( - actions = [ - ACTION_NAMES.c_compile, - ACTION_NAMES.linkstamp_compile, - ACTION_NAMES.cpp_compile, - ACTION_NAMES.cpp_module_compile, - ACTION_NAMES.cpp_module_codegen, - ACTION_NAMES.cpp_header_parsing, - ACTION_NAMES.cpp_module_deps_scanning, - ACTION_NAMES.cpp20_module_compile, - ACTION_NAMES.cpp20_module_codegen, - ACTION_NAMES.assemble, - ACTION_NAMES.preprocess_assemble, - ACTION_NAMES.cpp_link_executable, - ACTION_NAMES.cpp_link_dynamic_library, - ACTION_NAMES.cpp_link_nodeps_dynamic_library, - ACTION_NAMES.cpp_link_static_library, - ], - env_entries = [ - env_entry(key = "PATH", value = ctx.attr.tool_bin_path), - ], - ), - ], - ) - - default_compile_flags_feature = feature( - name = "default_compile_flags", - enabled = True, - flag_sets = [ - flag_set( - actions = [ - ACTION_NAMES.linkstamp_compile, - ACTION_NAMES.cpp_compile, - ACTION_NAMES.cpp_header_parsing, - ACTION_NAMES.cpp_module_compile, - ACTION_NAMES.cpp_module_codegen, - ACTION_NAMES.cpp_module_deps_scanning, - ACTION_NAMES.cpp20_module_compile, - ACTION_NAMES.cpp20_module_codegen, - ACTION_NAMES.lto_backend, - ACTION_NAMES.clif_match, - ], - flag_groups = [flag_group(flags = ["-std=gnu++14"] + ctx.attr.default_compile_flags)], - ), - ], - ) - - default_link_flags_feature = feature( - name = "default_link_flags", - enabled = True, - flag_sets = [ - flag_set( - actions = all_link_actions, - flag_groups = [flag_group(flags = ["-lstdc++"] + ctx.attr.default_link_flags)], - ), - ], - ) - - supports_dynamic_linker_feature = feature( - name = "supports_dynamic_linker", - enabled = True, - ) - - dbg_feature = feature( - name = "dbg", - flag_sets = [ - flag_set( - actions = [ACTION_NAMES.c_compile, ACTION_NAMES.cpp_compile], - flag_groups = [flag_group(flags = ["-g", "-Og"])], - ), - ], - ) - - opt_feature = feature( - name = "opt", - flag_sets = [ - flag_set( - actions = [ACTION_NAMES.c_compile, ACTION_NAMES.cpp_compile], - flag_groups = [flag_group(flags = [ - "-g0", - "-O3", - "-DNDEBUG", - "-ffunction-sections", - "-fdata-sections", - ])], - ), - flag_set( - actions = all_link_actions, - flag_groups = [flag_group(flags = ["-Wl,--gc-sections"])], - ), - ], - ) - - if ctx.attr.cpu == "x64_windows" and ctx.attr.compiler == "mingw-gcc": - archive_param_file_feature = feature( - name = "archive_param_file", - enabled = True, - ) - - compiler_param_file_feature = feature( - name = "compiler_param_file", - ) - - features = [ - targets_windows_feature, - copy_dynamic_libraries_to_binary_feature, - gcc_env_feature, - default_compile_flags_feature, - archive_param_file_feature, - compiler_param_file_feature, - default_link_flags_feature, - supports_dynamic_linker_feature, - dbg_feature, - opt_feature, - ] - else: - supports_pic_feature = feature( - name = "supports_pic", - enabled = True, - ) - - sysroot_feature = feature( - name = "sysroot", - enabled = True, - flag_sets = [ - flag_set( - actions = [ - ACTION_NAMES.preprocess_assemble, - ACTION_NAMES.linkstamp_compile, - ACTION_NAMES.c_compile, - ACTION_NAMES.cpp_compile, - ACTION_NAMES.cpp_header_parsing, - ACTION_NAMES.cpp_module_compile, - ACTION_NAMES.cpp_module_codegen, - ACTION_NAMES.cpp_module_deps_scanning, - ACTION_NAMES.cpp20_module_compile, - ACTION_NAMES.cpp20_module_codegen, - ACTION_NAMES.lto_backend, - ACTION_NAMES.clif_match, - ACTION_NAMES.cpp_link_executable, - ACTION_NAMES.cpp_link_dynamic_library, - ACTION_NAMES.cpp_link_nodeps_dynamic_library, - ], - flag_groups = [ - flag_group( - flags = ["--sysroot=%{sysroot}"], - expand_if_available = "sysroot", - ), - ], - ), - ], - ) - - fdo_optimize_feature = feature( - name = "fdo_optimize", - flag_sets = [ - flag_set( - actions = [ACTION_NAMES.c_compile, ACTION_NAMES.cpp_compile], - flag_groups = [ - flag_group( - flags = [ - "-fprofile-use=%{fdo_profile_path}", - "-fprofile-correction", - ], - expand_if_available = "fdo_profile_path", - ), - ], - ), - ], - provides = ["profile"], - ) - - treat_warnings_as_errors_feature = feature( - name = "treat_warnings_as_errors", - flag_sets = [ - flag_set( - actions = [ACTION_NAMES.c_compile, ACTION_NAMES.cpp_compile], - flag_groups = [flag_group(flags = ["-Werror"])], - ), - flag_set( - actions = all_link_actions, - flag_groups = [flag_group(flags = ["-Wl,-fatal-warnings"])], - ), - ], - ) - - user_compile_flags_feature = feature( - name = "user_compile_flags", - enabled = True, - flag_sets = [ - flag_set( - actions = [ - ACTION_NAMES.assemble, - ACTION_NAMES.preprocess_assemble, - ACTION_NAMES.linkstamp_compile, - ACTION_NAMES.c_compile, - ACTION_NAMES.cpp_compile, - ACTION_NAMES.cpp_header_parsing, - ACTION_NAMES.cpp_module_compile, - ACTION_NAMES.cpp_module_codegen, - ACTION_NAMES.cpp_module_deps_scanning, - ACTION_NAMES.cpp20_module_compile, - ACTION_NAMES.cpp20_module_codegen, - ACTION_NAMES.lto_backend, - ACTION_NAMES.clif_match, - ], - flag_groups = [ - flag_group( - flags = ["%{user_compile_flags}"], - iterate_over = "user_compile_flags", - expand_if_available = "user_compile_flags", - ), - ], - ), - ], - ) - - features = [ - targets_windows_feature, - copy_dynamic_libraries_to_binary_feature, - gcc_env_feature, - supports_pic_feature, - default_compile_flags_feature, - default_link_flags_feature, - fdo_optimize_feature, - supports_dynamic_linker_feature, - dbg_feature, - opt_feature, - user_compile_flags_feature, - treat_warnings_as_errors_feature, - sysroot_feature, - ] - - tool_paths = [ - tool_path(name = name, path = path) - for name, path in ctx.attr.tool_paths.items() - ] - - make_variables = [] - - # dumpbin.exe is not available in MSYS toolchain - if "dumpbin" in ctx.attr.tool_paths: - make_variables.append(make_variable(name = "DUMPBIN", value = ctx.attr.tool_paths["dumpbin"])) - - # Tell bazel we support C++ modules now - cpp_modules_feature = feature( - name = "cpp_modules", - # set default value to False - # to enable the feature - # use --features=cpp_modules - # or add cpp_modules to features attr - enabled = False, - ) - - cpp_module_modmap_file_feature = feature( - name = "cpp_module_modmap_file", - flag_sets = [ - flag_set( - actions = [ - ACTION_NAMES.cpp_compile, - ACTION_NAMES.cpp20_module_compile, - ACTION_NAMES.cpp20_module_codegen, - ], - flag_groups = [ - flag_group( - flags = ["@%{cpp_module_modmap_file}"], - expand_if_available = "cpp_module_modmap_file", - ), - ], - ), - ], - enabled = True, - ) - cpp20_module_compile_flags_feature = feature( - name = "cpp20_module_compile_flags", - flag_sets = [ - flag_set( - actions = [ - ACTION_NAMES.cpp20_module_compile, - ], - flag_groups = [ - flag_group( - flags = ["/ifcOutput%{cpp_module_output_file}"], - expand_if_available = "cpp_module_output_file", - ), - ], - ), - ], - enabled = True, - ) - return cc_common.create_cc_toolchain_config_info( - ctx = ctx, - features = features + [cpp_modules_feature, cpp_module_modmap_file_feature, cpp20_module_compile_flags_feature], - action_configs = action_configs, - artifact_name_patterns = artifact_name_patterns, - cxx_builtin_include_directories = ctx.attr.cxx_builtin_include_directories, - toolchain_identifier = ctx.attr.toolchain_identifier, - host_system_name = ctx.attr.host_system_name, - target_system_name = ctx.attr.target_system_name, - target_cpu = ctx.attr.cpu, - target_libc = ctx.attr.target_libc, - compiler = ctx.attr.compiler, - abi_version = ctx.attr.abi_version, - abi_libc_version = ctx.attr.abi_libc_version, - tool_paths = tool_paths, - make_variables = make_variables, - ) - -cc_toolchain_config = rule( - implementation = _impl, - attrs = { - "cpu": attr.string(mandatory = True), - "compiler": attr.string(), - "toolchain_identifier": attr.string(), - "host_system_name": attr.string(), - "target_system_name": attr.string(), - "target_libc": attr.string(), - "abi_version": attr.string(), - "abi_libc_version": attr.string(), - "tool_paths": attr.string_dict(), - "cxx_builtin_include_directories": attr.string_list(), - "archiver_flags": attr.string_list(default = []), - "default_compile_flags": attr.string_list(default = []), - "default_link_flags": attr.string_list(default = []), - "msvc_env_tmp": attr.string(default = "msvc_not_found"), - "msvc_env_path": attr.string(default = "msvc_not_found"), - "msvc_env_include": attr.string(default = "msvc_not_found"), - "msvc_env_lib": attr.string(default = "msvc_not_found"), - "msvc_cl_path": attr.string(default = "vc_installation_error.bat"), - "msvc_ml_path": attr.string(default = "vc_installation_error.bat"), - "msvc_link_path": attr.string(default = "vc_installation_error.bat"), - "msvc_lib_path": attr.string(default = "vc_installation_error.bat"), - "dbg_mode_debug_flag": attr.string(default = ""), - "fastbuild_mode_debug_flag": attr.string(default = ""), - "tool_bin_path": attr.string(default = "not_found"), - "supports_parse_showincludes": attr.bool(), - }, - provides = [CcToolchainConfigInfo], -) diff --git a/workspace_deps.bzl b/workspace_deps.bzl index 3535af79e857a8..bc4296111bce06 100644 --- a/workspace_deps.bzl +++ b/workspace_deps.bzl @@ -19,10 +19,10 @@ WORKSPACE_REPOS = { # Used in src/main/java/com/google/devtools/build/lib/bazel/rules/java/jdk.WORKSPACE. # Used in src/test/java/com/google/devtools/build/lib/blackbox/framework/blackbox.WORKSAPCE "rules_cc": { - "archive": "rules_cc-0.0.10.tar.gz", - "sha256": "65b67b81c6da378f136cc7e7e14ee08d5b9375973427eceb8c773a4f69fa7e49", - "urls": ["https://github.com/bazelbuild/rules_cc/releases/download/0.0.10/rules_cc-0.0.10.tar.gz"], - "strip_prefix": "rules_cc-0.0.10", + "archive": "rules_cc-0.0.12.tar.gz", + "sha256": "b26168b9a13f094794982b832975eaf53cefc5dced5b3be7df6b8b794dc2744b", + "urls": ["https://github.com/bazelbuild/rules_cc/releases/download/0.0.12/rules_cc-0.0.12.tar.gz"], + "strip_prefix": "rules_cc-0.0.12", }, "protobuf": { "archive": "v27.0.zip",