Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions appimage/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
16 changes: 6 additions & 10 deletions appimage/defs.bzl
Original file line number Diff line number Diff line change
@@ -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(
Expand All @@ -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
Expand Down Expand Up @@ -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/<name>.", 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):
Expand Down
2 changes: 1 addition & 1 deletion docs/cli/commands/generate.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ Set directives as `# gazelle:<name> <value>` comments in a `BUILD` file. They ap
| `dx_external <ecosystem> <path\|off> [<repo>]` | 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 <repo>` | Load `aliases` and `all_crate_deps` for Cargo packages from the crate_universe hub `@<repo>` instead of `@crates`. The package needs a `BUILD` file. |
| `dx_cuda_platforms <spec> <spec>...` | Set `platforms` of a generated `cuda_library`. Required for `.cu` and `.cuh` files. |
| `dx_cuda_archs <spec> <spec>...` | 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 <languages>` | Must list `dx_dispatch`, for example `go,dx_dispatch`. |

Expand Down
7 changes: 4 additions & 3 deletions families/android/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,8 @@ rust_android_apk(
The package links one `lib/<abi>/lib<name>_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
Expand Down Expand Up @@ -226,15 +227,15 @@ 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"],
)
```

| Attribute | Default | Meaning |
| --- | --- | --- |
| `package` | required | The `.apk` or `.aab` to check. |
| `platforms` | `[]` | ABIs that must ship a `base/lib/<abi>/*.so`. App Bundles only. |
| `platforms` | `[]` | Platform labels whose ABI must ship a `base/lib/<abi>/*.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. |

Expand Down
14 changes: 7 additions & 7 deletions families/android/packaging/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -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",
)

Expand Down Expand Up @@ -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 = [],
)
Expand Down Expand Up @@ -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",
)

Expand Down
28 changes: 19 additions & 9 deletions families/android/packaging/defs.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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-")
Expand Down Expand Up @@ -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 = [],
Expand All @@ -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,
Expand Down Expand Up @@ -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,
Expand All @@ -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"],
Expand All @@ -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",
Expand Down Expand Up @@ -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])
Expand Down
4 changes: 2 additions & 2 deletions families/android/tests/fixtures/consumer_android/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
14 changes: 7 additions & 7 deletions families/android/tests/fixtures/rust_apk/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -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"],
)
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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 = [
Expand All @@ -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",
Expand Down
4 changes: 3 additions & 1 deletion families/apple/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ filegroup(
"//bundle:module_srcs",
"//ios:module_srcs",
"//macos:module_srcs",
"//platforms:module_srcs",
"//provisioning:module_srcs",
"//signing:module_srcs",
],
Expand All @@ -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
Expand Down
10 changes: 8 additions & 2 deletions families/apple/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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
Expand Down Expand Up @@ -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`
Expand Down
4 changes: 2 additions & 2 deletions families/apple/macos/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -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",
)

Expand Down
Loading
Loading