diff --git a/appimage/README.md b/appimage/README.md index 13ea4f7644..99e7f4d1f3 100644 --- a/appimage/README.md +++ b/appimage/README.md @@ -101,6 +101,9 @@ Build for arm64 from any Linux host: bazel build //pkg:app --platforms=//appimage/platforms:linux_arm64 ``` +Or set `platform = "//appimage/platforms:linux_arm64"` on the target. Unset uses the +current target platform. + The image is packaged from the arm64 target bytes. Running it needs an arm64 Linux host. diff --git a/appimage/defs.bzl b/appimage/defs.bzl index 81ec9fdae1..103ccbf0d5 100644 --- a/appimage/defs.bzl +++ b/appimage/defs.bzl @@ -1,7 +1,8 @@ """Linux AppImage packaging for target binaries.""" load("//appimage:pins.bzl", "MKSQUASHFS_VERSION", "RUNTIME_VERSION", "TOOL_VERSION") -load("//libs/starlark:packaging.bzl", "claim_dest", "data_path", "platform_arch") +load("//libs/starlark:packaging.bzl", "claim_dest", "data_path") +load("//libs/starlark:platform.bzl", "PLATFORM_ATTRS", "platform_identity", "platform_transition") load(":validate.bzl", "appimage_name_errors") AppImageInfo = provider( @@ -25,11 +26,8 @@ def _add(ctx, args, inputs, seen, kind, dest, arg, file): inputs.append(file) def _appimage_impl(ctx): - cv = platform_common.ConstraintValueInfo - arch = platform_arch(ctx.target_platform_has_constraint, ctx.attr._linux[cv], [ - ("aarch64", ctx.attr._arm64[cv]), - ("x86_64", ctx.attr._x86_64[cv]), - ]) + identity = platform_identity(ctx) + arch = identity.cpu if identity.os == "linux" else "" if not arch: fail("appimage_package " + str(ctx.label) + ": target cell this platform is unsupported: only linux_x86_64 and linux_arm64 are pinned") name = ctx.attr.app_name or ctx.label.name @@ -102,14 +100,12 @@ _appimage_package = rule( "libs": attr.label_list(doc = "Shared libraries placed under usr/lib.", allow_files = True), "notice": attr.label_list(doc = "License and NOTICE files placed under usr/share/licenses/.", allow_files = True, mandatory = True, allow_empty = False), "version": attr.string(doc = "Application version.", mandatory = True), - "_arm64": attr.label(default = "@platforms//cpu:arm64"), "_build": attr.label(default = "//appimage/packer:appimage_packer", executable = True, cfg = "exec"), - "_linux": attr.label(default = "@platforms//os:linux"), "_runtime_aarch64": attr.label(default = "@dx_appimage_tools//:runtime_aarch64", allow_single_file = True), "_runtime_x86_64": attr.label(default = "@dx_appimage_tools//:runtime_x86_64", allow_single_file = True), "_tools": attr.label(doc = "The appimagetool closure.", cfg = "exec", default = "@dx_appimage_tools//:tools"), - "_x86_64": attr.label(default = "@platforms//cpu:x86_64"), - }, + } | PLATFORM_ATTRS, + cfg = platform_transition, ) def appimage_package(name, target_compatible_with = [], **kwargs): diff --git a/docs/cli/commands/generate.md b/docs/cli/commands/generate.md index bc6eb2ae4a..e42707b969 100644 --- a/docs/cli/commands/generate.md +++ b/docs/cli/commands/generate.md @@ -76,7 +76,7 @@ Set directives as `# gazelle: ` comments in a `BUILD` file. They ap | `dx_external []` | Name the manifest or lockfile that third-party imports resolve through. | | `dx_rust_corpus true\|false` | Turn the Rust corpus targets on or off. | | `dx_rust_crates_hub ` | Load `aliases` and `all_crate_deps` for Cargo packages from the crate_universe hub `@` instead of `@crates`. The package needs a `BUILD` file. | -| `dx_cuda_platforms ...` | Set `platforms` of a generated `cuda_library`. Required for `.cu` and `.cuh` files. | +| `dx_cuda_archs ...` | Set `cuda_archs` of a generated `cuda_library`. Required for `.cu` and `.cuh` files. | | `dx_fixture_testonly true\|false` | Mark generated libraries under a `tests/`, `fixtures/` or `testdata/` directory `testonly`. Off by default. Inherited by child packages. | | `lang ` | Must list `dx_dispatch`, for example `go,dx_dispatch`. | diff --git a/families/android/README.md b/families/android/README.md index a520ad6dba..33f87d3834 100644 --- a/families/android/README.md +++ b/families/android/README.md @@ -123,7 +123,8 @@ rust_android_apk( The package links one `lib//lib_bin.so` per ABI from the static native deps and signs the APK with the debug key. Builds never use a release key. Build `:app_apk` for the installable `app_apk.apk`; -it selects the platforms named in `platforms`, and an unknown ABI fails. The +it builds for the platform labels in `platforms`, `//platforms:arm64-v8a` and +`//platforms:x86_64` by default, and any other label fails. Do not set it with `select()`. The native deps need `alwayslink = True` so `ANativeActivity_onCreate` stays exported, and `-landroid -llog` as link options when they use the NDK APIs. The default manifest launches a `NativeActivity` loading that @@ -226,7 +227,7 @@ load("@rules_dx_android//packaging:defs.bzl", "android_check") android_check( name = "aab_check", package = ":app_apk_aab_file", - platforms = ["arm64-v8a", "x86_64"], + platforms = ["@rules_dx_android//platforms:arm64-v8a", "@rules_dx_android//platforms:x86_64"], resources = ["string/app_name"], ) ``` @@ -234,7 +235,7 @@ android_check( | Attribute | Default | Meaning | | --- | --- | --- | | `package` | required | The `.apk` or `.aab` to check. | -| `platforms` | `[]` | ABIs that must ship a `base/lib//*.so`. App Bundles only. | +| `platforms` | `[]` | Platform labels whose ABI must ship a `base/lib//*.so`. App Bundles only. | | `resources` | `[]` | `type/name` resources the bundle must resolve. App Bundles only. | | `size`, `tags`, `visibility` | `"small"`, none, none | Passed to the test. | diff --git a/families/android/packaging/BUILD.bazel b/families/android/packaging/BUILD.bazel index c8a2af7711..c926471f68 100644 --- a/families/android/packaging/BUILD.bazel +++ b/families/android/packaging/BUILD.bazel @@ -76,19 +76,19 @@ failure_test( rust_android_apk( name = "bad_abi", app_id = "com.example.app", - platforms = ["mips"], + platforms = ["//platforms:mips"], deps = [], ) failure_test( name = "bad_abi_test", - expected_failure_substring = "abi 'mips' is unknown", + expected_failure_substring = "//platforms:mips' is unknown", target = ":bad_abi", ) failure_test( name = "bad_abi_aab_file_test", - expected_failure_substring = "abi 'mips' is unknown", + expected_failure_substring = "//platforms:mips' is unknown", target = ":bad_abi_aab_file", ) @@ -129,8 +129,8 @@ rust_android_apk( name = "bad_dup_abis", app_id = "com.example.app", platforms = [ - "x86_64", - "x86_64", + "//platforms:x86_64", + "//platforms:x86_64", ], deps = [], ) @@ -246,13 +246,13 @@ failure_test( android_check( name = "bad_abi_aab_check", package = "//tests/fixtures/rust_apk:dummy.apk", - platforms = ["mips"], + platforms = ["//platforms:mips"], tags = ["manual"], ) failure_test( name = "bad_abi_aab_check_test", - expected_failure_substring = "abi 'mips' is unknown", + expected_failure_substring = "//platforms:mips' is unknown", target = ":bad_abi_aab_check_selection", ) diff --git a/families/android/packaging/defs.bzl b/families/android/packaging/defs.bzl index fb36ec6032..2e9e04a838 100644 --- a/families/android/packaging/defs.bzl +++ b/families/android/packaging/defs.bzl @@ -9,7 +9,7 @@ load("@rules_shell//shell:sh_binary.bzl", "sh_binary") load("@rules_shell//shell:sh_test.bzl", "sh_test") load("//platforms:defs.bzl", "api_floor") load("//sdk:repos.bzl", "BUILD_TOOLS", "SDK_PLATFORM") -load(":repos.bzl", "abi_errors", "abi_platforms", "app_id_errors", "manifest_lib_name") +load(":repos.bzl", "ABI_PLATFORMS", "abi_errors", "abi_platforms", "app_id_errors", "manifest_lib_name") load(":validate.bzl", "android_aab_check_errors", "android_apk_manifest_errors", "android_apk_set_errors", "android_release_sign_errors", "rust_android_apk_errors") _TARGET_SDK = SDK_PLATFORM.removeprefix("android-") @@ -141,11 +141,19 @@ _apk_manifest = rule( outputs = {"manifest": "%{name}.xml"}, ) +def abis_for_platforms(platforms): + """Returns the ABI name of each platform label; an unknown label stays as its text for abi_errors.""" + if type(platforms) != "list": + return platforms + by_label = {label: abi for abi, label in ABI_PLATFORMS.items()} + labels = [str(native.package_relative_label(platform)) for platform in platforms] + return [by_label.get(label, label) for label in labels] + def rust_android_apk( name, app_id, deps, - platforms = ["arm64-v8a", "x86_64"], + platforms = [Label("//platforms:arm64-v8a"), Label("//platforms:x86_64")], activity = "android.app.NativeActivity", api_level = 0, assets = [], @@ -161,11 +169,12 @@ def rust_android_apk( **kwargs): """Packages one APK and one unsigned App Bundle from native CcInfo deps with a Rust entry point.""" inner = ":" + name + "_bin" + abis = abis_for_platforms(platforms) package = custom_package if custom_package != "" else app_id effective_api = api_level if api_level != 0 else api_floor() _apk_validation( name = name + "_validation", - abis = platforms, + abis = abis, api_level = api_level, apk_name = name, app_id = app_id, @@ -200,8 +209,8 @@ def rust_android_apk( tags = ["manual"], visibility = visibility, ) - plain = not _has_select([platforms, app_id, api_level, version_code]) - invalid = plain and len(rust_android_apk_errors(name, app_id, platforms, api_level, version_code)) > 0 + plain = not _has_select([abis, app_id, api_level, version_code]) + invalid = plain and len(rust_android_apk_errors(name, app_id, abis, api_level, version_code)) > 0 android_application( name = name + "_bundle", base_module = inner, @@ -212,7 +221,7 @@ def rust_android_apk( ) _aab_file( name = name + "_aab_file", - abis = platforms, + abis = abis, src = None if invalid else ":" + name + "_bundle", validation = ":" + name + "_validation", tags = ["manual"], @@ -233,7 +242,7 @@ def rust_android_apk( ) _rust_android_apk( name = name, - abis = platforms, + abis = abis, binary = None if invalid else inner, testonly = testonly, validation = ":" + name + "_validation", @@ -640,17 +649,18 @@ _check_selection = rule( def android_check(name, package, platforms = [], resources = [], size = "small", tags = None, target_compatible_with = None, visibility = None): """Declares a test that the package is an unsigned APK or a valid App Bundle.""" + abis = abis_for_platforms(platforms) _check_selection( name = name + "_selection", package = package, - abis = platforms, + abis = abis, resources = resources, tags = ["manual"], target_compatible_with = target_compatible_with, visibility = ["//visibility:private"], ) args = ["$(rootpath " + str(_BUNDLETOOL) + ")", "$(rootpath " + package + ")"] - for abi in platforms: + for abi in abis: args.extend(["--abi", abi]) for resource in resources: args.extend(["--resource", resource]) diff --git a/families/android/tests/fixtures/consumer_android/BUILD.bazel b/families/android/tests/fixtures/consumer_android/BUILD.bazel index 198631f591..24cd19074e 100644 --- a/families/android/tests/fixtures/consumer_android/BUILD.bazel +++ b/families/android/tests/fixtures/consumer_android/BUILD.bazel @@ -36,8 +36,8 @@ cc_library( rust_android_apk( name = "consumer_android_apk", platforms = [ - "arm64-v8a", - "x86_64", + "@rules_dx_android//platforms:arm64-v8a", + "@rules_dx_android//platforms:x86_64", ], api_level = 31, app_id = "com.example.consumer_android", diff --git a/families/android/tests/fixtures/rust_apk/BUILD.bazel b/families/android/tests/fixtures/rust_apk/BUILD.bazel index a81ac13789..47be3c3499 100644 --- a/families/android/tests/fixtures/rust_apk/BUILD.bazel +++ b/families/android/tests/fixtures/rust_apk/BUILD.bazel @@ -56,7 +56,7 @@ rust_android_apk( assets = glob(["assets/**"]), assets_dir = "assets", permissions = ["android.permission.INTERNET"], - platforms = ["arm64-v8a"], + platforms = ["//platforms:arm64-v8a"], resource_files = glob(["res/**"]), deps = [":app_jni"], ) @@ -96,7 +96,7 @@ genrule( android_check( name = "check_test_bundle_test", package = ":test_bundle.aab", - platforms = ["x86_64"], + platforms = ["//platforms:x86_64"], ) android_apk_set( @@ -149,7 +149,7 @@ rust_android_apk( "android.permission.ACCESS_NETWORK_STATE", "android.permission.VIBRATE", ], - platforms = ["x86_64"], + platforms = ["//platforms:x86_64"], resource_files = glob(["res/**"]), version_code = 7, version_name = "2.3", @@ -248,8 +248,8 @@ android_check( name = "check_app_aab_test", package = ":app_apk_aab_file", platforms = [ - "arm64-v8a", - "x86_64", + "//platforms:arm64-v8a", + "//platforms:x86_64", ], resources = ["string/app_name"], target_compatible_with = [ @@ -270,8 +270,8 @@ android_check( name = "check_app_aab_starlark_flag_test", package = ":app_apk_aab_file_x86_64_flag", platforms = [ - "arm64-v8a", - "x86_64", + "//platforms:arm64-v8a", + "//platforms:x86_64", ], target_compatible_with = [ "@platforms//os:linux", diff --git a/families/apple/BUILD.bazel b/families/apple/BUILD.bazel index 670efe6d57..c81bad4e88 100644 --- a/families/apple/BUILD.bazel +++ b/families/apple/BUILD.bazel @@ -15,6 +15,7 @@ filegroup( "//bundle:module_srcs", "//ios:module_srcs", "//macos:module_srcs", + "//platforms:module_srcs", "//provisioning:module_srcs", "//signing:module_srcs", ], @@ -41,12 +42,13 @@ sh_test( "//bundle:corpus_starlark", "//ios:corpus_starlark", "//macos:corpus_starlark", + "//platforms:corpus_starlark", "//provisioning:corpus_starlark", "//signing:corpus_starlark", "//tests:corpus_starlark", "@rules_dx//tools/ci:starlark_docs_family_test", ], - env = {"STARLARK_DOCS_PACKAGES": "bundle,ios,macos,provisioning,signing,tests"}, + env = {"STARLARK_DOCS_PACKAGES": "bundle,ios,macos,platforms,provisioning,signing,tests"}, ) # dx:begin exports diff --git a/families/apple/README.md b/families/apple/README.md index ddb7e9b0c2..ce6d89d771 100644 --- a/families/apple/README.md +++ b/families/apple/README.md @@ -540,7 +540,7 @@ rust_static_library( apple_macos_app( name = "ledger", srcs = ["main.m"], - platforms = ["arm64"], + platform = "@rules_dx_apple//platforms:macos_arm64", bundle_id = "com.example.ledger", version = "1.0", deployment = "14.0", @@ -550,6 +550,12 @@ apple_macos_app( ) ``` +`platform` is optional and defaults to the current target platform. It names the +platform the selection and check rules read the arch from; only `macos_arm64` is +accepted. It does not change the platform the bundle is built for: build with +`--platforms` or `--macos_cpus`. An x86_64 macOS target platform fails with +"arch 'x86_64' is outside macos", where the app used to default to arm64. + `srcs` holds the native entry point. `library` is any target with `CcInfo` that links one static archive, such as `rust_static_library`. The app needs `srcs`, `library`, or both. `frameworks` takes frameworks @@ -612,7 +618,7 @@ Building signs ad hoc only, whatever `--macos_signing_cert_name` says. Failures read: -- `apple_macos_app: platforms takes one of arm64` +- `apple_macos_app: arch 'x86_64' is outside macos: want arm64` - `apple_macos_app: deployment '13.0' is below 14.0` - `apple_macos_app: plugin '//app:empty' places nothing under PlugIns` - `apple_macos_app: deployment '16.0' is above the Xcode 16 'macosx' ceiling 15.0` diff --git a/families/apple/macos/BUILD.bazel b/families/apple/macos/BUILD.bazel index f3923082f2..bf4947f7cb 100644 --- a/families/apple/macos/BUILD.bazel +++ b/families/apple/macos/BUILD.bazel @@ -117,14 +117,14 @@ apple_macos_app( srcs = ["main.m"], bundle_id = "com.example.ledger", deployment = "14.0", - platforms = ["x86_64"], + platform = "//platforms:macos_x86_64", tags = ["manual"], version = "1.0", ) failure_test( name = "x86_app_test", - expected_failure_substring = "apple_macos_app: platforms takes one of arm64", + expected_failure_substring = "apple_macos_app: arch 'x86_64' is outside macos: want arm64", target = ":x86_app_selection", ) diff --git a/families/apple/macos/app.bzl b/families/apple/macos/app.bzl index b211ab3753..01a9c62236 100644 --- a/families/apple/macos/app.bzl +++ b/families/apple/macos/app.bzl @@ -7,11 +7,11 @@ load("@rules_apple//apple:versioning.bzl", "apple_bundle_version") load("@rules_cc//cc:objc_library.bzl", "objc_library") load("@rules_cc//cc/common:cc_common.bzl", "cc_common") load("@rules_cc//cc/common:cc_info.bzl", "CcInfo") +load("@rules_dx//libs/starlark:platform.bzl", "PLATFORM_ATTRS", "platform_identity") load("@rules_dx//libs/starlark:resources.bzl", "dx_heavy_resources") load("@rules_dx//libs/starlark:rlocation.bzl", "rlocation_path") load("//bundle:defs.bzl", "TOOL_PATH", "adhoc_signing_transition", "archives", "check_cell", "display", "flat_resources", "label_text", "resolved_xcode") -load("//bundle:validate.bzl", "bundle_platform_errors") -load(":validate.bzl", "MACOS_ARCHES", "macos_app_errors") +load(":validate.bzl", "macos_app_errors") _CELL = "macos/arm64" @@ -37,12 +37,16 @@ _INFO_PLIST = """ """ +def _macho_arch(ctx): + """Returns the Mach-O arch name of the platform, or "" when it is not a macOS platform.""" + identity = platform_identity(ctx) + if identity.os != "macos": + return "" + return {"aarch64": "arm64", "x86_64": "x86_64"}.get(identity.cpu, "") + def _macos_selection_impl(ctx): - selected = bundle_platform_errors("apple_macos_app", list(ctx.attr.platforms), MACOS_ARCHES) - if len(selected) > 0: - fail("; ".join(selected)) failures = macos_app_errors(struct( - arch = ctx.attr.arch, + arch = _macho_arch(ctx), bundle_id = ctx.attr.bundle_id, deployment = ctx.attr.deployment, entitlements = ctx.attr.entitlements, @@ -63,20 +67,18 @@ _macos_selection = rule( implementation = _macos_selection_impl, doc = "Fails analysis when a macOS app declaration is invalid.", attrs = { - "arch": attr.string(doc = "Target CPU architecture of the app.", mandatory = True), "bundle_id": attr.string(doc = "Reverse DNS bundle identifier of the app.", mandatory = True), "deployment": attr.string(doc = "Minimum macOS version the app supports.", mandatory = True), "entitlements": attr.string(doc = "Entitlements label text, which building rejects.", mandatory = True), "framework_imports": attr.string_list(doc = "Label texts of embedded frameworks.", mandatory = True), "library": attr.string(doc = "Label text of the Rust library the app links.", mandatory = True), - "platforms": attr.string_list(doc = "The one architecture the app is built for.", mandatory = True), "plugins": attr.string_list(doc = "Label texts of plugins placed under PlugIns.", mandatory = True), "provisioning_profile": attr.string(doc = "Provisioning profile label text, which building rejects.", mandatory = True), "resources": attr.string_list(doc = "Label texts of resource files bundled into the app.", mandatory = True), "srcs": attr.string_list(doc = "Label texts of native sources, including the entry point.", mandatory = True), "version": attr.string(doc = "Bundle version string of the app.", mandatory = True), "xcode_version": attr.string(doc = "Xcode version the app build is pinned to.", mandatory = True), - }, + } | PLATFORM_ATTRS, ) def _has(ctx, constraint): @@ -213,7 +215,7 @@ def _macos_app_check_impl(ctx): info.bundle_id, ctx.attr.version, ctx.attr.deployment, - ctx.attr.arch, + _macho_arch(ctx), xcode, str(xcode_config.sdk_version_for_platform(apple_common.platform.macos)), _lines(_framework_names(ctx.attr.frameworks)), @@ -264,7 +266,6 @@ _macos_app_check = rule( mandatory = True, providers = [AppleBundleInfo], ), - "arch": attr.string(doc = "Architecture every Mach-O file of the app must carry.", mandatory = True), "deployment": attr.string(doc = "Minimum macOS version the app supports.", mandatory = True), "frameworks": attr.label_list( doc = "Frameworks the bundle must embed under Frameworks.", @@ -287,7 +288,7 @@ _macos_app_check = rule( fragment = "apple", ), ), - }, + } | PLATFORM_ATTRS, executable = True, fragments = ["apple"], ) @@ -305,7 +306,7 @@ def apple_macos_app( bundle_id = "", version = "", deployment = "", - platforms = ["arm64"], + platform = None, xcode_version = "", entitlements = None, provisioning_profile = None, @@ -313,11 +314,9 @@ def apple_macos_app( testonly = False, visibility = None): """Builds one upstream macOS application over a Rust library, checked and ad hoc signed.""" - arch = platforms[0] if len(platforms) == 1 else "" _macos_selection( name = name + "_selection", - arch = arch, - platforms = platforms, + platform = platform, bundle_id = bundle_id, deployment = deployment, entitlements = label_text(entitlements), @@ -392,7 +391,7 @@ def apple_macos_app( _macos_app_check( name = name, app = ":" + name + "_bundle", - arch = arch, + platform = platform, deployment = deployment, frameworks = frameworks, plugins = plugins, diff --git a/families/apple/macos/app_tests.bzl b/families/apple/macos/app_tests.bzl index f3decc45e3..d5590bf2f6 100644 --- a/families/apple/macos/app_tests.bzl +++ b/families/apple/macos/app_tests.bzl @@ -1,7 +1,7 @@ """macOS application selection coverage.""" load("@rules_dx//libs/starlark:defs.bzl", "expect_equal", "starlark_test") -load("//bundle:validate.bzl", "bundle_id_errors", "bundle_platform_errors", "bundle_version_errors") +load("//bundle:validate.bzl", "bundle_id_errors", "bundle_version_errors") load(":app.bzl", "owner_relative_path") load(":validate.bzl", "macos_app_errors", "macos_default_app", "macos_plugin_errors") @@ -85,11 +85,6 @@ def _app_checks(): macos_app_errors(_app(arch = "x86_64")), ["apple_macos_app: arch 'x86_64' is outside macos: want arm64"], )) - checks.append(expect_equal( - "two platforms fail", - bundle_platform_errors("apple_macos_app", ["arm64", "x86_64"], ["arm64"]), - ["apple_macos_app: platforms takes one of arm64"], - )) checks.append(expect_equal( "provisioning profile fails", macos_app_errors(_app(provisioning_profile = "ledger.provisionprofile")), diff --git a/families/apple/platforms/BUILD.bazel b/families/apple/platforms/BUILD.bazel new file mode 100644 index 0000000000..0d67d23e16 --- /dev/null +++ b/families/apple/platforms/BUILD.bazel @@ -0,0 +1,31 @@ +load("@rules_dx//quality:fixtures.bzl", "real_source_target") + +package(default_visibility = ["//visibility:public"]) + +platform( + name = "macos_arm64", + constraint_values = [ + "@platforms//cpu:arm64", + "@platforms//os:macos", + ], +) + +platform( + name = "macos_x86_64", + constraint_values = [ + "@platforms//cpu:x86_64", + "@platforms//os:macos", + ], +) + +real_source_target( + name = "corpus_starlark", + starlark_srcs = ["BUILD.bazel"], + tags = ["corpus"], +) + +filegroup( + name = "module_srcs", + srcs = glob(["**"]), + visibility = ["//visibility:public"], +) diff --git a/families/cuda/README.md b/families/cuda/README.md index a620a034c0..82ed71eb7e 100644 --- a/families/cuda/README.md +++ b/families/cuda/README.md @@ -53,7 +53,7 @@ cuda_library( name = "kernels", srcs = ["saxpy.cu"], hdrs = ["saxpy.cuh", "saxpy.h"], - platforms = ["compute_89:compute_89,sm_89", "sm_120"], + cuda_archs = ["compute_89:compute_89,sm_89", "sm_120"], ) ``` @@ -63,7 +63,7 @@ cuda_library( and `visibility` work as for `cc_library`. The CUDA runtime links statically. - `cuda_binary`: a `cc_binary`. Its `.cu` and `.cuh` sources go through a - `cuda_library` with the same `platforms`. The other sources compile as C++. + `cuda_library` with the same `cuda_archs`. The other sources compile as C++. - `cuda_test`: the same as `cuda_binary`, as a `cc_test`. `defines` and `local_defines` on `cuda_binary` and `cuda_test` apply to all @@ -78,7 +78,7 @@ to nvcc. `__device__` functions can call across `.cu` files and across libraries. `rdc` supports `sm_` archs. -`platforms` is required on all four. Each entry is one of: +`cuda_archs` is required on all four. Each entry is one of: - `sm_XY`: SASS for compute capability X.Y. - `compute_XY`: PTX for X.Y, compiled for the device at load time. @@ -104,7 +104,7 @@ failing. rules_dx patches rules_cuda 0.4.0-beta1 for the windows-arm64 toolkit | --- | --- | | `dx_cuda: the CUDA Toolkit EULA (https://docs.nvidia.com/cuda/eula/index.html) is not accepted; add cuda_license.license(accept = ["cuda-eula"]) to the root MODULE.bazel` | Add the license tag to the root `MODULE.bazel`. | | `dx_cuda: unknown license ''; the only one is 'cuda-eula'` | Accept `cuda-eula`. | -| `dx_cuda: platforms is empty; set platforms, for example platforms = ["sm_89"]` | Set `platforms`. | +| `dx_cuda: cuda_archs is empty; set cuda_archs, for example cuda_archs = ["sm_89"]` | Set `cuda_archs`. | | `dx_cuda: arch '' is not supported by nvcc 13.4; supported: ...` | Use an arch from the list. | | `dx_cuda: @rules_cuda//cuda:compiler is ''; dx CUDA targets compile with nvcc only` | Remove the `@rules_cuda//cuda:compiler` setting. | | `dx_cuda: the CUDA toolkit is not the pinned redistributable (nvcc at ''); declare the cuda.redist_json and cuda.toolkit tags from the dx CUDA README` | Add the `cuda.redist_json` and `cuda.toolkit` tags from Setup. | @@ -125,7 +125,7 @@ Depend on the license-gated labels: cuda_library( name = "gemm", srcs = ["gemm.cu"], - platforms = ["sm_89"], + cuda_archs = ["sm_89"], deps = ["@rules_dx_cuda//components:cublas"], # or :cufft, :curand ) ``` @@ -147,7 +147,7 @@ load("@rules_dx_cuda//rules:defs.bzl", "cuda_test") cuda_test( name = "saxpy_gpu_test", srcs = ["saxpy_gpu_test.cu"], - platforms = ["compute_89:compute_89,sm_89", "sm_120"], + cuda_archs = ["compute_89:compute_89,sm_89", "sm_120"], min_compute_capability = "8.9", min_driver = "13.0", tags = ["manual"], @@ -167,9 +167,9 @@ when a kernel launch fails. Return 0. Set `min_compute_capability` and `min_driver` on `cuda_test` to run it on a GPU. Set both. -- `platforms`: required arch specs, as for `cuda_library`. +- `cuda_archs`: required arch specs, as for `cuda_library`. - `min_compute_capability`: lowest device compute capability, `X.Y`. - It must be at least the lowest arch in `platforms`. + It must be at least the lowest arch in `cuda_archs`. - `min_driver`: lowest CUDA driver version, `X.Y`, from `13.0` to `13.4`. The runtime version is always the pinned toolkit, 13.4. diff --git a/families/cuda/rules/BUILD.bazel b/families/cuda/rules/BUILD.bazel index 4b10f8cd9f..6f51bf4558 100644 --- a/families/cuda/rules/BUILD.bazel +++ b/families/cuda/rules/BUILD.bazel @@ -151,8 +151,8 @@ dx_wrapper_contract_tests( [], ), expect_true( - "empty platforms fail", - "platforms is empty" in arch_errors([])[0], + "empty cuda_archs fail", + "cuda_archs is empty" in arch_errors([])[0], ), expect_true( "sm_70 fails", @@ -226,7 +226,7 @@ dx_wrapper_contract_tests( ), expect_true( "cc below the lowest arch fails", - "below the lowest arch in platforms (8.9)" in gpu_requirement_errors(_SAXPY_ARCHS, "8.6", "13.0")[0], + "below the lowest arch in cuda_archs (8.9)" in gpu_requirement_errors(_SAXPY_ARCHS, "8.6", "13.0")[0], ), expect_true( "malformed cc fails", diff --git a/families/cuda/rules/defs.bzl b/families/cuda/rules/defs.bzl index 11e24bd2e9..7367dc6ba4 100644 --- a/families/cuda/rules/defs.bzl +++ b/families/cuda/rules/defs.bzl @@ -100,15 +100,15 @@ def cuda_split_srcs(srcs): host.append(src) return device, host -def cuda_library(name, srcs, platforms, hdrs = None, visibility = None, tags = None, target_compatible_with = None, rdc = False, **kwargs): - """Minimal wrapper over rules_cuda cuda_library; platforms is required and rdc enables relocatable device code.""" +def cuda_library(name, srcs, cuda_archs, hdrs = None, visibility = None, tags = None, target_compatible_with = None, rdc = False, **kwargs): + """Minimal wrapper over rules_cuda cuda_library; cuda_archs is required and rdc enables relocatable device code.""" features = _cuda_features(kwargs.pop("features", None)) compatible = cuda_target_compatible_with(target_compatible_with) _cuda_library( name = name + "_upstream", srcs = srcs, hdrs = hdrs or [], - archs = platforms, + archs = cuda_archs, rdc = rdc, tags = dx_upstream_tags(tags), target_compatible_with = compatible + _UPSTREAM_ONLY_UNDER_TRANSITION, @@ -118,7 +118,7 @@ def cuda_library(name, srcs, platforms, hdrs = None, visibility = None, tags = N ) cuda_check( name = name + "_cuda_check", - archs = platforms, + archs = cuda_archs, tags = ["manual"], target_compatible_with = compatible, testonly = kwargs.get("testonly", None), @@ -141,7 +141,7 @@ def cuda_library(name, srcs, platforms, hdrs = None, visibility = None, tags = N **forward_kwargs ) -def cuda_objects(name, srcs, platforms, hdrs = None, deps = None, visibility = None, tags = None, target_compatible_with = None, **kwargs): +def cuda_objects(name, srcs, cuda_archs, hdrs = None, deps = None, visibility = None, tags = None, target_compatible_with = None, **kwargs): """Compiles .cu sources to relocatable device objects for the deps of an rdc cuda_library, cuda_binary or cuda_test.""" features = _cuda_features(kwargs.pop("features", None)) compatible = cuda_target_compatible_with(target_compatible_with) @@ -149,7 +149,7 @@ def cuda_objects(name, srcs, platforms, hdrs = None, deps = None, visibility = N name = name + "_upstream", srcs = srcs, hdrs = hdrs or [], - archs = platforms, + archs = cuda_archs, deps = list(deps or []) + [Label("@rules_cuda//cuda:runtime")], tags = dx_upstream_tags(tags), target_compatible_with = compatible + _UPSTREAM_ONLY_UNDER_TRANSITION, @@ -159,7 +159,7 @@ def cuda_objects(name, srcs, platforms, hdrs = None, deps = None, visibility = N ) cuda_check( name = name + "_cuda_check", - archs = platforms, + archs = cuda_archs, tags = ["manual"], target_compatible_with = compatible, testonly = kwargs.get("testonly", None), @@ -182,14 +182,14 @@ def cuda_objects(name, srcs, platforms, hdrs = None, deps = None, visibility = N **forward_kwargs ) -def _cuda_executable(cc_rule, name, srcs, platforms, deps, hdrs, visibility, tags, target_compatible_with, kwargs, library_tags = None, rdc = False, cuda_copts = None): +def _cuda_executable(cc_rule, name, srcs, cuda_archs, deps, hdrs, visibility, tags, target_compatible_with, kwargs, library_tags = None, rdc = False, cuda_copts = None): device, host = cuda_split_srcs(srcs) compatible = cuda_target_compatible_with(target_compatible_with) cuda_library( name = name + "_cuda", srcs = device, hdrs = hdrs, - platforms = platforms, + cuda_archs = cuda_archs, rdc = rdc, deps = deps, defines = kwargs.get("defines", []), @@ -210,9 +210,9 @@ def _cuda_executable(cc_rule, name, srcs, platforms, deps, hdrs, visibility, tag **kwargs ) -def cuda_binary(name, srcs, platforms, deps = None, hdrs = None, visibility = None, tags = None, target_compatible_with = None, rdc = False, cuda_copts = None, **kwargs): +def cuda_binary(name, srcs, cuda_archs, deps = None, hdrs = None, visibility = None, tags = None, target_compatible_with = None, rdc = False, cuda_copts = None, **kwargs): """Compiles .cu sources with nvcc and links them into a cc_binary; cuda_copts go to nvcc.""" - _cuda_executable(_cc_binary, name, srcs, platforms, deps, hdrs, visibility, tags, target_compatible_with, kwargs, rdc = rdc, cuda_copts = cuda_copts) + _cuda_executable(_cc_binary, name, srcs, cuda_archs, deps, hdrs, visibility, tags, target_compatible_with, kwargs, rdc = rdc, cuda_copts = cuda_copts) _GPU_TAGS = ["exclusive", "external", "local", "requires-gpu"] @@ -224,7 +224,7 @@ def cuda_gpu_env(min_compute_capability, min_driver): "DX_GPU_RUNTIME": CUDA_VERSION, } -def cuda_test(name, srcs, platforms, deps = None, hdrs = None, visibility = None, tags = None, target_compatible_with = None, rdc = False, min_compute_capability = None, min_driver = None, env = None, data = None, cuda_copts = None, **kwargs): +def cuda_test(name, srcs, cuda_archs, deps = None, hdrs = None, visibility = None, tags = None, target_compatible_with = None, rdc = False, min_compute_capability = None, min_driver = None, env = None, data = None, cuda_copts = None, **kwargs): """Compiles .cu sources into a cc_test; min_compute_capability and min_driver make it a GPU test, cuda_copts go to nvcc.""" if (min_compute_capability == None) != (min_driver == None): fail("cuda_test //{}:{}: set both min_compute_capability and min_driver for a GPU test".format(native.package_name(), name)) @@ -234,12 +234,12 @@ def cuda_test(name, srcs, platforms, deps = None, hdrs = None, visibility = None if data != None: kwargs["data"] = data kwargs["testonly"] = True - _cuda_executable(_cc_test, name, srcs, platforms, deps, hdrs, visibility, tags, target_compatible_with, kwargs, rdc = rdc, cuda_copts = cuda_copts) + _cuda_executable(_cc_test, name, srcs, cuda_archs, deps, hdrs, visibility, tags, target_compatible_with, kwargs, rdc = rdc, cuda_copts = cuda_copts) return compatible = cuda_target_compatible_with(target_compatible_with) cuda_gpu_check( name = name + "_gpu_check", - archs = platforms, + archs = cuda_archs, min_compute_capability = min_compute_capability, min_driver = min_driver, tags = ["manual"], @@ -255,7 +255,7 @@ def cuda_test(name, srcs, platforms, deps = None, hdrs = None, visibility = None _cc_test, name, srcs, - platforms, + cuda_archs, list(deps or []) + [Label("//testing:gpu_main")], hdrs, visibility, diff --git a/families/cuda/testing/BUILD.bazel b/families/cuda/testing/BUILD.bazel index eba0e5adaf..9200057e0b 100644 --- a/families/cuda/testing/BUILD.bazel +++ b/families/cuda/testing/BUILD.bazel @@ -18,7 +18,7 @@ cuda_library( testonly = True, srcs = ["gpu_main.cu"], hdrs = ["gpu_test.h"], - platforms = ["compute_75"], + cuda_archs = ["compute_75"], deps = [":gpu_facts"], ) diff --git a/families/cuda/tests/BUILD.bazel b/families/cuda/tests/BUILD.bazel index 36ad7c902a..2163e9483d 100644 --- a/families/cuda/tests/BUILD.bazel +++ b/families/cuda/tests/BUILD.bazel @@ -30,7 +30,7 @@ rust_test( cuda_test( name = "saxpy_gpu_test", srcs = ["saxpy_gpu_test.cu"], - platforms = [ + cuda_archs = [ "compute_89:compute_89,sm_89", "sm_120", ], @@ -105,7 +105,7 @@ hermetic_toolchain_test( cuda_test( name = "rdc_gpu_test", srcs = ["rdc_gpu_test.cu"], - platforms = [ + cuda_archs = [ "sm_89", "sm_120", ], @@ -128,7 +128,7 @@ rust_test( ) cuda_gpu_check( - name = "gpu_cc_below_platforms", + name = "gpu_cc_below_cuda_archs", archs = ["sm_89"], min_compute_capability = "7.5", min_driver = "13.0", @@ -136,9 +136,9 @@ cuda_gpu_check( ) failure_test( - name = "gpu_cc_below_platforms_failure_test", - expected_failure_substring = "dx_cuda: min_compute_capability 7.5 is below the lowest arch in platforms (8.9)", - target = ":gpu_cc_below_platforms", + name = "gpu_cc_below_cuda_archs_failure_test", + expected_failure_substring = "dx_cuda: min_compute_capability 7.5 is below the lowest arch in cuda_archs (8.9)", + target = ":gpu_cc_below_cuda_archs", target_compatible_with = CUDA_TARGET, ) @@ -160,7 +160,7 @@ rust_test( cuda_test( name = "cublas_gpu_test", srcs = ["cublas_gpu_test.cu"], - platforms = [ + cuda_archs = [ "compute_89:compute_89,sm_89", "sm_120", ], @@ -209,23 +209,23 @@ gcc_hermetic_toolchain_test( ) cuda_library( - name = "missing_platforms", + name = "missing_cuda_archs", srcs = ["//tests/fixtures/saxpy:saxpy.cu"], - platforms = [], + cuda_archs = [], tags = ["manual"], ) failure_test( - name = "missing_platforms_failure_test", - expected_failure_substring = "dx_cuda: platforms is empty", - target = ":missing_platforms", + name = "missing_cuda_archs_failure_test", + expected_failure_substring = "dx_cuda: cuda_archs is empty", + target = ":missing_cuda_archs", target_compatible_with = CUDA_TARGET, ) cuda_library( name = "unsupported_arch", srcs = ["//tests/fixtures/saxpy:saxpy.cu"], - platforms = ["sm_70"], + cuda_archs = ["sm_70"], tags = ["manual"], ) diff --git a/families/cuda/tests/fixtures/cublas/BUILD.bazel b/families/cuda/tests/fixtures/cublas/BUILD.bazel index 7a15d52689..f7a7883574 100644 --- a/families/cuda/tests/fixtures/cublas/BUILD.bazel +++ b/families/cuda/tests/fixtures/cublas/BUILD.bazel @@ -7,7 +7,7 @@ cuda_library( name = "cublas", srcs = ["cublas_saxpy.cu"], hdrs = ["cublas_saxpy.h"], - platforms = [ + cuda_archs = [ "compute_89:compute_89,sm_89", "sm_120", ], diff --git a/families/cuda/tests/fixtures/cuda-app/gpu/BUILD.bazel b/families/cuda/tests/fixtures/cuda-app/gpu/BUILD.bazel index 097e8d74e7..229e777840 100644 --- a/families/cuda/tests/fixtures/cuda-app/gpu/BUILD.bazel +++ b/families/cuda/tests/fixtures/cuda-app/gpu/BUILD.bazel @@ -14,7 +14,7 @@ exports_files([ cuda_test( name = "gpu_test", srcs = ["gpu_test.cu"], - platforms = [ + cuda_archs = [ "compute_80:compute_80,sm_80", "sm_90", ], diff --git a/families/cuda/tests/fixtures/cuda-app/kernels/BUILD.bazel b/families/cuda/tests/fixtures/cuda-app/kernels/BUILD.bazel index 52b94f15a4..a6ed76521f 100644 --- a/families/cuda/tests/fixtures/cuda-app/kernels/BUILD.bazel +++ b/families/cuda/tests/fixtures/cuda-app/kernels/BUILD.bazel @@ -25,7 +25,7 @@ cuda_library( "common.cuh", "kernels.h", ], - platforms = [ + cuda_archs = [ "compute_80:compute_80,sm_80", "sm_90", ], diff --git a/families/cuda/tests/fixtures/executable/BUILD.bazel b/families/cuda/tests/fixtures/executable/BUILD.bazel index 1ccfba78cb..41f05b09ea 100644 --- a/families/cuda/tests/fixtures/executable/BUILD.bazel +++ b/families/cuda/tests/fixtures/executable/BUILD.bazel @@ -14,7 +14,7 @@ cuda_binary( "main.cc", ], hdrs = ["add.h"], - platforms = _ARCHS, + cuda_archs = _ARCHS, ) cuda_binary( @@ -24,7 +24,7 @@ cuda_binary( "rdc_main.cc", ], hdrs = ["add.h"], - platforms = _ARCHS, + cuda_archs = _ARCHS, rdc = True, deps = ["//tests/fixtures/rdc:axpy"], ) @@ -36,7 +36,7 @@ cuda_test( "main.cc", ], hdrs = ["add.h"], - platforms = _ARCHS, + cuda_archs = _ARCHS, ) cuda_test( @@ -46,7 +46,7 @@ cuda_test( "rdc_main.cc", ], hdrs = ["add.h"], - platforms = _ARCHS, + cuda_archs = _ARCHS, rdc = True, deps = ["//tests/fixtures/rdc:axpy"], ) @@ -60,7 +60,7 @@ cuda_binary( cuda_copts = ["-DDX_EXEC_NVCC"], defines = ["DX_EXEC_PUBLIC"], local_defines = ["DX_EXEC_N=1024"], - platforms = _ARCHS, + cuda_archs = _ARCHS, ) cuda_test( @@ -72,5 +72,5 @@ cuda_test( cuda_copts = ["-DDX_EXEC_NVCC"], defines = ["DX_EXEC_PUBLIC"], local_defines = ["DX_EXEC_N=1024"], - platforms = _ARCHS, + cuda_archs = _ARCHS, ) diff --git a/families/cuda/tests/fixtures/rdc/BUILD.bazel b/families/cuda/tests/fixtures/rdc/BUILD.bazel index cb9a0dace4..e79eb2eba3 100644 --- a/families/cuda/tests/fixtures/rdc/BUILD.bazel +++ b/families/cuda/tests/fixtures/rdc/BUILD.bazel @@ -7,7 +7,7 @@ cuda_library( name = "scale", srcs = ["scale.cu"], hdrs = ["scale.cuh"], - platforms = [ + cuda_archs = [ "sm_89", "sm_120", ], @@ -18,7 +18,7 @@ cuda_library( name = "axpy", srcs = ["axpy.cu"], hdrs = ["axpy.h"], - platforms = [ + cuda_archs = [ "sm_89", "sm_120", ], @@ -37,7 +37,7 @@ cuda_objects( name = "scale_objects", srcs = ["scale.cu"], hdrs = ["scale.cuh"], - platforms = [ + cuda_archs = [ "sm_89", "sm_120", ], @@ -50,7 +50,7 @@ cuda_library( "axpy.h", "scale.cuh", ], - platforms = [ + cuda_archs = [ "sm_89", "sm_120", ], diff --git a/families/cuda/tests/fixtures/saxpy/BUILD.bazel b/families/cuda/tests/fixtures/saxpy/BUILD.bazel index 5194be90ff..887d1989dd 100644 --- a/families/cuda/tests/fixtures/saxpy/BUILD.bazel +++ b/families/cuda/tests/fixtures/saxpy/BUILD.bazel @@ -10,7 +10,7 @@ cuda_library( "saxpy.cuh", "saxpy.h", ], - platforms = [ + cuda_archs = [ "compute_89:compute_89,sm_89", "sm_120", ], diff --git a/families/cuda/toolchain/check.bzl b/families/cuda/toolchain/check.bzl index 4e8596236b..5d60e537ce 100644 --- a/families/cuda/toolchain/check.bzl +++ b/families/cuda/toolchain/check.bzl @@ -25,7 +25,7 @@ _TOOLCHAIN_TYPE = "@rules_cuda//cuda:toolchain_type" def arch_errors(archs): """Returns one error per arch spec token that the pinned nvcc does not support.""" if not archs: - return ["dx_cuda: platforms is empty; set platforms, for example platforms = [\"sm_89\"]"] + return ["dx_cuda: cuda_archs is empty; set cuda_archs, for example cuda_archs = [\"sm_89\"]"] errors = [] for spec in archs: for part in spec.replace(":", ",").split(","): @@ -61,7 +61,7 @@ def gpu_requirement_errors(archs, min_compute_capability, min_driver): if cc == None: errors.append("dx_cuda: min_compute_capability '" + str(min_compute_capability) + "' is not X.Y, for example \"8.9\"") elif lowest != None and cc < lowest: - errors.append("dx_cuda: min_compute_capability " + min_compute_capability + " is below the lowest arch in platforms (%d.%d)" % lowest) + errors.append("dx_cuda: min_compute_capability " + min_compute_capability + " is below the lowest arch in cuda_archs (%d.%d)" % lowest) driver = _version(min_driver) pinned = _version(CUDA_VERSION) floor = "%d.0" % pinned[0] diff --git a/families/msix/README.md b/families/msix/README.md index a7bca4e931..c666d438d8 100644 --- a/families/msix/README.md +++ b/families/msix/README.md @@ -50,7 +50,7 @@ msix_package( identity_name = "Example.App", logo = "logo.png", notice = ["NOTICE.txt"], - platforms = ["arm64"], + platform = "@rules_dx_msix//platforms:windows_arm64", publisher = "CN=Example", version = "1.2.3.0", ) @@ -63,9 +63,9 @@ msix_sign( Attributes: -- `platforms`: `arm64` or `x86_64`. Builds the package and its `binary`, `libs` and `data` for - that architecture. Empty uses the current target platform. `target_compatible_with` only marks - compatibility. Do not set it with `select()`. +- `platform`: a Windows platform label such as `@rules_dx_msix//platforms:windows_arm64`. Builds + the package and its `binary`, `libs` and `data` for it. Unset uses the current target + platform. `target_compatible_with` only marks compatibility. Do not set it with `select()`. - `binary`: the `.exe`. Its target-configuration bytes are packaged at the package root. Every `.dll` in its runfiles, such as its `dynamic_deps`, is packaged next to it. - `identity_name`: package identity name, 3 to 50 letters, digits, dots or dashes. @@ -106,7 +106,7 @@ bazel build //pkg:app bazel build //pkg:app --platforms=@rules_dx_msix//platforms:windows_arm64 ``` -The `platforms` attribute and `--platforms` do the same thing. +The `platform` attribute and `--platforms` do the same thing. The package digest changes between builds. The digests of the packaged files do not. diff --git a/families/msix/defs.bzl b/families/msix/defs.bzl index 3d339864ec..6e86898c27 100644 --- a/families/msix/defs.bzl +++ b/families/msix/defs.bzl @@ -1,9 +1,10 @@ """Windows MSIX packaging for target binaries.""" load("@rules_dx//powershell/rules:defs.bzl", "powershell_binary") -load("@rules_dx//libs/starlark:packaging.bzl", "claim_dest", "data_path", "platform_arch") +load("@rules_dx//libs/starlark:packaging.bzl", "claim_dest", "data_path") +load("@rules_dx//libs/starlark:platform.bzl", "PLATFORM_ATTRS", "platform_identity", "platform_transition") load(":pins.bzl", "MAX_VERSION_TESTED", "MIN_VERSION") -load(":validate.bzl", "PLATFORM_VALUES", "msix_alias_errors", "msix_application_errors", "msix_identity_errors", "msix_named_version_errors", "msix_platform_errors", "msix_publisher_errors", "msix_version_errors") +load(":validate.bzl", "msix_alias_errors", "msix_application_errors", "msix_identity_errors", "msix_named_version_errors", "msix_publisher_errors", "msix_version_errors") MsixInfo = provider( doc = "Identity of one MSIX package.", @@ -53,14 +54,8 @@ def _add(ctx, entries, seen, kind, dest, file): return True def _msix_impl(ctx): - errors = msix_platform_errors(ctx.attr.platforms) - if errors: - fail("msix_package " + str(ctx.label) + ": " + errors[0]) - cv = platform_common.ConstraintValueInfo - arch = platform_arch(ctx.target_platform_has_constraint, ctx.attr._windows[cv], [ - ("arm64", ctx.attr._arm64[cv]), - ("x64", ctx.attr._x86_64[cv]), - ]) + identity = platform_identity(ctx) + arch = {"aarch64": "arm64", "x86_64": "x64"}.get(identity.cpu, "") if identity.os == "windows" else "" if not arch: fail("msix_package " + str(ctx.label) + ": target cell this platform is unsupported: only windows_x86_64 and windows_arm64 are pinned") errors = ( @@ -169,17 +164,6 @@ def _msix_impl(ctx): ), ] -def _platforms_transition_impl(settings, attr): - if msix_platform_errors(attr.platforms) or not attr.platforms: - return {"//command_line_option:platforms": settings["//command_line_option:platforms"]} - return {"//command_line_option:platforms": [str(Label("//platforms:" + PLATFORM_VALUES[attr.platforms[0]]))]} - -_platforms_transition = transition( - implementation = _platforms_transition_impl, - inputs = ["//command_line_option:platforms"], - outputs = ["//command_line_option:platforms"], -) - _msix_package = rule( implementation = _msix_impl, doc = "Packages one Windows target binary and its files as an unsigned MSIX.", @@ -196,18 +180,14 @@ _msix_package = rule( "max_version_tested": attr.string(doc = "Highest Windows version tested.", default = MAX_VERSION_TESTED), "min_version": attr.string(doc = "Lowest Windows version supported.", default = MIN_VERSION), "notice": attr.label_list(doc = "License and NOTICE files placed under licenses/.", allow_files = True, mandatory = True, allow_empty = False), - "platforms": attr.string_list(doc = "One of arm64 or x86_64 to build the package for that architecture. Empty uses the current target platform. Do not set it with select()."), "publisher": attr.string(doc = "Publisher distinguished name. Must match the signing certificate subject.", mandatory = True), "publisher_display_name": attr.string(doc = "Publisher display name. Defaults to the publisher CN."), "version": attr.string(doc = "Four-part package version.", mandatory = True), - "_arm64": attr.label(default = "@platforms//cpu:arm64"), "_pack": attr.label(default = "//:pack.ps1", allow_single_file = True), "_pwsh": attr.label(default = "@rules_powershell//powershell:current_pwsh_toolchain", cfg = "exec"), - "_windows": attr.label(default = "@platforms//os:windows"), - "_x86_64": attr.label(default = "@platforms//cpu:x86_64"), - }, + } | PLATFORM_ATTRS, toolchains = [config_common.toolchain_type(TOOLCHAIN_TYPE, mandatory = False)], - cfg = _platforms_transition, + cfg = platform_transition, ) def _windowsonly_chars(target_compatible_with): diff --git a/families/msix/metadata_tests.bzl b/families/msix/metadata_tests.bzl index 75037674f6..58c177d17d 100644 --- a/families/msix/metadata_tests.bzl +++ b/families/msix/metadata_tests.bzl @@ -2,7 +2,7 @@ load("@rules_dx//libs/starlark:defs.bzl", "expect_contains", "expect_equal", "expect_true", "starlark_test") load(":defs.bzl", "compatible_with", "publisher_cn") -load(":validate.bzl", "msix_alias_errors", "msix_application_errors", "msix_identity_errors", "msix_named_version_errors", "msix_platform_errors", "msix_publisher_errors", "msix_version_errors") +load(":validate.bzl", "msix_alias_errors", "msix_application_errors", "msix_identity_errors", "msix_named_version_errors", "msix_publisher_errors", "msix_version_errors") load(":pins.bzl", "BUILDTOOLS_BIN", "BUILDTOOLS_SHA256", "BUILDTOOLS_URL", "BUILDTOOLS_VERSION", "LICENSE", "SUPPORTED_CELLS", "TOOL_ARCHES") load(":repos.bzl", "UNACCEPTED", "hub_build") @@ -35,12 +35,6 @@ def _checks(): expect_true("large version part", len(msix_version_errors("1.2.3.65536")) == 1), expect_true("text version part", len(msix_version_errors("1.2.x.0")) == 1), expect_true("empty version part", len(msix_version_errors("1..3.0")) == 1), - expect_equal("no platforms", msix_platform_errors([]), []), - expect_equal("arm64 platform", msix_platform_errors(["arm64"]), []), - expect_equal("x86_64 platform", msix_platform_errors(["x86_64"]), []), - expect_true("x86_32 platform", len(msix_platform_errors(["x86_32"])) == 1), - expect_true("two platforms", len(msix_platform_errors(["arm64", "x86_64"])) == 1), - expect_true("x64 platform", len(msix_platform_errors(["x64"])) == 1), expect_equal("good identity", msix_identity_errors("Contoso.App-2"), []), expect_true("short identity", len(msix_identity_errors("ab")) == 1), expect_true("identity with space", len(msix_identity_errors("Contoso App")) == 1), diff --git a/families/msix/tests/BUILD.bazel b/families/msix/tests/BUILD.bazel index eef67f3df9..c46f3cc378 100644 --- a/families/msix/tests/BUILD.bazel +++ b/families/msix/tests/BUILD.bazel @@ -215,7 +215,7 @@ msix_package( libs = [":cell_dll"], logo = "fixtures/logo.png", notice = ["fixtures/NOTICE.txt"], - platforms = ["arm64"], + platform = "//platforms:windows_arm64", publisher = "CN=Dx Cell, O=Dx", tags = ["manual"], version = "1.0.0.0", @@ -229,21 +229,7 @@ msix_package( libs = [":cell_dll"], logo = "fixtures/logo.png", notice = ["fixtures/NOTICE.txt"], - platforms = ["x86_64"], - publisher = "CN=Dx Cell, O=Dx", - tags = ["manual"], - version = "1.0.0.0", -) - -msix_package( - name = "bad_platforms", - binary = ":cell_exe", - data = ["fixtures/greeting.txt"], - identity_name = "Dx.Cell", - libs = [":cell_dll"], - logo = "fixtures/logo.png", - notice = ["fixtures/NOTICE.txt"], - platforms = ["x86_32"], + platform = "//platforms:windows_x86_64", publisher = "CN=Dx Cell, O=Dx", tags = ["manual"], version = "1.0.0.0", @@ -403,12 +389,6 @@ arch_on_arm64_test( target_under_test = ":cell_x86_64", ) -attribute_failure_test( - name = "bad_platforms_fails", - expected = "platforms takes one of arm64, x86_64", - target_under_test = ":bad_platforms", -) - arm64_action_test( name = "arm64_action_test", arch = "arm64", diff --git a/families/msix/validate.bzl b/families/msix/validate.bzl index 55f42f4534..9353448ca7 100644 --- a/families/msix/validate.bzl +++ b/families/msix/validate.bzl @@ -18,14 +18,6 @@ def msix_version_errors(version): """Returns why a package version is not four numbers up to 65535.""" return msix_named_version_errors("version", version) -PLATFORM_VALUES = {"arm64": "windows_arm64", "x86_64": "windows_x86_64"} - -def msix_platform_errors(platforms): - """Returns why a platforms value is not empty or one known architecture.""" - if len(platforms) == 0 or (len(platforms) == 1 and platforms[0] in PLATFORM_VALUES): - return [] - return ["platforms takes one of " + ", ".join(sorted(PLATFORM_VALUES))] - def msix_identity_errors(name): """Returns why a package identity name is invalid.""" if len(name) < 3 or len(name) > 50 or not only_chars(name, _LETTERS + _DIGITS + ".-"): diff --git a/gazelle/cc/cuda.go b/gazelle/cc/cuda.go index 3d332c328f..a4fa36a489 100644 --- a/gazelle/cc/cuda.go +++ b/gazelle/cc/cuda.go @@ -65,12 +65,12 @@ func generateCuda(args language.GenerateArgs, rep common.Reporter) language.Gene return language.GenerateResult{} } - var platforms []string + var archs []string if args.Config != nil { - platforms, _ = args.Config.Exts[platformsDirective].([]string) + archs, _ = args.Config.Exts[archsDirective].([]string) } - if len(platforms) == 0 { - rep.Fail(common.InPackage(args.Rel), "cc: %s: .cu/.cuh files need # gazelle:%s ...", args.Rel, platformsDirective) + if len(archs) == 0 { + rep.Fail(common.InPackage(args.Rel), "cc: %s: .cu/.cuh files need # gazelle:%s ...", args.Rel, archsDirective) return language.GenerateResult{} } @@ -121,7 +121,7 @@ func generateCuda(args language.GenerateArgs, rep common.Reporter) language.Gene if len(hdrs) > 0 { r.SetAttr("hdrs", hdrs) } - r.SetAttr("platforms", platforms) + r.SetAttr("cuda_archs", archs) if common.FixtureTestonly(args.Config, args.Rel) { r.SetAttr("testonly", true) } diff --git a/gazelle/cc/lang.go b/gazelle/cc/lang.go index a3eb8a263d..85f185f0d3 100644 --- a/gazelle/cc/lang.go +++ b/gazelle/cc/lang.go @@ -35,22 +35,22 @@ var ccKinds = map[string]rule.KindInfo{ }, } -const platformsDirective = "dx_cuda_platforms" +const archsDirective = "dx_cuda_archs" func configureCuda(c *config.Config, rel string, f *rule.File, rep common.Reporter) { if f == nil { return } for _, d := range f.Directives { - if d.Key != platformsDirective { + if d.Key != archsDirective { continue } - platforms := strings.Fields(d.Value) - if len(platforms) == 0 { - rep.Fail(common.InPackage(rel), "cc: %s: # gazelle:%s needs at least one arch", rel, platformsDirective) + archs := strings.Fields(d.Value) + if len(archs) == 0 { + rep.Fail(common.InPackage(rel), "cc: %s: # gazelle:%s needs at least one arch", rel, archsDirective) continue } - c.Exts[platformsDirective] = platforms + c.Exts[archsDirective] = archs } } @@ -63,7 +63,7 @@ func NewLanguage() language.Language { ExtraKinds: []string{CudaKind, TestKind}, KindDefs: map[string]string{CudaKind: "@rules_dx_cuda//rules:defs.bzl"}, IndexKinds: []string{CudaKind}, - Directives: []string{platformsDirective}, + Directives: []string{archsDirective}, ConfigureExt: configureCuda, ImportAttr: "hdrs", Identity: HeaderIdentity, diff --git a/gazelle/cc/lang_test.go b/gazelle/cc/lang_test.go index cc2a1dde5f..26be3c448b 100644 --- a/gazelle/cc/lang_test.go +++ b/gazelle/cc/lang_test.go @@ -261,7 +261,7 @@ func TestGenerateRootPackage(t *testing.T) { } } -func cudaFixture(t *testing.T, build string, platforms []string, files map[string]string) (language.Language, language.GenerateResult) { +func cudaFixture(t *testing.T, build string, archs []string, files map[string]string) (language.Language, language.GenerateResult) { t.Helper() root := t.TempDir() var regular []string @@ -270,8 +270,8 @@ func cudaFixture(t *testing.T, build string, platforms []string, files map[strin regular = append(regular, name) } cfg := &config.Config{RepoRoot: root, Exts: map[string]interface{}{}} - if platforms != nil { - cfg.Exts[platformsDirective] = platforms + if archs != nil { + cfg.Exts[archsDirective] = archs } var f *rule.File if build != "" { @@ -300,8 +300,8 @@ func TestCudaGenerateOwnedByDirectory(t *testing.T) { if got := strings.Join(r.AttrStrings("hdrs"), ","); got != "k.cuh" { t.Errorf("hdrs = %q", got) } - if got := strings.Join(r.AttrStrings("platforms"), "|"); got != "compute_89:compute_89,sm_89|sm_120" { - t.Errorf("platforms = %q", got) + if got := strings.Join(r.AttrStrings("cuda_archs"), "|"); got != "compute_89:compute_89,sm_89|sm_120" { + t.Errorf("cuda_archs = %q", got) } if len(res.Imports) != 1 { t.Errorf("imports = %v", res.Imports) @@ -313,7 +313,7 @@ func TestCudaMissingDirectiveRefuses(t *testing.T) { if len(res.Gen) != 0 { t.Fatalf("gen = %+v", res.Gen) } - wantRefusal(t, refusal(t, lang), "cc: pkg/demo: .cu/.cuh files need # gazelle:dx_cuda_platforms ...") + wantRefusal(t, refusal(t, lang), "cc: pkg/demo: .cu/.cuh files need # gazelle:dx_cuda_archs ...") } func TestCudaMainRefuses(t *testing.T) { @@ -322,19 +322,19 @@ func TestCudaMainRefuses(t *testing.T) { } func TestCudaBinaryNameClashRefuses(t *testing.T) { - lang, _ := cudaFixture(t, "cuda_binary(name = \"demo\", srcs = [\"main.cu\"], platforms = [\"sm_89\"])\n", []string{"sm_89"}, map[string]string{"main.cu": "int main() {}\n", "k.cu": "\n"}) + lang, _ := cudaFixture(t, "cuda_binary(name = \"demo\", srcs = [\"main.cu\"], cuda_archs = [\"sm_89\"])\n", []string{"sm_89"}, map[string]string{"main.cu": "int main() {}\n", "k.cu": "\n"}) wantRefusal(t, refusal(t, lang), "already creates demo_cuda") } func TestCudaOwnedFilesProduceNothing(t *testing.T) { - _, res := cudaFixture(t, "cuda_library(name = \"kernel\", srcs = [\"k.cu\"], hdrs = [\"k.cuh\"], platforms = [\"sm_89\"])\n", nil, map[string]string{"k.cu": "\n", "k.cuh": "\n"}) + _, res := cudaFixture(t, "cuda_library(name = \"kernel\", srcs = [\"k.cu\"], hdrs = [\"k.cuh\"], cuda_archs = [\"sm_89\"])\n", nil, map[string]string{"k.cu": "\n", "k.cuh": "\n"}) if len(res.Gen) != 0 || len(res.Empty) != 0 { t.Fatalf("result = %+v", res) } } func TestCudaStaleOwnedTargetIsEmptied(t *testing.T) { - _, res := cudaFixture(t, "cuda_library(name = \"demo_cuda\", srcs = [\"gone.cu\"], platforms = [\"sm_89\"])\ncuda_library(name = \"hand\", srcs = [\"h.cu\"])\n", nil, map[string]string{"h.cu": "\n"}) + _, res := cudaFixture(t, "cuda_library(name = \"demo_cuda\", srcs = [\"gone.cu\"], cuda_archs = [\"sm_89\"])\ncuda_library(name = \"hand\", srcs = [\"h.cu\"])\n", nil, map[string]string{"h.cu": "\n"}) if len(res.Gen) != 0 || len(res.Empty) != 1 || res.Empty[0].Name() != "demo_cuda" { t.Fatalf("result = %+v", res) } diff --git a/gazelle/cc/testdata/cuda_generate/README.md b/gazelle/cc/testdata/cuda_generate/README.md index dc3d3834c0..4b8a14ec6f 100644 --- a/gazelle/cc/testdata/cuda_generate/README.md +++ b/gazelle/cc/testdata/cuda_generate/README.md @@ -2,11 +2,11 @@ Verifies that Gazelle generates a `_cuda` `cuda_library` for `.cu` and `.cuh` files that no hand-written CUDA rule lists, using the arch list from the -`dx_cuda_platforms` directive. +`dx_cuda_archs` directive. The `newgpu` directory has no `BUILD` file, and its host `.cc` file gets a -dependency on the generated target. The `keepplatforms` directory shows that a -hand-edited `platforms` value survives later runs. The `multi` directory uses a +dependency on the generated target. The `keeparchs` directory shows that a +hand-edited `cuda_archs` value survives later runs. The `multi` directory uses a local directive with a spec that contains a comma. The `stale` directory loses its generated target when no CUDA files remain, while a hand-written target stays. diff --git a/gazelle/cc/testdata/cuda_generate/pkg/BUILD.in b/gazelle/cc/testdata/cuda_generate/pkg/BUILD.in index cea97e457f..ffc221e5a9 100644 --- a/gazelle/cc/testdata/cuda_generate/pkg/BUILD.in +++ b/gazelle/cc/testdata/cuda_generate/pkg/BUILD.in @@ -1 +1 @@ -# gazelle:dx_cuda_platforms sm_89 +# gazelle:dx_cuda_archs sm_89 diff --git a/gazelle/cc/testdata/cuda_generate/pkg/BUILD.out b/gazelle/cc/testdata/cuda_generate/pkg/BUILD.out index cea97e457f..ffc221e5a9 100644 --- a/gazelle/cc/testdata/cuda_generate/pkg/BUILD.out +++ b/gazelle/cc/testdata/cuda_generate/pkg/BUILD.out @@ -1 +1 @@ -# gazelle:dx_cuda_platforms sm_89 +# gazelle:dx_cuda_archs sm_89 diff --git a/gazelle/cc/testdata/cuda_generate/pkg/keepplatforms/BUILD.in b/gazelle/cc/testdata/cuda_generate/pkg/keeparchs/BUILD.in similarity index 60% rename from gazelle/cc/testdata/cuda_generate/pkg/keepplatforms/BUILD.in rename to gazelle/cc/testdata/cuda_generate/pkg/keeparchs/BUILD.in index 5c8f26a3e6..3b5f59bef0 100644 --- a/gazelle/cc/testdata/cuda_generate/pkg/keepplatforms/BUILD.in +++ b/gazelle/cc/testdata/cuda_generate/pkg/keeparchs/BUILD.in @@ -1,7 +1,7 @@ load("@rules_dx_cuda//rules:defs.bzl", "cuda_library") cuda_library( - name = "keepplatforms_cuda", + name = "keeparchs_cuda", srcs = ["a.cu"], - platforms = ["sm_120"], + cuda_archs = ["sm_120"], ) diff --git a/gazelle/cc/testdata/cuda_generate/pkg/keepplatforms/BUILD.out b/gazelle/cc/testdata/cuda_generate/pkg/keeparchs/BUILD.out similarity index 73% rename from gazelle/cc/testdata/cuda_generate/pkg/keepplatforms/BUILD.out rename to gazelle/cc/testdata/cuda_generate/pkg/keeparchs/BUILD.out index 01fc71721b..14f7e8865b 100644 --- a/gazelle/cc/testdata/cuda_generate/pkg/keepplatforms/BUILD.out +++ b/gazelle/cc/testdata/cuda_generate/pkg/keeparchs/BUILD.out @@ -1,11 +1,11 @@ load("@rules_dx_cuda//rules:defs.bzl", "cuda_library") cuda_library( - name = "keepplatforms_cuda", + name = "keeparchs_cuda", srcs = [ "a.cu", "b.cu", ], - platforms = ["sm_120"], + cuda_archs = ["sm_120"], visibility = ["//visibility:public"], ) diff --git a/gazelle/cc/testdata/cuda_generate/pkg/keepplatforms/a.cu b/gazelle/cc/testdata/cuda_generate/pkg/keeparchs/a.cu similarity index 100% rename from gazelle/cc/testdata/cuda_generate/pkg/keepplatforms/a.cu rename to gazelle/cc/testdata/cuda_generate/pkg/keeparchs/a.cu diff --git a/gazelle/cc/testdata/cuda_generate/pkg/keepplatforms/b.cu b/gazelle/cc/testdata/cuda_generate/pkg/keeparchs/b.cu similarity index 100% rename from gazelle/cc/testdata/cuda_generate/pkg/keepplatforms/b.cu rename to gazelle/cc/testdata/cuda_generate/pkg/keeparchs/b.cu diff --git a/gazelle/cc/testdata/cuda_generate/pkg/multi/BUILD.in b/gazelle/cc/testdata/cuda_generate/pkg/multi/BUILD.in index 718aa2cb89..fcac0476ff 100644 --- a/gazelle/cc/testdata/cuda_generate/pkg/multi/BUILD.in +++ b/gazelle/cc/testdata/cuda_generate/pkg/multi/BUILD.in @@ -1 +1 @@ -# gazelle:dx_cuda_platforms compute_89:compute_89,sm_89 sm_120 +# gazelle:dx_cuda_archs compute_89:compute_89,sm_89 sm_120 diff --git a/gazelle/cc/testdata/cuda_generate/pkg/multi/BUILD.out b/gazelle/cc/testdata/cuda_generate/pkg/multi/BUILD.out index 3c411dba05..16b0f638e3 100644 --- a/gazelle/cc/testdata/cuda_generate/pkg/multi/BUILD.out +++ b/gazelle/cc/testdata/cuda_generate/pkg/multi/BUILD.out @@ -1,11 +1,11 @@ load("@rules_dx_cuda//rules:defs.bzl", "cuda_library") -# gazelle:dx_cuda_platforms compute_89:compute_89,sm_89 sm_120 +# gazelle:dx_cuda_archs compute_89:compute_89,sm_89 sm_120 cuda_library( name = "multi_cuda", srcs = ["m.cu"], - platforms = [ + cuda_archs = [ "compute_89:compute_89,sm_89", "sm_120", ], diff --git a/gazelle/cc/testdata/cuda_generate/pkg/newgpu/BUILD.out b/gazelle/cc/testdata/cuda_generate/pkg/newgpu/BUILD.out index 9ed8e5eaea..fa0bbc8435 100644 --- a/gazelle/cc/testdata/cuda_generate/pkg/newgpu/BUILD.out +++ b/gazelle/cc/testdata/cuda_generate/pkg/newgpu/BUILD.out @@ -13,6 +13,6 @@ cuda_library( name = "newgpu_cuda", srcs = ["kernel.cu"], hdrs = ["kernel.cuh"], - platforms = ["sm_89"], + cuda_archs = ["sm_89"], visibility = ["//visibility:public"], ) diff --git a/gazelle/cc/testdata/cuda_generate/pkg/stale/BUILD.in b/gazelle/cc/testdata/cuda_generate/pkg/stale/BUILD.in index 3e75634262..966797ee72 100644 --- a/gazelle/cc/testdata/cuda_generate/pkg/stale/BUILD.in +++ b/gazelle/cc/testdata/cuda_generate/pkg/stale/BUILD.in @@ -3,11 +3,11 @@ load("@rules_dx_cuda//rules:defs.bzl", "cuda_library") cuda_library( name = "stale_cuda", srcs = ["gone.cu"], - platforms = ["sm_89"], + cuda_archs = ["sm_89"], ) cuda_library( name = "kernel", srcs = ["hand.cu"], - platforms = ["sm_89"], + cuda_archs = ["sm_89"], ) diff --git a/gazelle/cc/testdata/cuda_generate/pkg/stale/BUILD.out b/gazelle/cc/testdata/cuda_generate/pkg/stale/BUILD.out index d55f84d142..3ddccd030a 100644 --- a/gazelle/cc/testdata/cuda_generate/pkg/stale/BUILD.out +++ b/gazelle/cc/testdata/cuda_generate/pkg/stale/BUILD.out @@ -3,5 +3,5 @@ load("@rules_dx_cuda//rules:defs.bzl", "cuda_library") cuda_library( name = "kernel", srcs = ["hand.cu"], - platforms = ["sm_89"], + cuda_archs = ["sm_89"], ) diff --git a/gazelle/cc/testdata/cuda_keep/pkg/gpu/BUILD.in b/gazelle/cc/testdata/cuda_keep/pkg/gpu/BUILD.in index 60eaf75c29..e3ddb4b2eb 100644 --- a/gazelle/cc/testdata/cuda_keep/pkg/gpu/BUILD.in +++ b/gazelle/cc/testdata/cuda_keep/pkg/gpu/BUILD.in @@ -4,5 +4,5 @@ cuda_library( name = "kernel", srcs = ["kernel.cu"], hdrs = ["kernel.cuh"], - platforms = ["sm_89"], + cuda_archs = ["sm_89"], ) diff --git a/gazelle/cc/testdata/cuda_keep/pkg/gpu/BUILD.out b/gazelle/cc/testdata/cuda_keep/pkg/gpu/BUILD.out index 6015e3dc99..adbeb90824 100644 --- a/gazelle/cc/testdata/cuda_keep/pkg/gpu/BUILD.out +++ b/gazelle/cc/testdata/cuda_keep/pkg/gpu/BUILD.out @@ -5,7 +5,7 @@ cuda_library( name = "kernel", srcs = ["kernel.cu"], hdrs = ["kernel.cuh"], - platforms = ["sm_89"], + cuda_archs = ["sm_89"], ) cc_library( diff --git a/gazelle/cc/testdata/cuda_keep/pkg/gpuonly/BUILD.in b/gazelle/cc/testdata/cuda_keep/pkg/gpuonly/BUILD.in index 60eaf75c29..e3ddb4b2eb 100644 --- a/gazelle/cc/testdata/cuda_keep/pkg/gpuonly/BUILD.in +++ b/gazelle/cc/testdata/cuda_keep/pkg/gpuonly/BUILD.in @@ -4,5 +4,5 @@ cuda_library( name = "kernel", srcs = ["kernel.cu"], hdrs = ["kernel.cuh"], - platforms = ["sm_89"], + cuda_archs = ["sm_89"], ) diff --git a/gazelle/cc/testdata/cuda_keep/pkg/gpuonly/BUILD.out b/gazelle/cc/testdata/cuda_keep/pkg/gpuonly/BUILD.out index 60eaf75c29..e3ddb4b2eb 100644 --- a/gazelle/cc/testdata/cuda_keep/pkg/gpuonly/BUILD.out +++ b/gazelle/cc/testdata/cuda_keep/pkg/gpuonly/BUILD.out @@ -4,5 +4,5 @@ cuda_library( name = "kernel", srcs = ["kernel.cu"], hdrs = ["kernel.cuh"], - platforms = ["sm_89"], + cuda_archs = ["sm_89"], ) diff --git a/gazelle/cc/testdata/cuda_keep/pkg/hostinc/BUILD.in b/gazelle/cc/testdata/cuda_keep/pkg/hostinc/BUILD.in index 3956c5f5ec..8287ee5a0f 100644 --- a/gazelle/cc/testdata/cuda_keep/pkg/hostinc/BUILD.in +++ b/gazelle/cc/testdata/cuda_keep/pkg/hostinc/BUILD.in @@ -6,5 +6,5 @@ cuda_library( name = "kernel", srcs = ["kernel.cu"], hdrs = ["kernel.cuh"], - platforms = ["sm_89"], + cuda_archs = ["sm_89"], ) diff --git a/gazelle/cc/testdata/cuda_keep/pkg/hostinc/BUILD.out b/gazelle/cc/testdata/cuda_keep/pkg/hostinc/BUILD.out index 321981072f..9c15ad9784 100644 --- a/gazelle/cc/testdata/cuda_keep/pkg/hostinc/BUILD.out +++ b/gazelle/cc/testdata/cuda_keep/pkg/hostinc/BUILD.out @@ -7,7 +7,7 @@ cuda_library( name = "kernel", srcs = ["kernel.cu"], hdrs = ["kernel.cuh"], - platforms = ["sm_89"], + cuda_archs = ["sm_89"], ) cc_library( diff --git a/gazelle/dispatch/lang_test.go b/gazelle/dispatch/lang_test.go index 8d9d9c27c7..cdb948ca90 100644 --- a/gazelle/dispatch/lang_test.go +++ b/gazelle/dispatch/lang_test.go @@ -815,11 +815,11 @@ func TestAndroidSelectSkipped(t *testing.T) { } func TestAndroidAbisNeverChecked(t *testing.T) { - build := apkBuild(" platforms = [\"mips\"],\n app_id = \"org.example.adoptandroid\",\n manifest = \"AndroidManifest.xml\",\n") + build := apkBuild(" platforms = [\"//platforms:mips\"],\n app_id = \"org.example.adoptandroid\",\n manifest = \"AndroidManifest.xml\",\n") l, f := androidCheck(t, build, map[string]string{"AndroidManifest.xml": androidTestManifest}) wantAndroidErrors(t, l) - if got := strings.Join(f.Rules[0].AttrStrings("platforms"), ","); got != "mips" { - t.Errorf("platforms = %q, want mips unchanged", got) + if got := strings.Join(f.Rules[0].AttrStrings("platforms"), ","); got != "//platforms:mips" { + t.Errorf("platforms = %q, want //platforms:mips unchanged", got) } } diff --git a/libs/starlark/packaging.bzl b/libs/starlark/packaging.bzl index 94d84a0a4f..acf396b5ba 100644 --- a/libs/starlark/packaging.bzl +++ b/libs/starlark/packaging.bzl @@ -1,4 +1,4 @@ -"""Shared path and platform helpers for package rules.""" +"""Shared path helpers for package rules.""" def data_path(file, label): """Returns the install path of a data file relative to its target's package.""" @@ -8,15 +8,6 @@ def data_path(file, label): prefix = ("../" + label.repo_name + "/" if label.repo_name else "") + (label.package + "/" if label.package else "") return file.short_path[len(prefix):] -def platform_arch(has_constraint, os, arches): - """Returns the first matching arch name for the target OS, or "".""" - if not has_constraint(os): - return "" - for name, constraint in arches: - if has_constraint(constraint): - return name - return "" - def claim_dest(seen, dest, value, fold_case = False): """Records value for dest and returns the earlier value, or None.""" key = dest.lower() if fold_case else dest diff --git a/libs/starlark/platform.bzl b/libs/starlark/platform.bzl index 77f038e7e2..eef1a98c01 100644 --- a/libs/starlark/platform.bzl +++ b/libs/starlark/platform.bzl @@ -14,7 +14,7 @@ def _platform_transition_impl(settings, attr): return {"//command_line_option:platforms": settings["//command_line_option:platforms"]} return {"//command_line_option:platforms": [str(attr.platform)]} -_platform_transition = transition( +platform_transition = transition( implementation = _platform_transition_impl, inputs = ["//command_line_option:platforms"], outputs = ["//command_line_option:platforms"], @@ -50,7 +50,7 @@ PLATFORM_ATTRS = { providers = [platform_common.PlatformInfo], ), "_platform_probe": attr.label( - cfg = _platform_transition, + cfg = platform_transition, default = Label("//libs/starlark:platform_probe"), ), } @@ -58,3 +58,9 @@ PLATFORM_ATTRS = { def platform_identity(ctx): """Returns the DxPlatformInfo for ctx.attr.platform, or for the current platform when unset.""" return ctx.attr._platform_probe[0][DxPlatformInfo] + +def single_platform_error(rule, platforms): + """Returns the error for a platforms list that does not hold exactly one item, or "".""" + if len(platforms) == 1: + return "" + return rule + ": platforms takes exactly one platform label, got " + str(len(platforms)) diff --git a/libs/starlark/tests/packaging_tests.bzl b/libs/starlark/tests/packaging_tests.bzl index ec9fbb5a1b..af75c65476 100644 --- a/libs/starlark/tests/packaging_tests.bzl +++ b/libs/starlark/tests/packaging_tests.bzl @@ -1,7 +1,8 @@ """Unit tests for the shared packaging helpers.""" load("//libs/starlark:defs.bzl", "expect_equal", "starlark_test") -load("//libs/starlark:packaging.bzl", "claim_dest", "data_path", "platform_arch") +load("//libs/starlark:packaging.bzl", "claim_dest", "data_path") +load("//libs/starlark:platform.bzl", "single_platform_error") def _data_path_checks(): root = struct(repo_name = "", package = "") @@ -45,16 +46,11 @@ def _claim_checks(): expect_equal("seeded entry is reported", claim_dest(seeded, "AppxManifest.xml", "data", fold_case = True), "the generated manifest"), ] -def _has(constraints): - return lambda c: c in constraints - -def _platform_arch_checks(): - arches = [("aarch64", "arm64"), ("x86_64", "x86_64")] +def _single_platform_checks(): return [ - expect_equal("arm match", platform_arch(_has(["linux", "arm64"]), "linux", arches), "aarch64"), - expect_equal("x86 match", platform_arch(_has(["linux", "x86_64"]), "linux", arches), "x86_64"), - expect_equal("wrong os", platform_arch(_has(["macos", "arm64"]), "linux", arches), ""), - expect_equal("os without a pinned arch", platform_arch(_has(["linux", "riscv64"]), "linux", arches), ""), + expect_equal("one platform", single_platform_error("dx_x", ["//p:a"]), ""), + expect_equal("no platform", single_platform_error("dx_x", []), "dx_x: platforms takes exactly one platform label, got 0"), + expect_equal("two platforms", single_platform_error("dx_x", ["//p:a", "//p:b"]), "dx_x: platforms takes exactly one platform label, got 2"), ] def packaging_unit_tests(name): @@ -62,5 +58,5 @@ def packaging_unit_tests(name): starlark_test( name = name, mode = "unit", - checks = _data_path_checks() + _claim_checks() + _platform_arch_checks(), + checks = _data_path_checks() + _claim_checks() + _single_platform_checks(), ) diff --git a/quality/testdata/nvcc_syntax/BUILD.bazel b/quality/testdata/nvcc_syntax/BUILD.bazel index ba976014a9..2b9a5699d2 100644 --- a/quality/testdata/nvcc_syntax/BUILD.bazel +++ b/quality/testdata/nvcc_syntax/BUILD.bazel @@ -26,14 +26,14 @@ cuda_library( "dep.cuh", "host_only.cuh", ], - platforms = ["sm_89"], + cuda_archs = ["sm_89"], includes = ["."], ) cuda_library( name = "clean", srcs = ["clean.cu"], - platforms = ["sm_89"], + cuda_archs = ["sm_89"], copts = ["-DCLEAN_OFFSET=1"], deps = [":dep"], ) @@ -41,7 +41,7 @@ cuda_library( cuda_library( name = "two_archs", srcs = ["two_archs.cu"], - platforms = [ + cuda_archs = [ "sm_80", "sm_89", ], @@ -53,7 +53,7 @@ cuda_library( cuda_library( name = "dirty", srcs = ["dirty.cu"], - platforms = ["sm_89"], + cuda_archs = ["sm_89"], tags = ["manual"], deps = [":dep"], ) diff --git a/rust/tests/fixtures/shared-rust-checks/repos.bzl b/rust/tests/fixtures/shared-rust-checks/repos.bzl index a8c2b1ebe7..b0c910918a 100644 --- a/rust/tests/fixtures/shared-rust-checks/repos.bzl +++ b/rust/tests/fixtures/shared-rust-checks/repos.bzl @@ -236,7 +236,7 @@ rust_android_apk( name = "consumer_apk", testonly = True, app_id = "org.example.consumer.tasks", - platforms = ["x86_64"], + platforms = ["@rules_dx_android//platforms:x86_64"], api_level = 33, assets = [ ":assets/board.txt", diff --git a/swift/README.md b/swift/README.md index 1cf203801b..ac656f3d33 100644 --- a/swift/README.md +++ b/swift/README.md @@ -21,7 +21,9 @@ swift_binary( ``` `swift_library`, `swift_binary` and `swift_test` build for Linux on their own. -You need no `--platforms` or `--extra_execution_platforms` flags. +You need no `--platforms` or `--extra_execution_platforms` flags. To build for another +platform, pass `platforms = ["//your:platform"]` to the wrapper; it takes one label, and +empty uses the current target platform. Binaries and tests link the Swift runtime statically and need only the system C library. ```sh diff --git a/swift/platforms/transition.bzl b/swift/platforms/transition.bzl index e1f0f072e8..fa3e25c01e 100644 --- a/swift/platforms/transition.bzl +++ b/swift/platforms/transition.bzl @@ -1,5 +1,7 @@ """Builds Swift targets for the Swift Linux platform.""" +load("//libs/starlark:platform.bzl", "single_platform_error") + _PLATFORMS = "//command_line_option:platforms" _EXEC = "//command_line_option:extra_execution_platforms" _TOOLCHAINS = "//command_line_option:extra_toolchains" @@ -14,14 +16,16 @@ def swift_transition_settings(settings, attr): Returns: The new platforms, execution platforms and toolchains. """ - toolchains = [str(t) for t in getattr(attr, "swift_extra_toolchains", [])] + toolchains = [str(t) for t in attr._swift_extra_toolchains] for t in settings[_TOOLCHAINS]: if str(t) not in toolchains: toolchains.append(str(t)) - platform = attr.swift_platform - if platform == "": + if len(attr.platforms) == 0: return {_PLATFORMS: settings[_PLATFORMS], _EXEC: settings[_EXEC], _TOOLCHAINS: toolchains} - platform = str(Label(platform)) + error = single_platform_error("swift", attr.platforms) + if error: + fail(error) + platform = str(attr.platforms[0]) return { _PLATFORMS: [platform], _EXEC: [platform] + [str(p) for p in settings[_EXEC] if str(p) != platform], @@ -37,17 +41,10 @@ swift_linux_transition = transition( outputs = [_PLATFORMS, _EXEC, _TOOLCHAINS], ) -def swift_linux_platform(): - """Returns the Swift platform label for the current Linux cpu, or an empty string.""" - return select({ - Label("//swift/platforms:is_linux_aarch64"): "//swift/platforms:exec_linux_aarch64", - Label("//swift/platforms:is_linux_x86_64"): "//swift/platforms:exec_linux_x86_64", - "//conditions:default": "", - }) - -def swift_extra_toolchains(): - """Returns the toolchains Swift targets prefer: the Xcode C++ toolchain on macOS.""" +def swift_linux_platforms(): + """Returns the Linux platform for the current target cpu, or no platform elsewhere.""" return select({ - Label("@platforms//os:macos"): [str(Label("@local_config_apple_cc_toolchains//:all"))], + Label("//swift/platforms:is_linux_aarch64"): [Label("//swift/platforms:exec_linux_aarch64")], + Label("//swift/platforms:is_linux_x86_64"): [Label("//swift/platforms:exec_linux_x86_64")], "//conditions:default": [], }) diff --git a/swift/platforms/transition_tests.bzl b/swift/platforms/transition_tests.bzl index 7ee533f310..841566a024 100644 --- a/swift/platforms/transition_tests.bzl +++ b/swift/platforms/transition_tests.bzl @@ -12,25 +12,25 @@ def _settings(toolchains = []): "//command_line_option:platforms": ["@@//:p"], } -def _attr(platform = "", toolchains = []): - return struct(swift_platform = platform, swift_extra_toolchains = toolchains) +def _attr(platforms = [], toolchains = []): + return struct(platforms = platforms, _swift_extra_toolchains = toolchains) def _linux_test_impl(ctx): env = unittest.begin(ctx) - out = swift_transition_settings(_settings(["//a:b"]), _attr("//swift/platforms:exec_linux_x86_64")) + out = swift_transition_settings(_settings(["//a:b"]), _attr(["//swift/platforms:exec_linux_x86_64"])) asserts.equals(env, ["//a:b"], out["//command_line_option:extra_toolchains"]) asserts.equals(env, 1, len(out["//command_line_option:platforms"])) return unittest.end(env) def _macos_first_test_impl(ctx): env = unittest.begin(ctx) - out = swift_transition_settings(_settings(["//a:b"]), _attr("", [_APPLE])) + out = swift_transition_settings(_settings(["//a:b"]), _attr([], [_APPLE])) asserts.equals(env, [_APPLE, "//a:b"], out["//command_line_option:extra_toolchains"]) return unittest.end(env) def _idempotent_test_impl(ctx): env = unittest.begin(ctx) - attr = _attr("", [_APPLE]) + attr = _attr([], [_APPLE]) once = swift_transition_settings(_settings(["//a:b"]), attr) twice = swift_transition_settings(once, attr) asserts.equals(env, once, twice) diff --git a/swift/rules/defs.bzl b/swift/rules/defs.bzl index 2e4da67896..23c0df408b 100644 --- a/swift/rules/defs.bzl +++ b/swift/rules/defs.bzl @@ -11,14 +11,19 @@ load("//libs/starlark:fuzz.bzl", "dx_fuzz_binary", "dx_fuzz_runner") load("//libs/starlark:fuzz_bench.bzl", "merge_tags", "split_runner_kwargs", "split_test_kwargs", "with_default_size") load("//libs/starlark:wrapper.bzl", "DX_EXEC_PROVIDES", "dx_append_flags", "dx_executable_forward_rule", "dx_library_forward_rule", "dx_wrap", "dx_wrap_binary", "dx_wrap_test") load("//quality:sources.bzl", "QualitySourcesInfo", "QualityToolsInfo") -load("//swift/platforms:transition.bzl", "swift_extra_toolchains", "swift_linux_platform", "swift_linux_transition") +load("//swift/platforms:transition.bzl", "swift_linux_platforms", "swift_linux_transition") # Re-exported unchanged: BUILD files need it to expose C modules to Swift. swift_interop_hint = _swift_interop_hint _PLATFORM_ATTR = { - "swift_extra_toolchains": attr.string_list(doc = "Toolchains put first for Swift targets."), - "swift_platform": attr.string(doc = "Swift platform to build for."), + "platforms": attr.label_list( + doc = "The one platform to build for. Empty uses the current target platform.", + providers = [platform_common.PlatformInfo], + ), + "_swift_extra_toolchains": attr.string_list( + default = [str(Label("@local_config_apple_cc_toolchains//:all"))], + ), } _STATIC = ["swift.static_stdlib", "-static_link_cpp_runtimes"] _INDEX = ["swift.index_while_building", "swift.disable_system_index", "-swift.index_store_compress"] @@ -70,20 +75,17 @@ _swift_forward_test = dx_executable_forward_rule( quality_tools = SWIFT_QUALITY_TOOLS, ) -def _forward(): - return {"swift_extra_toolchains": swift_extra_toolchains(), "swift_platform": swift_linux_platform()} - -def swift_library(name, srcs = None, visibility = None, **kwargs): +def swift_library(name, srcs = None, visibility = None, platforms = None, **kwargs): """Wraps swift_library and builds it for Linux, or with Xcode on macOS.""" - dx_wrap(name, _swift_library, _swift_library_forward, srcs, visibility = visibility, upstream_kwargs = dx_append_flags(kwargs, "features", _STATIC + _INDEX), quality_srcs = srcs or [], extra_forward_kwargs = _forward(), **kwargs) + dx_wrap(name, _swift_library, _swift_library_forward, srcs, visibility = visibility, upstream_kwargs = dx_append_flags(kwargs, "features", _STATIC + _INDEX), quality_srcs = srcs or [], extra_forward_kwargs = {"platforms": platforms if platforms != None else swift_linux_platforms()}, **kwargs) -def swift_binary(name, srcs = None, visibility = None, **kwargs): +def swift_binary(name, srcs = None, visibility = None, platforms = None, **kwargs): """Wraps swift_binary and builds it for Linux, or with Xcode on macOS.""" - dx_wrap_binary(name, _swift_binary, _swift_binary_forward, srcs, visibility = visibility, upstream_kwargs = dx_append_flags(kwargs, "features", _STATIC + _INDEX), quality_srcs = srcs or [], extra_forward_kwargs = _forward(), **kwargs) + dx_wrap_binary(name, _swift_binary, _swift_binary_forward, srcs, visibility = visibility, upstream_kwargs = dx_append_flags(kwargs, "features", _STATIC + _INDEX), quality_srcs = srcs or [], extra_forward_kwargs = {"platforms": platforms if platforms != None else swift_linux_platforms()}, **kwargs) -def swift_test(name, srcs = None, visibility = None, **kwargs): +def swift_test(name, srcs = None, visibility = None, platforms = None, **kwargs): """Wraps swift_test and builds it for Linux, or with Xcode on macOS.""" - dx_wrap_test(name, _swift_test, _swift_forward_test, srcs, visibility = visibility, upstream_kwargs = dx_append_flags(kwargs, "features", _STATIC + _INDEX), quality_srcs = srcs or [], extra_forward_kwargs = _forward(), **kwargs) + dx_wrap_test(name, _swift_test, _swift_forward_test, srcs, visibility = visibility, upstream_kwargs = dx_append_flags(kwargs, "features", _STATIC + _INDEX), quality_srcs = srcs or [], extra_forward_kwargs = {"platforms": platforms if platforms != None else swift_linux_platforms()}, **kwargs) def swift_fuzz_test(name, srcs = None, visibility = None, tags = None, copts = None, linkopts = None, **kwargs): """A libFuzzer binary with AddressSanitizer plus a `_run` runner for `dx fuzz`. Linux only.""" diff --git a/tools/testing/hermetic/cuda_gpu_test.rs b/tools/testing/hermetic/cuda_gpu_test.rs index 16e7f82a08..668991d9cf 100644 --- a/tools/testing/hermetic/cuda_gpu_test.rs +++ b/tools/testing/hermetic/cuda_gpu_test.rs @@ -9,7 +9,7 @@ cuda_library( name = "kernels", srcs = ["reduce.cu", "stencil.cu", "vector_add.cu"], hdrs = ["common.cuh", "kernels.h"], - platforms = ["compute_80:compute_80,sm_80", "sm_90"], + cuda_archs = ["compute_80:compute_80,sm_80", "sm_90"], visibility = ["//visibility:public"], ) "#; diff --git a/tools/testing/starters/fixtures/cuda/BUILD.bazel.fixture b/tools/testing/starters/fixtures/cuda/BUILD.bazel.fixture index 19ae2e0f73..bb7c5581a1 100644 --- a/tools/testing/starters/fixtures/cuda/BUILD.bazel.fixture +++ b/tools/testing/starters/fixtures/cuda/BUILD.bazel.fixture @@ -8,7 +8,7 @@ cuda_library( "scale.cuh", "scale.h", ], - platforms = [ + cuda_archs = [ "compute_89:compute_89,sm_89", "sm_120", ], diff --git a/tools/testing/starters/fixtures/rust-android/BUILD.bazel.fixture b/tools/testing/starters/fixtures/rust-android/BUILD.bazel.fixture index 196401ef51..06bab7fdf2 100644 --- a/tools/testing/starters/fixtures/rust-android/BUILD.bazel.fixture +++ b/tools/testing/starters/fixtures/rust-android/BUILD.bazel.fixture @@ -31,8 +31,8 @@ cc_library( rust_android_apk( name = "demo-app_apk", platforms = [ - "arm64-v8a", - "x86_64", + "@rules_dx_android//platforms:arm64-v8a", + "@rules_dx_android//platforms:x86_64", ], api_level = 31, app_id = "com.example.demo_app",