diff --git a/AGENTS.md b/AGENTS.md index 25f91f12b7..0cf0e2ac91 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -10,7 +10,7 @@ This repository uses Bazel. - Generate files at build time. If one must be checked in, a freshness test regenerates and diffs it; never sync it by hand. Generated data holds only non-default keys. - `core/` never loads a language `.bzl` file. One exception: `core/quality/tools.bzl` loads the `_tools.bzl` files. - Root holds only language directories and the shared directories in `docs/design/layout.md`. -- Docs are for people who use or release rules_dx: command pages, guides, tutorials, the generated `docs/support-matrix.md`, READMEs, `examples/`, and runbooks like `RELEASING.md`. Never write design rationale, history, alternatives, or implementation notes. One exception: the "What rules_dx replaces" section in `README.md` may state what you get and what it costs. Keep it to those two lists. +- Docs are for people who use or release rules_dx: command pages, guides, tutorials, READMEs, `examples/`, and runbooks like `RELEASING.md`. The docs build generates doc pages such as the support matrix, the supported surface, the quality configs and the language pages. Never commit them. Never write design rationale, history, alternatives, or implementation notes. One exception: the "What rules_dx replaces" section in `README.md` may state what you get and what it costs. Keep it to those two lists. - User docs stay complete: every command page documents its flags, scopes, output, reports, exit codes, and examples. Match `dx --help`. Keep them user-facing; still no rationale, history, or issue numbers. - No comments in any language, Rust `///`/`//!` and Go doc comments included. Use names and tests instead. Assigned strings like `_HUB_BUILD = """..."""` are code, not comments. - Kept: tool directives, shebangs, license headers, lines tools parse (`# Why:`, `# Upstream:`, `# dx:`), `LCOV_EXCL_*`, `# floor:`, `// SAFETY:`, one Starlark docstring line per item, one clap `--help` line per flag. diff --git a/BUILD.bazel b/BUILD.bazel index 81359daa29..49eb6101cf 100644 --- a/BUILD.bazel +++ b/BUILD.bazel @@ -1112,7 +1112,6 @@ real_source_target( "//docs:cli/commands/upgrade.md", "//docs:github-ci.md", "//docs:proxy-and-ca.md", - "//docs:support-matrix.md", "//docs:tutorial.md", "//examples:README.md", "LICENSE", diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index ed9a6e255d..5fb87bf013 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -181,7 +181,7 @@ Without a key, the remote cache returns no hits, so leave `--config=bb` and `--c bazel run //tools/new_language -- [title] ``` -It creates `/` with `defs.bzl`, `extensions.bzl`, `BUILD.bazel`, `lang.json`, `pins.json`, `private/` and `tests/`. Fill in `lang.json`, then refresh the support matrix: +It creates `/` with `defs.bzl`, `extensions.bzl`, `BUILD.bazel`, `lang.json`, `pins.json`, `private/` and `tests/`. Fill in `lang.json` and add the language to `tools/docs/languages/pages.bzl`. Then refresh the unsupported-platform list: ```sh bazel run //tools/docs/support_matrix:update diff --git a/README.md b/README.md index c5254e1c78..88d2855ace 100644 --- a/README.md +++ b/README.md @@ -61,7 +61,7 @@ Already have a Bazel repo? Read New to Bazel and moving an existing project? Read [adopting rules_dx without Bazel experience](docs/adopting-without-bazel.md). You can also browse the [examples](examples/README.md), set up -[CI](docs/github-ci.md), check the [support matrix](docs/support-matrix.md), +[CI](docs/github-ci.md), check the [support matrix](https://devhusdk.github.io/rules_dx/docs/support-matrix.html), or read everything on the [docs site](https://devhusdk.github.io/rules_dx/). ## What rules_dx replaces @@ -167,7 +167,7 @@ version in `.dx/pins` without Bazel. See ## C and C++ toolchains -- Microsoft `cl.exe` (`--//cc:compiler=msvc`): the Visual Studio Build Tools come from the hermetic `@dx_msvc` repo, not an installed Visual Studio. The download needs the Visual Studio Build Tools license, accepted with `dx_licenses.accept(ids = ["visual-studio-build-tools"])`. See the [support matrix](docs/support-matrix.md). +- Microsoft `cl.exe` (`--//cc:compiler=msvc`): the Visual Studio Build Tools come from the hermetic `@dx_msvc` repo, not an installed Visual Studio. The download needs the Visual Studio Build Tools license, accepted with `dx_licenses.accept(ids = ["visual-studio-build-tools"])`. See the [support matrix](https://devhusdk.github.io/rules_dx/docs/support-matrix.html). - GCC (`--//cc:compiler=gcc`): GCC 16.2.0 on `linux_x86_64` and `linux_arm64`, with no install. ## Contributing diff --git a/android/BUILD.bazel b/android/BUILD.bazel index 6c2a440166..675588d270 100644 --- a/android/BUILD.bazel +++ b/android/BUILD.bazel @@ -108,7 +108,6 @@ real_source_target( name = "corpus_markdown", markdown_siblings = [ "//android/tests/fixtures/adopt_android:README.md", - "//docs:languages/android.md", ], markdown_srcs = ["README.md"], tags = ["corpus"], diff --git a/android/README.md b/android/README.md index 8fedfd981b..c882a0962b 100644 --- a/android/README.md +++ b/android/README.md @@ -6,7 +6,7 @@ Load its rules in a `BUILD.bazel` file, the file that declares what Bazel builds, from `@rules_dx//android:defs.bzl`. `extensions.bzl` holds the module extension: the part you call from `MODULE.bazel` to set up toolchains and dependencies. -The tests live in `tests/`. The [Android page](../docs/languages/android.md) shows +The tests live in `tests/`. The [Android page](https://devhusdk.github.io/rules_dx/docs/languages/android.html) shows setup, every rule and the tools dx runs. Run the Android tests from a rules_dx checkout: diff --git a/appimage/BUILD.bazel b/appimage/BUILD.bazel index 1becffe2ca..24d76fd8c2 100644 --- a/appimage/BUILD.bazel +++ b/appimage/BUILD.bazel @@ -60,7 +60,6 @@ real_source_target( name = "corpus_markdown", markdown_siblings = [ "//appimage/tests/fixtures/appimage_app:README.md", - "//docs:languages/appimage.md", ], markdown_srcs = ["README.md"], tags = ["corpus"], diff --git a/appimage/README.md b/appimage/README.md index 0de9ad7f33..cf12ff0825 100644 --- a/appimage/README.md +++ b/appimage/README.md @@ -6,7 +6,7 @@ Load its rules in a `BUILD.bazel` file, the file that declares what Bazel builds, from `@rules_dx//appimage:defs.bzl`. `extensions.bzl` holds the module extension: the part you call from `MODULE.bazel` to set up toolchains and dependencies. -The tests live in `tests/`. The [AppImage page](../docs/languages/appimage.md) shows +The tests live in `tests/`. The [AppImage page](https://devhusdk.github.io/rules_dx/docs/languages/appimage.html) shows setup, every rule and the tools dx runs. Run the AppImage tests from a rules_dx checkout: diff --git a/apple/BUILD.bazel b/apple/BUILD.bazel index 0392ce71b7..8fdd574b4a 100644 --- a/apple/BUILD.bazel +++ b/apple/BUILD.bazel @@ -85,9 +85,6 @@ alias( real_source_target( name = "corpus_markdown", - markdown_siblings = [ - "//docs:languages/apple.md", - ], markdown_srcs = ["README.md"], tags = ["corpus"], ) diff --git a/apple/README.md b/apple/README.md index b981ef7f26..e2c15cf56a 100644 --- a/apple/README.md +++ b/apple/README.md @@ -6,7 +6,7 @@ Load its rules in a `BUILD.bazel` file, the file that declares what Bazel builds, from `@rules_dx//apple:defs.bzl`. `extensions.bzl` holds the module extension: the part you call from `MODULE.bazel` to set up toolchains and dependencies. -The tests live in `tests/`. The [Apple page](../docs/languages/apple.md) shows +The tests live in `tests/`. The [Apple page](https://devhusdk.github.io/rules_dx/docs/languages/apple.html) shows setup, every rule and the tools dx runs. Run the Apple tests from a rules_dx checkout: diff --git a/cc/BUILD.bazel b/cc/BUILD.bazel index cbbcfa77a5..2e47a6f478 100644 --- a/cc/BUILD.bazel +++ b/cc/BUILD.bazel @@ -45,7 +45,6 @@ filegroup( real_source_target( name = "corpus_markdown", markdown_siblings = [ - "//docs:languages/cc.md", "//docs:own-cc-toolchain.md", ], markdown_srcs = ["README.md"], diff --git a/cc/README.md b/cc/README.md index db72ae54fe..f8d552687e 100644 --- a/cc/README.md +++ b/cc/README.md @@ -6,7 +6,7 @@ Load its rules in a `BUILD.bazel` file, the file that declares what Bazel builds, from `@rules_dx//cc:defs.bzl`. `extensions.bzl` holds the module extension: the part you call from `MODULE.bazel` to set up toolchains and dependencies. -The tests live in `tests/`. The [C and C++ page](../docs/languages/cc.md) shows +The tests live in `tests/`. The [C and C++ page](https://devhusdk.github.io/rules_dx/docs/languages/cc.html) shows setup, every rule and the tools dx runs. Run the C and C++ tests from a rules_dx checkout: diff --git a/cli/exec_audit/BUILD.bazel b/cli/exec_audit/BUILD.bazel index 9b5627f1ea..cf60bb544f 100644 --- a/cli/exec_audit/BUILD.bazel +++ b/cli/exec_audit/BUILD.bazel @@ -66,12 +66,12 @@ rust_test( aliases = {}, # keep compile_data = [ "clippy.toml", - "//docs:support-matrix.md", "//haskell/tests/fixtures/stack:stack.yaml.lock", ], coverage_lib = ":dx_exec_audit", crate_name = "dx_exec_audit", crate_root = "src/lib.rs", + data = ["//docs:support-matrix.md"], # keep deps = [ "//cli/adopt:dx_adopt", @@ -93,6 +93,7 @@ rust_test( "//cli/sbom/schema:dx_sbom_schema", "//cli/tool_resolve:dx_tool_resolve", "//cli/update:dx_update", + "//tools/testing:dx_testing", "@crates//:chrono", "@crates//:serde_json", "@crates//:tempfile", diff --git a/cli/exec_audit/src/audit_uncovered.rs b/cli/exec_audit/src/audit_uncovered.rs index b580bdada6..fc5f80ce85 100644 --- a/cli/exec_audit/src/audit_uncovered.rs +++ b/cli/exec_audit/src/audit_uncovered.rs @@ -104,16 +104,17 @@ fn walk( mod tests { use super::{find_unowned, unowned_names}; - const MATRIX: &str = include_str!("../../../docs/support-matrix.md"); - #[test] fn locks_without_a_set_have_a_none_reason_in_the_matrix() { + let matrix = + std::fs::read_to_string(dx_testing::resolve_runfiles("docs/support-matrix.md")) + .expect("support-matrix.md"); for (name, _, _) in unowned_names() .expect("hub") .iter() .filter(|(_, _, has_set)| !has_set) { - let shown = MATRIX.lines().any(|line| { + let shown = matrix.lines().any(|line| { line.contains(&format!("`{name}`")) && (line.contains("none for ") || line.contains("| none:")) }); diff --git a/core/quality/tool_config_docs.bzl b/core/quality/tool_config_docs.bzl index f1d634985f..b720000e70 100644 --- a/core/quality/tool_config_docs.bzl +++ b/core/quality/tool_config_docs.bzl @@ -1,14 +1,9 @@ -"""Renders the tool config table in docs/cli/commands/quality.md from tools.bzl.""" +"""Renders the tool config table of the quality configs page from tools.bzl.""" -load("@bazel_lib//lib:write_source_files.bzl", "write_source_files") -load("@bazel_skylib//rules:write_file.bzl", "write_file") load(":curated_defaults.bzl", "CROSS_FAMILY_TOOLS", "CURATED_DEFAULTS") load(":tools.bzl", "TOOLS") -visibility(["//docs/..."]) - -BEGIN = "" -END = "" +visibility(["//tools/docs/quality_configs"]) _HEADER = [ "| Tool | Level | Native file(s) | Base | Config source | Shared with |", @@ -56,26 +51,4 @@ def tool_config_table(): config.config_source if config.ships_config else "", ", ".join(["`%s`" % id for id in others]), )) - return [BEGIN, ""] + _HEADER + rows + ["", END] - -def tool_config_docs(name, page): - """Declares the update target and currency test for the config table in `page`.""" - write_file( - name = name + "_block", - out = name + "_block.md", - content = tool_config_table() + [""], - ) - native.genrule( - name = name + "_page", - srcs = [page, ":" + name + "_block"], - outs = [name + "_page.md"], - cmd = """awk -v block="$(location :%s_block)" ' -// { skip = 0; next } -!skip { print } -' $(location %s) > $@""" % (name, page), - ) - write_source_files( - name = name, - files = {page: ":" + name + "_page"}, - ) + return _HEADER + rows diff --git a/csharp/BUILD.bazel b/csharp/BUILD.bazel index ddc4fd5471..971af23060 100644 --- a/csharp/BUILD.bazel +++ b/csharp/BUILD.bazel @@ -30,9 +30,6 @@ real_source_target( real_source_target( name = "corpus_markdown", aspect_hints = ["//core/quality:corpus_vale_config"], - markdown_siblings = [ - "//docs:languages/csharp.md", - ], markdown_srcs = ["README.md"], tags = ["corpus"], ) diff --git a/csharp/README.md b/csharp/README.md index 42f06caeb0..29b2c7ee80 100644 --- a/csharp/README.md +++ b/csharp/README.md @@ -6,7 +6,7 @@ Load its rules in a `BUILD.bazel` file, the file that declares what Bazel builds, from `@rules_dx//csharp:defs.bzl`. `extensions.bzl` holds the module extension: the part you call from `MODULE.bazel` to set up toolchains and dependencies. -The tests live in `tests/`. The [C# page](../docs/languages/csharp.md) shows +The tests live in `tests/`. The [C# page](https://devhusdk.github.io/rules_dx/docs/languages/csharp.html) shows setup, every rule and the tools dx runs. Run the C# tests from a rules_dx checkout: @@ -83,4 +83,4 @@ The test assembly counts only with `--instrument_test_targets`. Tag a test ## Platforms -See the [support matrix](https://github.com/devhusdk/rules_dx/blob/main/docs/support-matrix.md). +See the [support matrix](https://devhusdk.github.io/rules_dx/docs/support-matrix.html). diff --git a/cuda/BUILD.bazel b/cuda/BUILD.bazel index f977041125..dd56dc9ea5 100644 --- a/cuda/BUILD.bazel +++ b/cuda/BUILD.bazel @@ -88,9 +88,6 @@ filegroup( real_source_target( name = "corpus_markdown", - markdown_siblings = [ - "//docs:languages/cuda.md", - ], markdown_srcs = ["README.md"], tags = ["corpus"], ) diff --git a/cuda/README.md b/cuda/README.md index d79af20427..1f8ebee170 100644 --- a/cuda/README.md +++ b/cuda/README.md @@ -6,7 +6,7 @@ Load its rules in a `BUILD.bazel` file, the file that declares what Bazel builds, from `@rules_dx//cuda:defs.bzl`. `extensions.bzl` holds the module extension: the part you call from `MODULE.bazel` to set up toolchains and dependencies. -The tests live in `tests/`. The [CUDA page](../docs/languages/cuda.md) shows +The tests live in `tests/`. The [CUDA page](https://devhusdk.github.io/rules_dx/docs/languages/cuda.html) shows setup, every rule and the tools dx runs. Run the CUDA tests from a rules_dx checkout: @@ -183,7 +183,7 @@ rules_dx declares the pinned nvcc toolchain; a consumer adds no ## Platforms -See the [support matrix](https://github.com/devhusdk/rules_dx/blob/main/docs/support-matrix.md). +See the [support matrix](https://devhusdk.github.io/rules_dx/docs/support-matrix.html). On Windows, nvcc compiles with `cl.exe` from the hermetic Visual Studio Build Tools, so you don't set `--//cc:compiler`. `cuda_binary` and `cuda_test` build and link everything in them with `cl.exe`. Link a `cuda_library` into a `cuda_binary` or `cuda_test`: on Windows a `cc_binary` or `cc_test` only takes one under `--//cc:compiler=msvc`. Accept both licenses in the root `MODULE.bazel`: `dx_licenses.accept(ids = ["cuda-eula", "visual-studio-build-tools"])`. diff --git a/d/BUILD.bazel b/d/BUILD.bazel index cbd15cebf2..07b2e086e5 100644 --- a/d/BUILD.bazel +++ b/d/BUILD.bazel @@ -21,10 +21,6 @@ toolchain_type( real_source_target( name = "corpus_markdown", - markdown_siblings = [ - "//docs:languages/d.md", - "//docs:support-matrix.md", - ], markdown_srcs = ["README.md"], tags = ["corpus"], ) diff --git a/d/README.md b/d/README.md index 63bb854712..74717ec351 100644 --- a/d/README.md +++ b/d/README.md @@ -6,7 +6,7 @@ Load its rules in a `BUILD.bazel` file, the file that declares what Bazel builds, from `@rules_dx//d:defs.bzl`. `extensions.bzl` holds the module extension: the part you call from `MODULE.bazel` to set up toolchains and dependencies. -The tests live in `tests/`. The [D page](../docs/languages/d.md) shows +The tests live in `tests/`. The [D page](https://devhusdk.github.io/rules_dx/docs/languages/d.html) shows setup, every rule and the tools dx runs. Run the D tests from a rules_dx checkout: @@ -111,5 +111,5 @@ API reference. ## Platforms -The [support matrix](../docs/support-matrix.md) lists the platforms. On +The [support matrix](https://devhusdk.github.io/rules_dx/docs/support-matrix.html) lists the platforms. On Windows arm64, the x64 LDC runs under emulation. diff --git a/dart/BUILD.bazel b/dart/BUILD.bazel index 346c27a084..4b147985a4 100644 --- a/dart/BUILD.bazel +++ b/dart/BUILD.bazel @@ -4,9 +4,6 @@ package(default_visibility = ["//:__subpackages__"]) real_source_target( name = "corpus_markdown", - markdown_siblings = [ - "//docs:languages/dart.md", - ], markdown_srcs = ["README.md"], tags = ["corpus"], ) diff --git a/dart/README.md b/dart/README.md index 9816e7c0f5..55e949600e 100644 --- a/dart/README.md +++ b/dart/README.md @@ -6,7 +6,7 @@ Load its rules in a `BUILD.bazel` file, the file that declares what Bazel builds, from `@rules_dx//dart:defs.bzl`. `extensions.bzl` holds the module extension: the part you call from `MODULE.bazel` to set up toolchains and dependencies. -The tests live in `tests/`. The [Dart page](../docs/languages/dart.md) shows +The tests live in `tests/`. The [Dart page](https://devhusdk.github.io/rules_dx/docs/languages/dart.html) shows setup, every rule and the tools dx runs. Run the Dart tests from a rules_dx checkout: diff --git a/docs/AGENTS.md b/docs/AGENTS.md index 1c292b51e5..2b79052b6e 100644 --- a/docs/AGENTS.md +++ b/docs/AGENTS.md @@ -1,6 +1,6 @@ # Documentation Instructions -- Docs are for people who use or release rules_dx: command pages, guides, tutorials, the generated `docs/support-matrix.md`, READMEs, `examples/`, and runbooks like `RELEASING.md`. +- Docs are for people who use or release rules_dx: command pages, guides, tutorials, READMEs, `examples/`, and runbooks like `RELEASING.md`. The docs build generates doc pages such as the support matrix, the supported surface, the quality configs and the language pages. Never commit them. - One page per command or task. Commands first. Short sentences. - Write for a person who just arrived: start each page with one line on what it helps them do, then the steps. Use "you". Show a working example before the reference tables. Prefer everyday words over jargon, and explain a Bazel term the first time a page uses it. - User docs stay complete: every command page documents its flags, scopes, output, reports, exit codes, and examples. Match `dx --help`. diff --git a/docs/BUILD.bazel b/docs/BUILD.bazel index 226243f9c3..0bf9bcf0b3 100644 --- a/docs/BUILD.bazel +++ b/docs/BUILD.bazel @@ -1,5 +1,6 @@ +load("@bazel_skylib//rules:copy_file.bzl", "copy_file") load("//core/quality:fixtures.bzl", "real_source_target") -load("//core/quality:tool_config_docs.bzl", "tool_config_docs") +load("//tools/docs/languages:pages.bzl", "LANGUAGES") load("//tools/docs/quality_configs:quality_configs.bzl", "quality_configs_docs") package(default_visibility = ["//:__subpackages__"]) @@ -10,45 +11,7 @@ exports_files([ "cli/commands/generate.md", "cli/commands/init.md", "cli/commands/quality.md", - "languages/android.md", - "languages/appimage.md", - "languages/apple.md", - "languages/cc.md", - "languages/csharp.md", - "languages/cuda.md", - "languages/d.md", - "languages/dart.md", - "languages/elixir.md", - "languages/erlang.md", - "languages/flutter.md", - "languages/fortran.md", - "languages/fsharp.md", - "languages/go.md", - "languages/haskell.md", - "languages/helm.md", - "languages/java.md", - "languages/javascript.md", - "languages/julia.md", - "languages/kotlin.md", - "languages/lua.md", - "languages/msix.md", - "languages/ocaml.md", - "languages/perl.md", - "languages/php.md", - "languages/powershell.md", - "languages/python.md", - "languages/qt.md", - "languages/ruby.md", - "languages/rust.md", - "languages/scala.md", - "languages/swift.md", - "languages/terraform.md", - "languages/typescript.md", - "languages/zig.md", "own-cc-toolchain.md", - "support-matrix.md", - "supported-surface.md", - "quality-configs.md", "tutorial.md", ]) @@ -60,6 +23,9 @@ filegroup( real_source_target( name = "corpus_markdown", markdown_siblings = [ + "quality-configs.md", + "support-matrix.md", + "supported-surface.md", "//.github:workflows/README.md", "//:AGENTS.md", "//android/tests/fixtures/adopt_android:README.md", @@ -121,70 +87,11 @@ real_source_target( "own-cc-toolchain.md", "remote-cache.md", "remote-execution.md", - "support-matrix.md", - "supported-surface.md", - "quality-configs.md", "tutorial.md", "proxy-and-ca.md", "design/host-tools.md", "design/locks.md", "design/test-budget.md", - "languages/android.md", - "languages/ansible.md", - "languages/api_spec.md", - "languages/appimage.md", - "languages/apple.md", - "languages/asciidoc.md", - "languages/astro.md", - "languages/avro.md", - "languages/bicep.md", - "languages/capnproto.md", - "languages/cc.md", - "languages/cloudformation.md", - "languages/cmake.md", - "languages/csharp.md", - "languages/cuda.md", - "languages/d.md", - "languages/dart.md", - "languages/dockerfile.md", - "languages/dotnet.md", - "languages/elixir.md", - "languages/erlang.md", - "languages/flatbuffers.md", - "languages/flutter.md", - "languages/fortran.md", - "languages/fsharp.md", - "languages/go.md", - "languages/haskell.md", - "languages/helm.md", - "languages/java.md", - "languages/javascript.md", - "languages/julia.md", - "languages/kotlin.md", - "languages/kubernetes.md", - "languages/lua.md", - "languages/make.md", - "languages/mdx.md", - "languages/msix.md", - "languages/ocaml.md", - "languages/perl.md", - "languages/php.md", - "languages/powershell.md", - "languages/python.md", - "languages/qt.md", - "languages/rego.md", - "languages/rst.md", - "languages/ruby.md", - "languages/rust.md", - "languages/scala.md", - "languages/sql.md", - "languages/svelte.md", - "languages/swift.md", - "languages/terraform.md", - "languages/thrift.md", - "languages/typescript.md", - "languages/vue.md", - "languages/zig.md", ], tags = ["corpus"], ) @@ -195,16 +102,44 @@ real_source_target( tags = ["corpus"], ) -tool_config_docs( - name = "update_tool_configs", - page = "cli/commands/quality.md", -) - quality_configs_docs( - name = "update_quality_configs", + name = "quality_configs", page = "quality-configs.md", ) +genrule( + name = "support_matrix", + testonly = True, + outs = ["support-matrix.md"], + cmd = "$(execpath //tools/docs/support_matrix:update) --matrix $@", + tools = ["//tools/docs/support_matrix:update"], +) + +copy_file( + name = "supported_surface", + src = "//tools/api:surface_page.md", + out = "supported-surface.md", +) + +genrule( + name = "language_pages", + testonly = True, + srcs = [ + "@dx_consumer_fixtures//:consumer.json", + "@dx_test_tags_sources//:files.json", + "@dx_test_tags_sources//:sources.json", + ], + outs = ["languages/%s.md" % lang for lang in LANGUAGES], + cmd = " ".join([ + "DX_CONSUMER_JSON=$(rlocationpath @dx_consumer_fixtures//:consumer.json)", + "DX_FILES_JSON=$(rlocationpath @dx_test_tags_sources//:files.json)", + "DX_SOURCES_JSON=$(rlocationpath @dx_test_tags_sources//:sources.json)", + "$(execpath //tools/docs/languages:languages_bin)", + "$(RULEDIR)/languages", + ] + LANGUAGES), + tools = ["//tools/docs/languages:languages_bin"], +) + filegroup( name = "module_srcs", srcs = [ diff --git a/docs/cli/commands/quality.md b/docs/cli/commands/quality.md index 5f5aab57f3..cc34bb2185 100644 --- a/docs/cli/commands/quality.md +++ b/docs/cli/commands/quality.md @@ -510,93 +510,8 @@ trivy config and terraform typecheck read a Terraform file (`.tf` or `.tf.json`) ### Change a rule -Edit the tool's own root file. Where the Base column says `extends`, the file extends the dx base, so your edit is the only thing you keep. Where it says `override copy`, the root file is a copy of the base, and you edit the copy. +Edit the tool's own root file. Where the Base column of the [tool table](../../quality-configs.md#native-files) says `extends`, the file extends the dx base, so your edit is the only thing you keep. Where it says `override copy`, the root file is a copy of the base, and you edit the copy. rules_dx ships one strict config per tool. To change it, point the tool at your own config: edit the tool's root file, or bind `clang_tidy_config`. [Quality configs](../../quality-configs.md) lists each shipped config. - - -| Tool | Level | Native file(s) | Base | Config source | Shared with | -| --- | --- | --- | --- | --- | --- | -| `ansible_lint` | catalog | `*.ansible-lint`, `*.yml`, `*.yaml` | none | ansible-lint moderate and production profiles | | -| `bicep` | curated | `bicepconfig.json` | none | dx | | -| `biome` | curated | `biome.json` | none | dx | | -| `buf` | catalog | `buf.yaml` | override copy | dx | | -| `buildifier` | curated | `.buildifier.json` | override copy | dx | | -| `cfn_lint` | curated | `*.cfnlintrc`, `*.yaml`, `*.yml` | none | dx | | -| `checkmake` | catalog | `checkmake.ini` | override copy | dx | | -| `clang_format` | curated | `.clang-format` | none | dx | | -| `clang_tidy` | curated | `*.clang-tidy` | none | dx | | -| `clippy` | curated | | none | dx | | -| `cmakelint` | catalog | `.cmakelintrc` | override copy | dx | | -| `credo` | catalog | `*.exs` | none | dx | | -| `csharpier` | catalog | `*.yaml` | none | dx | | -| `dart` | curated | `analysis_options.yaml` | extends | dx | | -| `deadnix` | curated | `*.txt` | none | dx | | -| `detekt` | curated | `*.yml`, `*.yaml` | none | dx | | -| `djlint` | catalog | `djlint.toml`, `*.djlintrc` | none | dx | | -| `docstrfmt` | catalog | `docstrfmt.toml` | override copy | dx | | -| `elvis` | catalog | `elvis.config`, `*.config` | none | dx | | -| `errcheck` | curated | `*.txt` | none | dx | | -| `eslint` | catalog | `eslint.config.mjs`, `eslint.config.js`, `eslint.config.cjs`, `eslint.config.ts`, `.eslintrc*` | extends | dx | | -| `fortitude` | curated | `*.toml` | none | dx | | -| `fsharplint` | catalog | `*.json` | none | dx | | -| `gersemi` | catalog | `.gersemirc` | override copy | dx | | -| `govet` | curated | `*.json` | none | dx | | -| `gplint` | catalog | `*.gplintrc`, `*.json` | none | dx | | -| `graphql_eslint` | catalog | `*.json` | none | dx | | -| `hadolint` | curated | `*.yaml`, `*.yml` | none | dx | | -| `hlint` | catalog | `.hlint.yaml` | override copy | dx | | -| `julialint` | curated | `*.toml` | none | dx | | -| `kubeconform` | curated | `kubernetes.kubeconform.json` | none | dx | | -| `latexindent` | catalog | `*.yaml`, `*.yml` | none | dx | | -| `luals` | catalog | `*.json` | none | dx | | -| `lychee` | curated | `lychee.toml` | override copy | dx | | -| `markdown_check` | curated | `*.txt` | none | dx | | -| `mbake` | catalog | `.bake.toml` | override copy | dx | | -| `mix_format` | catalog | `.formatter.exs` | override copy | dx | | -| `perlcritic` | catalog | `*.perlcriticrc`, `perlcriticrc` | none | dx | | -| `perltidy` | catalog | `.perltidyrc` | override copy | dx | | -| `phpcs` | catalog | `*.xml`, `*.xml.dist` | none | dx | | -| `phpstan` | catalog | `*.neon`, `*.neon.dist` | none | phpstan level 6 and phpstan-strict-rules | | -| `pmd` | curated | `*.xml` | none | dx | | -| `prettier` | curated | `*.prettierrc`, `*.json`, `*.json5`, `*.yaml`, `*.yml`, `*.toml`, `*.mjs`, `*.cjs`, `*.js` | none | dx | | -| `psscriptanalyzer` | catalog | `PSScriptAnalyzerSettings.psd1` | override copy | dx | | -| `pydoclint` | catalog | `*.toml` | override copy | dx | | -| `qmlformat` | catalog | `*.qmlformat.ini` | none | dx | | -| `qmllint` | catalog | `*.qmllint.ini` | none | dx | | -| `redocly` | catalog | `*.yaml`, `*.yml` | none | redocly spec and all rulesets | | -| `regal` | catalog | `.regal/config.yaml` | none | dx | | -| `remark` | curated | `*.json` | none | dx | | -| `roslyn` | catalog | `*.globalconfig` | none | dx | | -| `rubocop` | catalog | `*.yml`, `*.yaml` | none | dx | | -| `ruff` | curated | `ruff.toml`, `.ruff.toml` | extends | dx | | -| `rustfmt` | curated | `rustfmt.toml`, `.rustfmt.toml` | none | dx | | -| `scalafix` | catalog | `*.conf` | none | dx | | -| `scalafmt` | curated | `.scalafmt.conf` | none | dx | | -| `selene` | catalog | `*.toml` | none | dx | | -| `shellcheck` | curated | `.shellcheckrc` | none | dx | | -| `shfmt` | curated | `.editorconfig` | override copy | dx | | -| `spotbugs` | curated | `*.xml` | none | dx | | -| `sqlfluff` | catalog | `.sqlfluff` | override copy | dx | | -| `staticcheck` | curated | `staticcheck.conf` | none | dx | | -| `stylelint` | catalog | `.stylelintrc.json`, `.stylelintrc*`, `stylelint.config.*` | extends | dx | | -| `stylua` | catalog | `*.toml` | none | dx | | -| `swift_format` | curated | `*.swift-format`, `*.json` | none | dx | | -| `swift_lint` | curated | `*.swift-format`, `*.json` | none | dx | | -| `taplo` | catalog | `.taplo.toml` | override copy | dx | | -| `tflint` | catalog | `*.hcl` | none | dx | | -| `tombi` | curated | `tombi.toml` | override copy | dx | | -| `trivy_config` | curated | `*.txt` | none | dx | | -| `tsc` | curated | `tsconfig.json` | extends | dx | | -| `ty` | curated | `*.toml` | none | dx | | -| `typos` | curated | `typos.toml` | override copy | dx | | -| `vale` | catalog | `.vale.ini`, `_vale.ini` | none | dx | | -| `yamlfmt` | curated | `.yamlfmt` | override copy | dx | | -| `yamllint` | curated | `.yamllint` | override copy | dx | | -| `zanuda` | catalog | `*.txt` | none | dx | | -| `zizmor` | curated | `*.txt` | none | dx | | - - - Formatters run on their tool defaults. dx ships no style for them, and `dx init` writes no formatter file. diff --git a/docs/languages/android.md b/docs/languages/android.md deleted file mode 100644 index 9e6d14db46..0000000000 --- a/docs/languages/android.md +++ /dev/null @@ -1,659 +0,0 @@ -# Android - - - -This page helps you build, test and check Android code with rules_dx. - -## Quick start - -`MODULE.bazel` sits at the root of your repository and lists the Bazel modules, meaning external dependencies, that your project uses. Add `rules_dx` to it: - -```python -bazel_dep(name = "rules_dx", version = "") -``` - -Then let dx set up the rest, as in the [Quickstart](../../README.md#quickstart): - -```sh -bazel run @rules_dx//dx/launch:dx -- init --apply -``` - -For a Android project, `MODULE.bazel` then looks like this: - -```python -module(name = "my_project") - -bazel_dep(name = "rules_dx", version = "") -include("//third_party/rules_dx:rules_dx.MODULE.bazel") -``` - -A `BUILD.bazel` file declares targets: the libraries, binaries and tests that Bazel builds. This one is a small Android package from [`android/tests/consumer`](https://github.com/devhusdk/rules_dx/blob/main/android/tests/consumer/BUILD.bazel): - -```python -load("@rules_dx//android:defs.bzl", "android_java_library") - -android_java_library( - name = "my_project", - srcs = ["Greeting.java"], - custom_package = "consumer", - target_compatible_with = [ - "@platforms//cpu:x86_64", - "@platforms//os:linux", - ], - visibility = ["//visibility:public"], -) -``` - -Build and test everything. `//...` means every target in the repository: - -```sh -tools/dx test //... -``` - -## Packaging - -### Application packaging - -`android_rust_apk` from `@rules_dx//android:defs.bzl` builds one installable -APK from static native deps with `rules_android`: - -```python -load("@rules_dx//android:defs.bzl", "android_rust_apk") - -android_rust_apk( - name = "app_apk", - app_id = "com.example.app", - deps = [":app_jni"], - permissions = ["android.permission.INTERNET"], - resource_files = glob(["res/**"]), - assets = glob(["assets/**"]), - assets_dir = "assets", -) -``` - -Build `:app_apk` for the installable `app_apk.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. - -- `platforms`: the ABIs to build, as platform labels. The default is - `@rules_dx//android:arm64-v8a` and `@rules_dx//android:x86_64`. Any - other label fails. rules_dx sets up the NDK and Rust toolchains for these - two 64-bit ABIs only, so it builds no `armeabi-v7a` or `x86` code. Do not - set it with `select()`. -- `deps`: the native deps. They need `alwayslink = True` so - `ANativeActivity_onCreate` stays exported, and `-landroid -llog` as - link options when they use the NDK APIs. -- `manifest`: unset gives a manifest that launches a `NativeActivity` - loading that library. A custom `NativeActivity` manifest must set - `android.app.lib_name` to `_bin`. -- Java `srcs` with a `manifest` that names your own activity package a - Java bridge. Load the library with `System.loadLibrary("_bin")`. -- `app_id`, `permissions`, `api_level`, `version_code`, and - `version_name`: you set these. - -Analysis, the step where Bazel reads BUILD files before it runs -anything, fails on unknown ABIs, an empty ABI set, a malformed app ID, a -downgraded API level, a non-positive version code, an empty launch -activity, or an adb launcher without a serial. - -Package outputs build only when you name their label. For the `.aab` -output, see [App Bundles](#app-bundles). - -`android_java_library` and `android_kotlin_library` from -`@rules_dx//android:defs.bzl` are rules_android `android_library` and -rules_kotlin `kt_android_library`. `dx generate` writes them for Java and -Kotlin sources that import the Android SDK. - -Device operations are launchers: targets that do their work only when -you `bazel run` them, never at build time: - -```python -load("@rules_dx//android:defs.bzl", "android_adb_install", "android_adb_log", "android_adb_start") - -android_adb_install(name = "install", apk = ":app_apk_file", serial = "emulator-5554") -android_adb_start(name = "start", app_id = "com.example.app", serial = "emulator-5554") -android_adb_log(name = "log", serial = "emulator-5554") -``` - -Run one with `bazel run //path:install`. `serial` names the device or -emulator. The launcher runs the pinned adb when `extra_packages` of the -`android` extension lists `platform-tools`. Set `ADB` to the path of -another adb to use that one instead. - -`android_adb_install` takes exactly one of `apk` or `apk_set`. Neither or -both fail at analysis. `apk_set` names an [`android_apk_set`](#apk-sets) -and installs its split APKs with `adb install-multiple -r`. - -### Release signing - -`:app_apk_unsigned_file` is the unsigned package. Sign it with a -launcher that runs only when you ask: - -```python -load("@rules_dx//android:defs.bzl", "android_check", "android_sign") - -android_sign(name = "sign", package = ":app_apk_unsigned_file") -android_check(name = "sign_check", package = ":app_apk_unsigned_file") -``` - -`bazel test :sign_check` checks the package without signing it. The -package must be a readable zip with an `AndroidManifest.xml` and no -signature yet. - -`android_sign` takes: - -- `schemes`: any of `v1`, `v2`, `v3` and `v4`. Default `v1`, `v2`, `v3`. -- `min_sdk`: the signing minimum SDK. Default the manifest value, at - least 31. - -Unknown or duplicate schemes, `v4` without `v2` or `v3`, and a low -`min_sdk` fail at analysis. A run with `v4` also writes the signature -next to the APK as `.idsig`. A run without `v4` deletes a -stale one. - -Pass the key through the environment of the run, never through BUILD -files: - -```sh -export DX_SIGN_KEYSTORE=release.jks DX_SIGN_STORE_PASS_FILE=store.pass -export DX_SIGN_KEY_ALIAS=release DX_SIGN_KEY_PASS_FILE=key.pass DX_SIGN_OUT=app-release.apk -bazel run //path:sign --java_runtime_version=remotejdk_25 -``` - -Passwords are read from the named files only. `DX_SIGN_KEY_ALIAS` and -`DX_SIGN_KEY_PASS_FILE` are optional. Relative paths resolve against -the directory you ran from. - -The launcher aligns the APK with the pinned build-tools `zipalign` and -signs it with `apksigner`. It verifies the result and only then writes -`DX_SIGN_OUT`. `apksigner` runs on the Java runtime that -`--java_runtime_version` picks. Set it, for example to `remotejdk_25`; -the default `local_jdk` is the host JDK. Neither `ANDROID_HOME` nor -`PATH` supplies a tool. `apksigner` turns on the schemes the minimum SDK -needs, so an API 31 package carries a v3 signature. - -Exit codes: - -- `0`: the signed APK is written. -- `1`: a wrong password, wrong alias or malformed package. No APK is - written. -- `2`: a missing input. -- `127`: missing build-tools (no `configure` tag) or no Java runtime. - -Run `bazel test //android/tests/fixtures/rust_apk:sign_test` to sign a -package with a generated test key and verify it. - -### App Bundles - -`android_rust_apk` also declares `:_aab_file`. It builds the -unsigned App Bundle `_bundle_unsigned.aab` from the same app as the -APK. The bundle keeps the APK's app ID, version, API floor, ABIs, -resources, assets and native library. For the example above, -`:app_apk_aab_file` builds `app_apk_bundle_unsigned.aab`. - -To rotate keys, set `debug_signing_lineage_file`. - -Check an App Bundle with a test: - -```python -load("@rules_dx//android:defs.bzl", "android_check") - -android_check( - name = "aab_check", - package = ":app_apk_aab_file", - platforms = ["@rules_dx//android:arm64-v8a", "@rules_dx//android:x86_64"], - resources = ["string/app_name"], -) -``` - -| Attribute | Default | Meaning | -| --- | --- | --- | -| `package` | required | The `.apk` or `.aab` to check. | -| `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. | - -For a bundle, the test runs `bundletool validate`, reads the base module -manifest, checks each ABI entry, and resolves each resource with -`bundletool dump resources`. For an APK, it checks that the package is -readable, has a manifest, and carries no signature. - -The test exits: - -- `0` for a good package; -- `1` when the package is rejected; -- `2` for a missing package, a missing bundletool, bad arguments, or an - APK given `--abi` or `--resource`. - -Unknown ABIs, resources that are not `type/name`, and `platforms` or -`resources` on an APK fail at analysis. - -The check runs the pinned bundletool 1.15.5 on the rules_java JDK. The -`android` extension downloads the jar and checks its checksum. - -Build and check the fixture bundles on a Linux x86_64 host: - -```sh -bazel build //android/tests/fixtures/rust_apk:app_apk_aab_file \ - --extra_toolchains=@android_ndk_toolchain//:all -bazel test //android/tests/fixtures/rust_apk:check_app_aab_test \ - //android/tests/fixtures/rust_apk:check_aab_missing_abi_test \ - //android/tests/fixtures/rust_apk:check_aab_missing_resource_test \ - //android/tests/fixtures/rust_apk:inspect_aab_test \ - //android/tests/fixtures/rust_apk:inspect_custom_aab_test \ - --test_env=ANDROID_HOME \ - --extra_toolchains=@android_ndk_toolchain//:all -``` - -The inspect tests read the package, version, SDK floors and library -name from the bundle manifest, and check the asset, the resource table, -the dex and the ELF machine of each `base/lib//lib.so`. - -#### APK sets - -Turn a bundle into the split APKs one device installs: - -```python -load("@rules_dx//android:defs.bzl", "android_adb_install", "android_apk_set") - -android_apk_set(name = "app_set", aab = ":app_apk_aab_file", device_spec = "device.json") -android_adb_install(name = "install_set", apk_set = ":app_set", serial = "emulator-5554") -``` - -`device_spec` is a bundletool device spec JSON. Write one by hand or -save the spec of a connected device with -`bundletool get-device-spec --output=device.json`: - -```json -{"supportedAbis": ["x86_64"], "supportedLocales": ["en"], "screenDensity": 420, "sdkVersion": 34} -``` - -The rule runs `bundletool build-apks` and `extract-apks` with the -rules_android debug key, so the APKs are for development only. Its -default output is the directory `_apks` of APKs. The `apks` output -group holds the `.apks` archive. - -- A bundle that does not match the spec fails the build with - `dx-android-apk-set: device spec ... does not match ...` and exit 1. -- A missing bundle or spec exits 2. -- An `aab` without one `.aab` or a `device_spec` without one `.json` - fails at analysis. - -`android_adb_install(name, apk_set = ":set")` installs the set with -`adb install-multiple`. Give it exactly one of `apk` or `apk_set`. An -`apk_set` that is not an `android_apk_set` fails at analysis. The set -uses the public debug keystore, so install it for development only. - -On a Linux x86_64 host with `emulator-5554` running, -`tools/dx run $pkg:install_set $pkg:start` installs the fixture set and -starts it; `device_run.sh` checks its logcat. - -#### Upload signing - -Sign a bundle with your upload key through a launcher: - -```python -load("@rules_dx//android:defs.bzl", "android_sign") - -android_sign(name = "sign_aab", package = ":app_apk_aab_file") -``` - -Pass the key through the environment of the run: - -```sh -export DX_SIGN_KEYSTORE=upload.jks DX_SIGN_STORE_PASS_FILE=store.pass -export DX_SIGN_KEY_ALIAS=upload DX_SIGN_KEY_PASS_FILE=key.pass DX_SIGN_OUT=app-release.aab -bazel run //path:sign_aab --java_runtime_version=remotejdk_25 -``` - -The variables match APK signing, except that `DX_SIGN_KEY_ALIAS` is -required. `DX_SIGN_KEY_PASS_FILE` is optional. Passwords are read from -the named files only, and relative paths resolve against the directory -you ran from. - -App Bundles carry a JAR signature, so the launcher uses `jarsigner` -and `keytool` from the selected JDK, not `apksigner`. It: - -1. rejects a bundle that is already signed; -2. runs `bundletool validate`; -3. signs with `SHA256withRSA` or `SHA256withECDSA` and a SHA-256 digest; -4. verifies the result with `jarsigner -verify -strict`; -5. only then writes `DX_SIGN_OUT`. - -The upload key must be RSA or EC. Upload keys are self-signed, so the -self-signed warning passes. An expired or not yet valid certificate -fails. - -Exit codes: - -- `0`: the signed bundle is written. -- `1`: a wrong password, wrong alias, or an already-signed or invalid - bundle. No bundle is written. -- `2`: missing inputs or variables. -- `127`: a missing bundletool or `jarsigner`. - -Run `bazel test //android/tests/fixtures/rust_apk:sign_aab_test` to -sign a generated test bundle with a disposable key and verify it. - -### SDK for packaging builds - -To start a new app, run `dx init --apply ` and add the sources and -targets above. - -Packaging builds read the `androidsdk` repository. It holds the pinned -build-tools, platform and platform-tools packages that the `android` -extension downloads, so you need no `ANDROID_HOME` on Linux x86_64, macOS -arm64, Windows x86_64 or Windows arm64. On Linux arm64 the repository is -empty. - -rules_dx pins its own `rules_android_maven` install with a lock file. In -your root `MODULE.bazel`, add your own -`maven.install(name = "rules_android_maven", lock_file = ...)` the same -way, or the first fetch resolves it through Coursier. - -Swap in the SDK from your root `MODULE.bazel`: - -```python -android = use_extension("@rules_dx//android:extensions.bzl", "android") -dx_licenses = use_extension("@rules_dx//core:extensions.bzl", "dx_licenses") -dx_licenses.accept(ids = ["android-sdk-license"]) -android.configure() -use_repo(android, "dx_androidsdk") - -android_sdk_repository = use_extension("@rules_android//rules/android_sdk_repository:rule.bzl", "android_sdk_repository_extension") -override_repo(android_sdk_repository, androidsdk = "dx_androidsdk") -``` - -`rules_android` 0.8.1 or newer is needed. It needs build-tools 35.0.0 or -newer; the pinned ones are 35.0.0. - -If `dx init --apply` did not set up your repo, add these lines to its -`.bazelrc`: - -```text -build --tool_java_runtime_version=remotejdk_25 -build --tool_java_language_version=17 -``` - -`dx build`, `dx test` and `dx check` never install or sign an APK on a -device. Build one APK for both tuples with: - -```sh -bazel build //android/tests/fixtures/rust_apk:app_apk_file -``` - -Inspect the APK with the SDK `aapt`, or run `inspect_apk_test` and -`inspect_custom_apk_test` in `//android/tests/fixtures/rust_apk` on Linux -x86_64. They check the package ID, version, SDK floors, label, activity, -library name, permissions, the requested ABI directories, the exported -`ANativeActivity_onCreate`, system-only `NEEDED` entries, the asset -bundle, and the debug signature. The custom target packages `x86_64` -only, at API 33, with its own ID and permissions. - -### Run on a device - -The fixture app logs `lifecycle=`, `input=` and `asset=` lines under the -`DxRustApk` tag. With the SDK host above and an emulator on -`emulator-5554`: - -```sh -pkg=//android/tests/fixtures/rust_apk -tools/dx run $pkg:install $pkg:start -adb -s emulator-5554 shell input tap 200 400 -adb -s emulator-5554 shell input keyevent KEYCODE_ENTER -tools/dx run $pkg:log > "$PWD/logcat.txt" -tools/dx run $pkg:device_check -- logcat "$PWD/logcat.txt" 30 -``` - -`bazel run` works the same way. Pass absolute paths to `:device_check`. `:install_custom` -and `:start_custom` install and launch the custom package. `dx build`, -`dx test` and `dx check` never install, launch or release-sign. - -To run the whole scenario, run -`tests/fixtures/rust_apk/device_run.sh ` from the -repository root. It writes logs, `logcat-default.txt`, -`dumpsys-custom.txt`, `versions.txt` and `exit-codes.txt` to ``. - -### Example - -See [`tests/fixtures/adopt_android`](../../android/tests/fixtures/adopt_android/README.md) for a -consumer that adopts these rules end to end. - -## Toolchain - -### Setup - -Turn the SDK on in your root `MODULE.bazel` and accept its license there: - -```python -android = use_extension("@rules_dx//android:extensions.bzl", "android") - -dx_licenses = use_extension("@rules_dx//core:extensions.bzl", "dx_licenses") -dx_licenses.accept(ids = ["android-sdk-license"]) -android.configure( - # api_level = 31, # 31-34, default 34 - # extra_packages = ["platform-tools"], # and/or "emulator" -) - -use_repo( - android, - "dx_android_sdk", - "dx_android_ndk_linux_x86_64", - "dx_android_build_tools_linux_x86_64", - "dx_android_platform", -) -``` - -Bazel fetches each package only when a build needs it: - -- the NDK (`dx_android_ndk_`) -- build-tools (`dx_android_build_tools_`) -- `platforms;android-` for `api_level` 31 to 34, default 34 - (`dx_android_platform`; the name does not depend on the level) -- through `extra_packages`: `platform-tools` - (`dx_android_platform_tools_`) and `emulator` - (`dx_android_emulator_`, 350 to 490 MB). The emulator ships - no system image. - -`` is `linux_x86_64`, `macos_arm64` or `windows_x86_64`. Windows -arm64 uses the `windows_x86_64` packages. `` is the machine that -runs the build: `linux_x86_64`, `macos_arm64` or `windows_x86_64`, and -for the NDK also `windows_arm64`, which runs the x64 NDK. - -Google ships no SDK packages for Linux arm64, so there the targets are -skipped. Google ships no emulator for Windows arm64, so `emulator` there -fails with an error that names the hosts it is pinned for. - -Any other `extra_packages` entry, a repeated entry, or an `api_level` -outside 31 to 34 fails with an error that names the allowed values. - -The `dx_android_sdk` repository has the targets `ndk`, `zipalign`, -`apksigner_jar`, `bundletool_jar`, `android_jar`, `adb` and `emulator`. -Targets for packages you did not ask for are empty. Without a -`configure` tag, the defaults apply. Pass `mirror` to `configure` to -download from another host. - -Only your root `MODULE.bazel` decides the setup: - -- With a `configure` tag, that tag is used as written, and `configure` - tags from dependencies are ignored. List every package you want. -- Without one, the defaults apply, plus the `extra_packages` your - dependencies ask for. -- Two `configure` tags in the root module fail with - "configure the Android SDK once". - -### Registration - -rules_dx registers the NDK clang toolchains for both tuples. You add no -`register_toolchains` line. The NDK comes from the `android` extension's -pinned download for the machine that runs the build. It is fetched only -after `dx_licenses.accept(ids = ["android-sdk-license"])` is in the root -module. `android.configure` is the one optional tag. - -### Backend - -`android_rust_apk` builds on `android_binary` from `rules_android` 0.8.1. -Manifest merge, resources, native ABI placement, DEX, and signing come -from rules_android and the pinned SDK. App Bundles come from the -rules_android `android_application` rule. - -APK assembly and device install need a Linux x86_64, macOS arm64, -Windows x86_64 or Windows arm64 host. The emulator needs a Linux x86_64, -macOS arm64 or Windows x86_64 host. On an x86_64 host it runs x86_64 code; -the `arm64-v8a` library is packaged but not run there. The other tests run -on every host: - -```sh -bazel test //android/... -``` - -On Linux arm64 this skips the APK, native-library and packaging targets. - -## Rules - -`load` brings rules into a `BUILD.bazel` file. Load the ones you use from `@rules_dx//android:defs.bzl`: - -```python -load("@rules_dx//android:defs.bzl", "android_java_library", "android_kotlin_library", "android_native_library") -``` - -### `android_java_library` - -```python -android_java_library(**kwargs) -``` - -Android Java library over rules_android android_library. - -### `android_kotlin_library` - -```python -android_kotlin_library(**kwargs) -``` - -Android Kotlin library over rules_kotlin kt_android_library. - -### `android_native_library` - -```python -android_native_library(name, rust_srcs, c_srcs, hdrs = [], crate_name = None, edition = RUST_EDITION, platforms = None, api_level = 31, crate_features = None, rustc_flags = [], copts = [], linkopts = [], visibility = None, **kwargs) -``` - -Builds one mixed Rust and C shared library per Android tuple. - -### `android_rust_apk` - -```python -android_rust_apk(name, app_id, deps, platforms = [Label("//android:arm64-v8a"), Label("//android:x86_64")], activity = "android.app.NativeActivity", api_level = 0, assets = [], assets_dir = "", custom_package = "", manifest = None, permissions = [], resource_files = [], version_code = 1, version_name = "1.0", visibility = None, tags = None, **kwargs) -``` - -Packages one APK and one unsigned App Bundle from native CcInfo deps with a Rust entry point. - -### `android_apk_set` - -Builds the debug-signed split APKs that one App Bundle installs on one device spec. - -| Attribute | Type | Required | Description | -| --- | --- | --- | --- | -| `aab` | `label` | yes | Target that builds the App Bundle. | -| `device_spec` | `label` | yes | bundletool device spec JSON. | -| `_bundletool` | `label` | no | Pinned bundletool. | -| `_java_runtime` | `label` | no | | -| `_keystore` | `label` | no | Public rules_android debug keystore; debug installs only. | -| `_dx` | `label` | no | dx, whose android_ops subcommand builds the APK set. | - -### `android_check` - -```python -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. - -### `android_sign` - -```python -android_sign(name, package, schemes = None, min_sdk = 0, visibility = None) -``` - -Declares an explicit release signing launcher for an APK or App Bundle; builds never sign or read keys. - -### `android_adb_install` - -```python -android_adb_install(name, apk = None, serial = "", apk_set = None, visibility = None) -``` - -Declares an explicit APK or APK set install launcher; nothing runs at build time. - -### `android_adb_start` - -```python -android_adb_start(name, app_id, activity = "android.app.NativeActivity", serial = "", visibility = None) -``` - -Declares an explicit application launch launcher; nothing runs at build time. - -### `android_adb_log` - -```python -android_adb_log(name, serial = "", visibility = None) -``` - -Declares an explicit logcat dump launcher; nothing runs at build time. - -## Tools and package files - -dx runs these tools and reads these package files for Android: - -| | | -| --- | --- | -| Tools | none | -| Ecosystems | none | -| Manifests | none | -| Lockfiles | none | - -## Platforms - -Android builds and tests on: - -- Linux x86_64 -- macOS arm64 -- Windows arm64 -- Windows x86_64 - -### Native platforms - -`@rules_dx//android` names the two supported tuples as platforms: -`android_device` (`aarch64-linux-android`) and `android_emulator` -(`x86_64-linux-android`), at API floor 31. Build one mixed Rust and C -library for both tuples with `android_native_library` from -`@rules_dx//android:defs.bzl`: - -```python -load("@rules_dx//android:defs.bzl", "android_native_library") - -android_native_library( - name = "native_lib", - rust_srcs = ["src/lib.rs"], - c_srcs = ["native.c"], - hdrs = ["native.h"], -) -``` - -Each Android platform label in `platforms` gets a `:name_` shared -library, and `:name` groups them. - -- `platforms`: default `@rules_dx//android:android_device` and - `@rules_dx//android:android_emulator`. -- `api_level`: the NDK level to compile and link against. Default 31, - the floor. Each level builds in its own configuration. -- `edition`: defaults to the repo Rust edition. -- `crate_features`, `rustc_flags`, `copts`, and `linkopts`: reach the - Rust and C actions. Build scripts stay on the host toolchain. -- `compatible_with`, `deprecation`, `exec_compatible_with`, `features`, - `restricted_to`, `tags`, `target_compatible_with`, and `testonly`: - reach every generated target. - -Unknown platforms, downgraded API levels, and unknown C++ runtimes fail -at analysis. diff --git a/docs/languages/ansible.md b/docs/languages/ansible.md deleted file mode 100644 index 24e63a430d..0000000000 --- a/docs/languages/ansible.md +++ /dev/null @@ -1,83 +0,0 @@ -# Ansible - - - -This page helps you build, test and check Ansible code with rules_dx. - -## Quick start - -`MODULE.bazel` sits at the root of your repository and lists the Bazel modules, meaning external dependencies, that your project uses. Add `rules_dx` to it: - -```python -bazel_dep(name = "rules_dx", version = "") -``` - -Then let dx set up the rest, as in the [Quickstart](../../README.md#quickstart): - -```sh -bazel run @rules_dx//dx/launch:dx -- init --apply -``` - -For a Ansible project, `MODULE.bazel` then looks like this: - -```python -module(name = "my_project") - -bazel_dep(name = "rules_dx", version = "") -include("//third_party/rules_dx:rules_dx.MODULE.bazel") -``` - -A `BUILD.bazel` file declares targets: the libraries, binaries and tests that Bazel builds. This one is a small Ansible package from [`ansible/tests/consumer`](https://github.com/devhusdk/rules_dx/blob/main/ansible/tests/consumer/BUILD.bazel): - -```python -load("@rules_dx//ansible:defs.bzl", "ansible_library") - -ansible_library( - name = "ansible", - srcs = ["site.yml"], - visibility = ["//visibility:public"], -) -``` - -Build and test everything. `//...` means every target in the repository: - -```sh -tools/dx test //... -``` - -## Rules - -`load` brings rules into a `BUILD.bazel` file. Load the ones you use from `@rules_dx//ansible:defs.bzl`: - -```python -load("@rules_dx//ansible:defs.bzl", "ansible_library") -``` - -### `ansible_library` - -Owns the Ansible and plain YAML files of one package for dx quality, split by Ansible layout. - -| Attribute | Type | Required | Description | -| --- | --- | --- | --- | -| `srcs` | `label_list` | no | YAML files of this package. | -| `playbooks` | `label_list` | no | Subset of srcs forced to the ansible class. | -| `deps` | `label_list` | no | Libraries this package depends on. | - -## Tools and package files - -dx runs these tools and reads these package files for Ansible: - -| | | -| --- | --- | -| Tools | `ansible_lint`, `yamlfmt` | -| Ecosystems | ansible | -| Manifests | `requirements.yml` | -| Lockfiles | `ansible.lock.json` | - -## Platforms - -Ansible builds and tests on: - -- Linux arm64 -- Linux x86_64 -- macOS arm64 diff --git a/docs/languages/api_spec.md b/docs/languages/api_spec.md deleted file mode 100644 index bb063bfcda..0000000000 --- a/docs/languages/api_spec.md +++ /dev/null @@ -1,148 +0,0 @@ -# OpenAPI and AsyncAPI - - - -This page helps you build, test and check OpenAPI and AsyncAPI code with rules_dx. - -## Quick start - -`MODULE.bazel` sits at the root of your repository and lists the Bazel modules, meaning external dependencies, that your project uses. Add `rules_dx` to it: - -```python -bazel_dep(name = "rules_dx", version = "") -``` - -Then let dx set up the rest, as in the [Quickstart](../../README.md#quickstart): - -```sh -bazel run @rules_dx//dx/launch:dx -- init --apply -``` - -For a OpenAPI and AsyncAPI project, `MODULE.bazel` then looks like this: - -```python -module(name = "my_project") - -bazel_dep(name = "rules_dx", version = "") -include("//third_party/rules_dx:rules_dx.MODULE.bazel") -``` - -A `BUILD.bazel` file declares targets: the libraries, binaries and tests that Bazel builds. This one is a small OpenAPI and AsyncAPI package from [`api_spec/tests/consumer`](https://github.com/devhusdk/rules_dx/blob/main/api_spec/tests/consumer/BUILD.bazel): - -```python -load("@rules_dx//api_spec:defs.bzl", "api_spec_library") - -api_spec_library( - name = "api_spec", - srcs = ["openapi.yaml"], - visibility = ["//visibility:public"], -) -``` - -Build and test everything. `//...` means every target in the repository: - -```sh -tools/dx test //... -``` - -## Rules - -`load` brings rules into a `BUILD.bazel` file. Load the ones you use from `@rules_dx//api_spec:defs.bzl`: - -```python -load("@rules_dx//api_spec:defs.bzl", "api_spec_go_client", "api_spec_library", "api_spec_python_client") -``` - -### `api_spec_go_client` - -Generates one Go client file (types and client) with oapi-codegen from an OpenAPI root of an api_spec_library. - -| Attribute | Type | Required | Description | -| --- | --- | --- | --- | -| `out` | `string` | no | Output file name; defaults to NAME.go. | -| `package` | `string` | yes | Go package name of the generated file. | -| `root` | `label` | no | The root document; required when the spec has more than one. | -| `spec` | `label` | yes | The api_spec_library to generate from. | -| `_driver` | `label` | no | | -| `_oapi_codegen` | `label` | no | | -| `_preflight` | `label` | no | | - -### `api_spec_library` - -Owns the OpenAPI and AsyncAPI documents of one package for dx quality. - -| Attribute | Type | Required | Description | -| --- | --- | --- | --- | -| `srcs` | `label_list` | no | Root OpenAPI or AsyncAPI documents to lint. | -| `refs` | `label_list` | no | Files the roots reach through relative $ref. | -| `deps` | `label_list` | no | Spec libraries the roots reach through relative $ref. | - -### `api_spec_python_client` - -Generates one Python client package directory with openapi-python-client from an OpenAPI root of an api_spec_library; usable as a Python dep. - -| Attribute | Type | Required | Description | -| --- | --- | --- | --- | -| `out` | `string` | no | Output directory name; defaults to NAME. | -| `root` | `label` | no | The root document; required when the spec has more than one. | -| `spec` | `label` | yes | The api_spec_library to generate from. | -| `_config` | `label` | no | | -| `_generator` | `label` | no | | -| `_preflight` | `label` | no | | - -### `api_spec_rust_client` - -Generates one Rust client file with progenitor from an OpenAPI root of an api_spec_library. The file needs progenitor-client, reqwest, serde and serde_json at compile time. - -| Attribute | Type | Required | Description | -| --- | --- | --- | --- | -| `out` | `string` | no | Output file name; defaults to NAME.rs. | -| `root` | `label` | no | The root document; required when the spec has more than one. | -| `spec` | `label` | yes | The api_spec_library to generate from. | -| `_generator` | `label` | no | | -| `_preflight` | `label` | no | | - -### `api_spec_typescript_client` - -Generates one self-contained TypeScript client from an OpenAPI root of an api_spec_library. - -| Attribute | Type | Required | Description | -| --- | --- | --- | --- | -| `out` | `string` | no | Output file name; defaults to NAME.ts. | -| `root` | `label` | no | The root document; required when the spec has more than one. | -| `spec` | `label` | yes | The api_spec_library to generate from. | -| `_config` | `label` | no | | -| `_isolate` | `label` | no | | -| `_preflight` | `label` | no | | -| `_redocly` | `label` | no | | - -### `api_spec_protobuf_doc_shard` - -Load it from `@rules_dx//api_spec:proto.bzl`. - -```python -api_spec_protobuf_doc_shard(name, proto, package = "", **kwargs) -``` - -Declares the DocIr shard of one proto_library. - -## Tools and package files - -dx runs these tools and reads these package files for OpenAPI and AsyncAPI: - -| | | -| --- | --- | -| Tools | `prettier`, `redocly` | -| Ecosystems | none | -| Manifests | none | -| Lockfiles | none | - -## Platforms - -OpenAPI and AsyncAPI builds and tests on: - -- Linux arm64 -- Linux x86_64 -- macOS arm64 -- Windows arm64 -- Windows x86_64 diff --git a/docs/languages/appimage.md b/docs/languages/appimage.md deleted file mode 100644 index 7a63d3d1f8..0000000000 --- a/docs/languages/appimage.md +++ /dev/null @@ -1,234 +0,0 @@ -# AppImage - - - -This page helps you build, test and check AppImage code with rules_dx. - -## Quick start - -`MODULE.bazel` sits at the root of your repository and lists the Bazel modules, meaning external dependencies, that your project uses. Add `rules_dx` to it: - -```python -bazel_dep(name = "rules_dx", version = "") -``` - -Then let dx set up the rest, as in the [Quickstart](../../README.md#quickstart): - -```sh -bazel run @rules_dx//dx/launch:dx -- init --apply -``` - -For a AppImage project, `MODULE.bazel` then looks like this: - -```python -module(name = "my_project") - -bazel_dep(name = "rules_dx", version = "") -include("//third_party/rules_dx:rules_dx.MODULE.bazel") -``` - -A `BUILD.bazel` file declares targets: the libraries, binaries and tests that Bazel builds. This one is a small AppImage package from [`appimage/tests/consumer`](https://github.com/devhusdk/rules_dx/blob/main/appimage/tests/consumer/BUILD.bazel): - -```python -load("@rules_dx//appimage:defs.bzl", "appimage_package") -load("@rules_dx//go:defs.bzl", "go_binary") - -go_binary( - name = "my_project", - srcs = ["main.go"], -) - -appimage_package( - name = "hello_appimage", - app_name = "hello", - binary = ":my_project", - desktop = "hello.desktop", - icon = "hello.svg", - notice = ["NOTICE.txt"], - version = "1.0", -) -``` - -Build and test everything. `//...` means every target in the repository: - -```sh -tools/dx test //... -``` - -## Packaging - -The tools are pinned and fetched by Bazel. You need no FUSE or distro -packages to build or run an AppImage. - -### Use - -Your `MODULE.bazel` needs nothing extra. The tools come from -`@dx_appimage_tools`, which rules_dx declares and Bazel fetches on first -use. Declare the package in a `BUILD.bazel` file: - -```python -load("@rules_dx//appimage:defs.bzl", "appimage_package") - -appimage_package( - name = "app", - app_name = "app", - binary = ":app_bin", - data = ["greeting.txt"], - desktop = "app.desktop", - icon = "app.png", - libs = [":native_shared"], - notice = ["NOTICE.txt"], - version = "1.2.3", -) -``` - -Attributes: - -- `binary`: the executable, packaged as built for the target platform. -- `app_name`: defaults to the target name. `desktop` must be `.desktop` - with `Exec=`. `icon` must be `.png` or `.svg`. -- `libs`: shared libraries copied to `usr/lib`. Link the binary with - `-Wl,-rpath,$ORIGIN/../lib`. -- `data`: files copied to `usr/share/`. Files keep their path relative to - their data target's package. Files a data target collects from another package - or repo keep only their file name. -- `notice`: license and NOTICE files copied to `usr/share/licenses/`. -- `version`: recorded in the identity file. - -Two different `libs`, `notice` or `data` files that map to the same path -fail analysis, the step where Bazel reads BUILD files before it runs -anything. The same file listed twice is packaged once. - -Outputs: - -- `.AppImage` -- `.AppImage.identity.json`: app name and version, tool and runtime - versions, arch (`x86_64` or `aarch64`), runtime digest, interpreter, minimum - glibc, image digest and a digest for every packaged file. - -Inside the image, `AppRun` is a link to `usr/bin/`. The -runtime sets `$APPDIR`. - -`dx init` and `tools/dx generate` write a `_appimage` target with -`version = "1.0"` for you when a directory holds: - -- `.desktop`; -- `.png` or `.svg`; -- a `NOTICE`, `LICENSE` or `COPYING` file; -- exactly one `*_binary` target. - -### Build and run - -```sh -bazel build //pkg:app -``` - -Building signs nothing, uploads nothing and needs no credentials. - -Run the image without FUSE. Either let it extract itself on each run: - -```sh -APPIMAGE_EXTRACT_AND_RUN=1 bazel-bin/pkg/app.AppImage -``` - -Or extract it once and run `AppRun`: - -```sh -bazel-bin/pkg/app.AppImage --appimage-extract -APPDIR="$PWD/squashfs-root" squashfs-root/AppRun -``` - -#### Supported tuples - -| Build host | Target cell | Run host | Run route | Install | Sign | -| --- | --- | --- | --- | --- | --- | -| Linux x86_64 or arm64 | `linux_x86_64` | Linux x86_64, glibc at least `min_glibc` | FUSE mount, `APPIMAGE_EXTRACT_AND_RUN=1` or `--appimage-extract` | none, copy the file | unsupported, images are unsigned | -| Linux x86_64 or arm64 | `linux_arm64` | Linux arm64, glibc at least `min_glibc` | FUSE mount, `APPIMAGE_EXTRACT_AND_RUN=1` or `--appimage-extract` | none, copy the file | unsupported, images are unsigned | -| macOS or Windows | any | none | none | none | unsupported, the targets are incompatible | - -`min_glibc` is in the identity file. - -Failures: - -- A missing resource or library fails in the app or the loader, not silently. -- A truncated or corrupted image exits non-zero. -- A wrong desktop or icon name fails analysis. -- Two different files that map to the same path in the image fail analysis. -- A target that is not Linux x86_64 or arm64 fails analysis. -- A desktop file without `Exec=` fails the build. - -Build for arm64 from any Linux host: - -```sh -bazel build //pkg:app --platforms=@rules_dx//appimage:linux_arm64 -``` - -Or set `platform = "@rules_dx//appimage:linux_arm64"` on the target. -Unset uses the current target platform. - -The image then holds the arm64 build of the binary. Running it needs an -arm64 Linux host. - -### Test - -Run the AppImage tests from a rules_dx checkout: - -```sh -bazel test //appimage/... //appimage/tests/fixtures/appimage_app/... -``` - -The [appimage_app fixture](../../appimage/tests/fixtures/appimage_app/README.md) is a two-package -app that is built, relocated and run without FUSE in its tests. - -## Toolchain - -### Pins - -| Tool | License | -| --- | --- | -| appimagetool | MIT | -| type 2 runtime (x86_64, aarch64) | MIT | -| mksquashfs | GPL-2.0-or-later | - -Versions are in `pins.json`. `dx update` regenerates the pin data. After editing it by hand, run `tools/dx run //core/modules:update_pins_data`. - -## Rules - -`load` brings rules into a `BUILD.bazel` file. Load the ones you use from `@rules_dx//appimage:defs.bzl`: - -```python -load("@rules_dx//appimage:defs.bzl", "AppImageInfo", "appimage_package") -``` - -### `AppImageInfo` - -No documentation. - -### `appimage_package` - -```python -appimage_package(name, target_compatible_with = None, **kwargs) -``` - -Packages one Linux target binary and its files as an AppImage. - -## Tools and package files - -dx runs these tools and reads these package files for AppImage: - -| | | -| --- | --- | -| Tools | none | -| Ecosystems | none | -| Manifests | none | -| Lockfiles | none | - -## Platforms - -AppImage builds and tests on: - -- Linux arm64 -- Linux x86_64 - -AppImages build for `linux_x86_64` and `linux_arm64`. Any other target -platform fails analysis with `target platform is unsupported`. diff --git a/docs/languages/apple.md b/docs/languages/apple.md deleted file mode 100644 index 57c03a0fb4..0000000000 --- a/docs/languages/apple.md +++ /dev/null @@ -1,805 +0,0 @@ -# Apple - - - -This page helps you build, test and check Apple code with rules_dx. - -## Quick start - -`MODULE.bazel` sits at the root of your repository and lists the Bazel modules, meaning external dependencies, that your project uses. Add `rules_dx` to it: - -```python -bazel_dep(name = "rules_dx", version = "") -``` - -Then let dx set up the rest, as in the [Quickstart](../../README.md#quickstart): - -```sh -bazel run @rules_dx//dx/launch:dx -- init --apply -``` - -For a Apple project, `MODULE.bazel` then looks like this: - -```python -module(name = "my_project") - -bazel_dep(name = "rules_dx", version = "") -include("//third_party/rules_dx:rules_dx.MODULE.bazel") -dx_licenses = use_extension("@rules_dx//core:extensions.bzl", "dx_licenses") -dx_licenses.accept(ids = ["apple-xcode-license"], terms_sha256 = {"apple-xcode-license": "5e6bd16bcba3dd591bde1c57f7c6f19f08a194c84cdc54485c4660f90e2a26ec"}) -``` - -A `BUILD.bazel` file declares targets: the libraries, binaries and tests that Bazel builds. This one is a small Apple package from [`apple/tests/consumer`](https://github.com/devhusdk/rules_dx/blob/main/apple/tests/consumer/BUILD.bazel): - -```python - -``` - -Build and test everything. `//...` means every target in the repository: - -```sh -tools/dx test //... -``` - -## Packaging - -### iOS libraries - -Build one Rust static library for one iOS cell. A cell is one target -kind and arch, such as `simulator/arm64`. - -```python -load("@rules_dx//apple:defs.bzl", "apple_ios_lib") - -apple_ios_lib( - name = "share", - srcs = ["share.rs"], - hdrs = ["share_api.h"], - platform = "@rules_dx//apple:ios_sim_arm64", - deployment = "17.0", - xcode_version = "16.4", - frameworks = ["Foundation"], - crate_features = ["share"], - rustc_flags = ["--cfg", "dx_ios"], -) -``` - -Build it on a macOS host with Xcode: - -```sh -bazel build //:share -``` - -The build writes the static archive and `_cell.txt`. The text file -records the cell, SDK, deployment target, Xcode, and the archive's -Mach-O platform and minimum OS. - -`srcs`, `deps`, `proc_macro_deps`, `crate_root`, `crate_name`, and -`edition` pass to `rust_static_library`. Targets that depend on the -library get the archive, `hdrs`, and one `-Wl,-framework,` link -flag per framework through `CcInfo`, the provider that C and C++ rules -read. - -The cells: - -| Cell | Triple | SDK | -| --- | --- | --- | -| `device/arm64` | `aarch64-apple-ios` | `iphoneos` | -| `simulator/arm64` | `aarch64-apple-ios-sim` | `iphonesimulator` | -| `simulator/x86_64` | `x86_64-apple-ios` | `iphonesimulator` | - -`bazel_dep(name = "rules_dx")` brings the Rust toolchains for these triples. - -On its own, the library builds for its own cell at `deployment` -(default 17.0, the lowest iOS the SDK supports). Inside an app or -framework, it builds in that app's cell. Linux hosts skip it. - -The build fails when: - -- a device triple, SDK, or arch is set on a simulator cell, or the reverse; -- `deployment` is below 17.0 or above the Xcode 16 ceiling (18.0), or - above the iOS version of the build; -- Xcode is outside lineage 16, or another Xcode resolved; -- the library links no static archive; -- the archive carries another arch or platform, or needs a newer iOS - than the deployment; -- the app or framework builds another cell than the library declares. - -One `apple_ios_lib` serves one cell. Use it in an app of that cell or -in an `apple_ios_xcframework` with that one slice. - -### Simulator apps - -Build one iOS app bundle over a Rust static library. The app is a -rules_apple `ios_application`. Building it never boots, installs, or -launches a simulator. - -```python -load("@rules_dx//apple:defs.bzl", "apple_ios_app", "apple_ios_app_test") -load("@rules_dx//rust:defs.bzl", "rust_static_library") - -rust_static_library( - name = "ledger_rust", - srcs = ["ledger.rs"], -) - -apple_ios_app( - name = "ledger_app", - srcs = ["main.m", "LedgerAppDelegate.m"], - hdrs = ["LedgerAppDelegate.h"], - platform = "@rules_dx//apple:ios_sim_arm64", - bundle_id = "com.example.ledger", - version = "1.0", - deployment = "17.0", - xcode_version = "16.4", - library = ":ledger_rust", - resources = ["entries.txt"], -) - -apple_ios_app_test( - name = "ledger_app_test", - size = "large", - srcs = ["LedgerAppTests.m"], - app = ":ledger_app", - deployment = "17.0", - device_type = "iPhone 16", - os_version = "18.5", -) -``` - -- `srcs`: the native entry point that calls `UIApplicationMain`. For a - Swift `@main` module, set `entry` instead. Never set both. -- `library`: any target with `CcInfo` that links one static archive, - such as `rust_static_library`. -- `frameworks`: XCFramework imports, as in - [Consume an XCFramework](#consume-an-xcframework). -- `infoplists`: unset gives the app a default `Info.plist`. - -The app needs `library`, `frameworks`, `entry`, or a mix. - -Build and test on a macOS host with Xcode: - -```sh -bazel build //:ledger_app -bazel test //:ledger_app_test -``` - -The build writes: - -- `bazel-bin//.ipa`: the app. -- `bazel-bin//_library.txt`: the cell, SDK, SDK version, - deployment target, Xcode, and each archive's arch, platform, and - minimum OS. Linking waits for this check. - -`apple_ios_app_test` creates and boots a new simulator of `device_type` -on the exact iOS `os_version` runtime. It runs the XCTest cases inside -the app, then deletes the simulator. The next test run on that host -deletes any simulator that an interrupted or timed-out run left behind. - -Install the runtime first. A missing runtime fails the test and creates -no simulator; the test never falls back to another runtime. An -`os_version` below `deployment` fails analysis, the step where Bazel -reads BUILD files before it runs anything. - -The build fails before linking when: - -- the library links no static archive or lacks `CcInfo`; -- an archive misses the cell's arch, is built for another platform - (`iphoneos`, `macosx`), or needs a newer iOS than `deployment`; -- a library builds for another cell than the app declares (the app - picks its own cell); -- no Xcode resolves, as on a Linux host, or Bazel resolved a different - Xcode than `xcode_version`; -- `srcs` and `entry` are both empty or both set, `deployment`, - `bundle_id`, or `version` is missing or malformed, or `library`, - `frameworks`, and `entry` are all empty. - -#### Swift apps - -`entry` takes any `CcInfo` or `SwiftInfo` target that holds the `@main` -module, such as a `swift_library` from `@rules_dx//swift:defs.bzl`. -`swift_library` keeps `alwayslink` on, so the `@main` module stays -linked. Name the file something other than `main.swift`. - -Use `swift_binary` and `swift_test` for a macOS-native Swift tool; they -need no simulator. - -```python -apple_ios_app( - name = "ledger_app", - entry = ":ledger_main", - library = ":ledger_rust", - platform = "@rules_dx//apple:ios_sim_arm64", - bundle_id = "com.example.ledger", - version = "1.0", - deployment = "17.0", - xcode_version = "16.4", -) - -apple_ios_app_test( - name = "ledger_app_test", - app = ":ledger_app", - deps = [":ledger_xctests"], - deployment = "17.0", - device_type = "iPhone 16", - os_version = "18.5", -) -``` - -`apple_ios_app_test` takes `srcs` for native XCTest sources, `deps` for -Swift XCTest modules, or both. It runs on the simulator only. - -Simulator builds sign ad hoc, so setting `provisioning_profile` fails -there. On non-Apple hosts the app targets are incompatible, and Bazel -skips them. - -#### Device apps - -Set `platform = "@rules_dx//apple:ios_arm64"` and -`provisioning_profile` to a `.mobileprovision` file: - -```python -apple_ios_app( - name = "ledger_device", - srcs = ["main.m"], - bundle_id = "com.example.ledger", - deployment = "17.0", - platform = "@rules_dx//apple:ios_arm64", - library = ":ledger_rust", - provisioning_profile = "ledger_dev.mobileprovision", - version = "1.0", -) -``` - -```sh -bazel build //:ledger_device -``` - -Device builds sign ad hoc and embed the profile. They never read a -keychain, even when `signing_certificate_name` is set. The build fails -when the profile has expired, does not cover `bundle_id`, or does not -allow an entitlement. - -#### Simulator operations - -Boot, install, and launch are launchers: targets that do their work -only when you `bazel run` them. - -```python -load( - "@rules_dx//apple:defs.bzl", - "apple_simulator_boot", - "apple_simulator_install", - "apple_simulator_launch", -) - -apple_simulator_boot(name = "boot", simulator = "iPhone 16") - -apple_simulator_install(name = "install", app = ":ledger_app", simulator = "iPhone 16") - -apple_simulator_launch(name = "launch", bundle_id = "com.example.ledger", simulator = "iPhone 16") -``` - -```sh -bazel run //:boot -bazel run //:install -bazel run //:launch -``` - -`simulator` is an available simulator's name or UDID. A non-empty -`DX_SIMCTL_DEVICE` in the environment replaces it. Each launcher -exits with: - -- `0` when `xcrun simctl` succeeds; -- `2` when no available simulator matches, a name matches several, or - an input is missing; -- `127` only when `xcrun` is missing; -- `simctl`'s own code when it fails. - -#### Export a signed IPA - -Export a device app with a launcher: - -```python -load("@rules_dx//apple:defs.bzl", "apple_ios_export") - -apple_ios_export(name = "export", app = ":ledger_device") -``` - -```sh -bazel run //:export -- \ - --certificate dev.p12 --password-file dev.p12.pass --out dist/Ledger.ipa -``` - -Flags: - -- `--certificate`: the signing identity `.p12` file. -- `--password-file`: the file holding the `.p12` password. -- `--out`: the `.ipa` to write, outside `bazel-out`. - -Relative paths resolve against the directory you ran `bazel` from. -`app` must be a device `apple_ios_app`. Other targets fail analysis. - -The launcher checks that: - -- the IPA embeds the declared profile; -- the profile has not expired and covers the bundle id; -- the app's entitlements are in the profile; -- the certificate is in the profile's `DeveloperCertificates`. - -It signs `Frameworks/*`, then the app. Then it checks the result: -`codesign --verify --deep --strict`, the team, `arm64` only, the -`iphoneos` platform, and an unchanged file list. Apps with extensions -fail. - -It writes `` and `.txt`, which records the bundle id, team, -profile name, UUID and expiry, certificate SHA-1, signing authority, -entitlement keys, archs, platform, and minimum OS. - -The certificate and password are never Bazel inputs. The identity goes -into a temporary keychain that is deleted on exit, and the keychain -search list is restored. Override tools with `XCRUN`, `SECURITY`, -`CODESIGN`, `OPENSSL`, `PLUTIL`, `DX_UNZIP`, `DITTO`, or `DX_ZIP`. - -The launcher exits with: - -- `0` when the IPA and report are written; -- `1` when the signed app fails verification; -- `2` when an input is missing or bad, or the profile or certificate is - rejected; -- `127` when a tool is missing; -- `codesign`'s own code when signing fails. - -### XCFrameworks - -Build one XCFramework over a Rust static library and public headers. The -bundle is a rules_apple `apple_xcframework`. Each slice builds for its -own platform. - -```python -load("@rules_dx//apple:defs.bzl", "apple_ios_xcframework") -load("@rules_dx//rust:defs.bzl", "rust_static_library") - -rust_static_library( - name = "share_rust", - srcs = ["share.rs"], -) - -apple_ios_xcframework( - name = "share", - bundle_id = "com.example.share", - bundle_name = "Share", - version = "1.4", - deployment = "17.0", - xcode_version = "16.4", - hdrs = ["share_api.h"], - library = ":share_rust", - resources = ["rates.txt"], - platforms = [ - "@rules_dx//apple:ios_arm64", - "@rules_dx//apple:ios_sim_arm64", - "@rules_dx//apple:ios_x86_64", - ], -) -``` - -Build on a macOS host with Xcode: - -```sh -bazel build //:share -``` - -The build writes: - -- `bazel-bin//.xcframework.zip`, with - `.xcframework` inside. It appears only after every check - passes. -- `bazel-bin//_xcframework.txt`: each slice's library - identifier, platform, minimum OS, and install name. - -Each platform is a `@rules_dx//apple` label: `ios_arm64`, -`ios_sim_arm64`, or `ios_x86_64`. The framework needs `ios_arm64` and at -least one simulator platform. - -The build fails when: - -- a platform is not an iOS platform label or is listed twice, or `ios_arm64` or - every simulator platform is missing; -- `hdrs`, `deployment`, `bundle_id`, `version`, or `library` is missing - or malformed, or a resource path is empty or absolute; -- a public header has the umbrella header's name in any case, such as - `share.h` next to `Share.h`; -- the library links no static archive, or an archive misses the slice's - arch, is built for another platform, or needs a newer iOS than - `deployment`; -- the XCFramework misses a declared slice, carries an undeclared one, or - lists one twice; -- a slice binary is built for another platform, needs a newer iOS than - `deployment`, or has the wrong install name; -- a slice misses its module map, a public header, a resource, or the - declared bundle identifier, version, or minimum OS; -- no Xcode resolves, or Bazel resolved a different Xcode than - `xcode_version`. - -#### Consume an XCFramework - -Import the unpacked XCFramework with `apple_dynamic_xcframework_import` -from rules_apple, and pass it in `frameworks`: - -```python -load("@rules_dx//apple:defs.bzl", "apple_dynamic_xcframework_import", "apple_ios_app") - -apple_dynamic_xcframework_import( - name = "share", - xcframework_imports = glob(["Share.xcframework/**"]), -) - -apple_ios_app( - name = "till_app", - srcs = ["main.m"], - platform = "@rules_dx//apple:ios_sim_arm64", - bundle_id = "com.example.till", - version = "2.0", - deployment = "17.0", - frameworks = [":share"], -) -``` - -Your sources import ``. The app embeds the framework -under `Frameworks/`. Load its resources with -`[NSBundle bundleWithIdentifier:]`. - -`bazel-bin//_library.txt` records each framework binary's -arch, platform, and minimum OS. The app build fails when the imported -XCFramework has no slice for the cell, or the slice binary misses the -arch, is built for another platform, or needs a newer iOS than the app -`deployment`. - -### macOS apps - -Build one macOS app bundle over a Rust static library. The bundle is a -rules_apple `macos_application`. `apple_macos_app` checks it and ships -it signed ad hoc. - -```python -load("@rules_dx//apple:defs.bzl", "apple_macos_app") -load("@rules_dx//rust:defs.bzl", "rust_static_library") - -rust_static_library( - name = "ledger_rust", - srcs = ["ledger.rs"], -) - -apple_macos_app( - name = "ledger", - srcs = ["main.m"], - platform = "@rules_dx//apple:macos_arm64", - bundle_id = "com.example.ledger", - version = "1.0", - deployment = "14.0", - xcode_version = "16.4", - library = ":ledger_rust", - resources = ["entries.txt"], -) -``` - -- `platform`: the platform the build reads the arch from. Only - `macos_arm64` is accepted. Unset uses the current target platform. The - bundle always builds for macos/arm64, and an x86_64 macOS target - platform fails with "arch 'x86_64' is outside macos". -- `deployment`: 14.0 by default for macOS apps, and 17.0 for iOS apps - and XCFrameworks. -- `xcode_version`: 16.4 by default. Both defaults are in - `apple/pins.json`. -- `srcs`: the native entry point. For a Swift `@main` module, set - `entry` instead. Never set both. -- `library`: any target with `CcInfo` that links one static archive, - such as `rust_static_library`. -- `frameworks`: `macos_dynamic_framework` targets, checked by bundle - name under `Contents/Frameworks`. -- `plugins`: `macos_bundle` targets, checked as `.bundle`, - binaries, or files placed by their package-relative path under - `Contents/PlugIns`. -- `infoplists`: unset gives the app a default `Info.plist`. - -The app needs `srcs` or `entry`, `library`, or both. - -```sh -bazel build //:ledger -bazel run //:ledger -``` - -`bazel run` unpacks the app into a temporary directory and runs its -executable with your arguments. - -The build writes: - -- `bazel-bin//.zip`: the app, copied only after every - check passes. This is the checked artifact. -- `bazel-bin//.app.identity.json`: what the checks saw. - -The identity JSON holds `identity` (`bundle_id`, `executable`, -`version`, `deployment`), `target` (`arch`, `platform`, `sdk_version`, -`xcode`, `minos`), `linkage` (`rpaths`, `loads`), `contents` -(`frameworks`, `plugins`, `resources`), and `signing` (`signature`, -`executable_sha256`). - -The app builds for macos/arm64, deployment 14.0 to 15.0, with Xcode 16. -The check fails the build when: - -- an `Info.plist` key, the architecture, or the build platform differs - from the declaration; -- a Mach-O file needs a newer macOS than `deployment`; -- a file has an rpath or a load outside `/usr/lib`, `/System/Library`, - and the bundle, or an `@rpath` load missing from the bundle; -- a declared framework, plugin, or resource is missing; -- the signature is not ad hoc. - -Building signs ad hoc only, whatever `--macos_signing_cert_name` says. -`provisioning_profile` and `entitlements` are rejected. To sign, use -[macOS signing and notarization](#macos-signing-and-notarization). -`--norun_validations` skips the check as a validation, but the check -still runs for `.zip`. Ship -`.zip`. - -Failures read: - -- `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` -- `apple_macos_app: building signs ad hoc only; signing is a separate operation` -- `apple_macos_app: srcs, entry or library is required; pass the native entry point, a Swift @main module or a Rust static library` -- `apple_macos_app: set srcs or entry for the app entry point, not both` -- `apple_macos_app: app declares macos/arm64 but this build targets macos/x86_64; build the app target, which selects its cell` -- `apple_macos_app: loads host runtime ; embed it under Frameworks` - -### macOS signing and notarization - -Sign and notarize a macOS app with two launchers. `app` must provide -rules_apple's `AppleBundleInfo`, as `macos_application` and -`apple_macos_app` do: - -```python -load("@rules_dx//apple:defs.bzl", "apple_macos_notarize", "apple_macos_sign") - -apple_macos_sign(name = "sign", app = ":ledger") - -apple_macos_notarize(name = "notarize", app = ":ledger") -``` - -```sh -bazel run //:sign -- \ - --certificate developer_id.p12 --password-file developer_id.p12.pass \ - --out dist/Ledger.app -bazel run //:notarize -- --app dist/Ledger.app \ - --key AuthKey_2X9R4HXF34.p8 --key-id 2X9R4HXF34 --issuer -``` - -`bazel build` and `dx check` only write a small metadata file for these -targets. They never sign anything or contact Apple. Both launchers need a -macOS host with Xcode. Relative paths resolve against the directory you -ran `bazel` from. An `app` that is not a macOS `.app` fails analysis. - -#### Sign - -Flags: - -- `--certificate`: the Developer ID Application identity `.p12` file. -- `--password-file`: the file holding the `.p12` password. -- `--identity`: instead of the two flags above, the SHA-1 or name of a - code signing identity that is already in a keychain. A name must match - exactly one identity. -- `--keychain`: with `--identity`, the keychain to search. It must be - unlocked. Without it, the user keychain search list is used. -- `--out`: the `.app` to write, outside `bazel-out`. - -When no credential flag is given, the launcher reads the identity from -`DX_APPLE_SIGN_IDENTITY` and the keychain from `DX_APPLE_KEYCHAIN`. - -The launcher unpacks the built app and signs it inside out. In each -bundle it signs, in order: - -1. each entry in `Contents/Frameworks`; -2. each entry in `Contents/PlugIns`, `Contents/XPCServices`, - `Contents/Helpers`, and `Contents/Library/LoginItems`, - `SystemExtensions`, `QuickLook` and `Spotlight`, signing the nested - code of each nested bundle first; -3. any other Mach-O file in `Contents/MacOS`; -4. the bundle itself. - -Nested code keeps its own entitlements through -`--preserve-metadata=entitlements`. The app itself gets the target's -entitlements. Every call uses `--force --options runtime --timestamp`. -That replaces the ad hoc build signature, turns on the hardened runtime, -and attaches Apple's secure timestamp. It never signs with `--deep`. - -Input that fails before signing: - -- entitlements on the app or on nested code that set - `com.apple.security.get-task-allow`; -- a nested bundle without `Contents/Info.plist`; -- code nested inside a framework; -- a Mach-O file anywhere else, such as `Contents/Resources`. It would - keep its ad hoc signature and fail notarization. - -After signing, the launcher checks `codesign --verify --deep --strict` -and that `codesign -dvv` shows the runtime flag, a timestamp, and a -signing authority. It then writes `` and `.txt`, which records -the bundle id, team, signing authority, certificate SHA-1, timestamp, -entitlement keys, archs, and the runtime flag. - -The certificate and password are never Bazel inputs. A `.p12` identity -goes into a temporary keychain that is deleted on exit, and the keychain -search list is restored. An `--identity` is used where it is and no -keychain is changed. - -#### Notarize - -Flags: - -- `--app`: the signed `.app` to notarize and staple. -- `--keychain-profile`: a profile stored with - `xcrun notarytool store-credentials`. -- `--key`, `--key-id`, `--issuer`: an App Store Connect API key file, - its key id, and the issuer id. Use these three or `--keychain-profile`, - not both. -- `--timeout`: how long `notarytool` waits, `2h` by default. - -The launcher checks that the app's bundle id is the target's bundle id -and that the app carries a hardened runtime signature that is not ad hoc. -It zips the app with `ditto`, submits it with `xcrun notarytool submit ---wait`, and reads the submission status from the JSON output. It always -fetches the notary log to `.notary.json`. Only an `Accepted` -submission is stapled; the launcher then runs `xcrun stapler validate` -and `spctl --assess --type execute`. - -Only file paths of secrets are passed to the tools. The launchers never -print the password or key contents. - -Override tools with `XCRUN`, `SECURITY`, `CODESIGN`, `OPENSSL`, `PLUTIL`, -`DITTO`, or `SPCTL`. - -Both launchers exit with: - -- `0` when the signed app and report are written, or the app is - notarized and stapled; -- `1` when the signed app fails verification, notarization returns - `Invalid` or `Rejected`, or stapling or assessment fails; -- `2` when an input or credential is missing or bad; -- `3` when the Apple timestamp or notary service is unreachable, or the - submission is still `In Progress` after `--timeout`; -- `127` when a tool is missing; -- `codesign`'s or `notarytool`'s own code for other failures. - -## Toolchain - -rules_dx registers the Xcode C/C++ toolchain. You add no -`register_toolchains` line and no Apple-specific tag. - -## License - -Accept the Xcode and Apple SDKs Agreement once in your root `MODULE.bazel`. -Without it every Apple rule fails analysis and names the license id. - -```python -dx_licenses = use_extension("@rules_dx//core:extensions.bzl", "dx_licenses") -dx_licenses.accept(ids = ["apple-xcode-license"]) -``` - -## Rules - -`load` brings rules into a `BUILD.bazel` file. Load the ones you use from `@rules_dx//apple:defs.bzl`: - -```python -load("@rules_dx//apple:defs.bzl", "apple_ios_app", "apple_ios_app_test", "apple_ios_xcframework") -``` - -### `apple_ios_app` - -```python -apple_ios_app(name, library = None, frameworks = [], entry = None, srcs = None, hdrs = [], deps = None, platform = None, bundle_id = "", version = "", deployment = "", xcode_version = "", resources = [], infoplists = [], families = ["iphone"], entitlements = None, provisioning_profile = None, tags = None, testonly = False, visibility = None) -``` - -Builds one upstream iOS application bundle. - -### `apple_ios_app_test` - -```python -apple_ios_app_test(name, app, srcs = None, deployment = "", device_type = "", os_version = "", deps = None, tags = None, visibility = None, **kwargs) -``` - -Runs XCTest cases inside one app on a declared simulator device and runtime. - -### `apple_ios_xcframework` - -```python -apple_ios_xcframework(name, library = None, hdrs = [], deps = None, bundle_id = "", bundle_name = "", version = "", deployment = "", xcode_version = "", platforms = [], resources = [], infoplists = [], tags = None, testonly = False, visibility = None) -``` - -Builds and checks one XCFramework over a Rust static library and public headers. - -### `apple_ios_lib` - -```python -apple_ios_lib(name, srcs = [], deps = [], proc_macro_deps = [], crate_root = None, crate_name = None, edition = None, hdrs = [], platform = None, triple = "", sdk = "", deployment = "", xcode_version = "", crate_features = [], rustc_flags = [], frameworks = [], tags = [], testonly = False, visibility = None) -``` - -Builds one Rust static library for one iOS device or simulator cell and checks its Mach-O. - -### `apple_ios_export` - -```python -apple_ios_export(name, app, visibility = None) -``` - -Declares an explicit launcher that signs one device app into a distributable IPA. - -### `apple_macos_app` - -```python -apple_macos_app(name, srcs = None, hdrs = [], deps = None, entry = None, library = None, frameworks = [], plugins = [], resources = [], infoplists = [], bundle_id = "", version = "", deployment = "", platform = None, xcode_version = "", entitlements = None, provisioning_profile = None, tags = None, testonly = None, visibility = None) -``` - -Builds one upstream macOS application over a Rust library, checked and ad hoc signed. - -### `apple_macos_sign` - -```python -apple_macos_sign(name, app, visibility = None) -``` - -Declares an explicit launcher that signs one macOS app with a Developer ID. - -### `apple_macos_notarize` - -```python -apple_macos_notarize(name, app, visibility = None) -``` - -Declares an explicit launcher that notarizes and staples one signed macOS app. - -### `apple_simulator_boot` - -```python -apple_simulator_boot(name, simulator = "", visibility = None) -``` - -Declares an explicit launcher that boots one simulator and waits for it. - -### `apple_simulator_install` - -```python -apple_simulator_install(name, app, simulator = "", visibility = None) -``` - -Declares an explicit launcher that installs one built app on one simulator. - -### `apple_simulator_launch` - -```python -apple_simulator_launch(name, bundle_id, simulator = "", visibility = None) -``` - -Declares an explicit launcher that starts one installed app on one simulator. - -### `apple_dynamic_xcframework_import` - -Re-exported from `@rules_apple//apple:apple.bzl`. - -## Tools and package files - -dx runs these tools and reads these package files for Apple: - -| | | -| --- | --- | -| Tools | none | -| Ecosystems | none | -| Manifests | none | -| Lockfiles | none | - -## Platforms - -Apple builds and tests on: - -- macOS arm64 diff --git a/docs/languages/asciidoc.md b/docs/languages/asciidoc.md deleted file mode 100644 index 66ff312ef3..0000000000 --- a/docs/languages/asciidoc.md +++ /dev/null @@ -1,79 +0,0 @@ -# AsciiDoc - - - -This page helps you build, test and check AsciiDoc code with rules_dx. - -## Quick start - -`MODULE.bazel` sits at the root of your repository and lists the Bazel modules, meaning external dependencies, that your project uses. Add `rules_dx` to it: - -```python -bazel_dep(name = "rules_dx", version = "") -``` - -Then let dx set up the rest, as in the [Quickstart](../../README.md#quickstart): - -```sh -bazel run @rules_dx//dx/launch:dx -- init --apply -``` - -For a AsciiDoc project, `MODULE.bazel` then looks like this: - -```python -module(name = "my_project") - -bazel_dep(name = "rules_dx", version = "") -include("//third_party/rules_dx:rules_dx.MODULE.bazel") -``` - -A `BUILD.bazel` file declares targets: the libraries, binaries and tests that Bazel builds. This one is a small AsciiDoc package from [`asciidoc/tests/consumer`](https://github.com/devhusdk/rules_dx/blob/main/asciidoc/tests/consumer/BUILD.bazel): - -```python -load("@rules_dx//asciidoc:defs.bzl", "asciidoc_library") - -asciidoc_library( - name = "asciidoc", - srcs = ["index.adoc"], - visibility = ["//visibility:public"], -) -``` - -Build and test everything. `//...` means every target in the repository: - -```sh -tools/dx test //... -``` - -## Rules - -`load` brings rules into a `BUILD.bazel` file. Load the ones you use from `@rules_dx//asciidoc:defs.bzl`: - -```python -load("@rules_dx//asciidoc:defs.bzl", "asciidoc_library") -``` - -### `asciidoc_library` - -No documentation. - -## Tools and package files - -dx runs these tools and reads these package files for AsciiDoc: - -| | | -| --- | --- | -| Tools | `lychee`, `vale` | -| Ecosystems | none | -| Manifests | none | -| Lockfiles | none | - -## Platforms - -AsciiDoc builds and tests on: - -- Linux arm64 -- Linux x86_64 -- macOS arm64 -- Windows arm64 -- Windows x86_64 diff --git a/docs/languages/astro.md b/docs/languages/astro.md deleted file mode 100644 index fa41d872ef..0000000000 --- a/docs/languages/astro.md +++ /dev/null @@ -1,117 +0,0 @@ -# Astro - - - -This page helps you build, test and check Astro code with rules_dx. - -## Quick start - -`MODULE.bazel` sits at the root of your repository and lists the Bazel modules, meaning external dependencies, that your project uses. Add `rules_dx` to it: - -```python -bazel_dep(name = "rules_dx", version = "") -``` - -Then let dx set up the rest, as in the [Quickstart](../../README.md#quickstart): - -```sh -bazel run @rules_dx//dx/launch:dx -- init --apply -``` - -For a Astro project, `MODULE.bazel` then looks like this: - -```python -module(name = "my_project") - -bazel_dep(name = "rules_dx", version = "") -include("//third_party/rules_dx:rules_dx.MODULE.bazel") -``` - -A `BUILD.bazel` file declares targets: the libraries, binaries and tests that Bazel builds. This one is a small Astro package from [`astro/tests/consumer`](https://github.com/devhusdk/rules_dx/blob/main/astro/tests/consumer/BUILD.bazel): - -```python -load("@rules_dx//astro:defs.bzl", "astro_library") - -astro_library( - name = "greeting", - srcs = ["greeting.astro"], - visibility = ["//visibility:public"], -) -``` - -Build and test everything. `//...` means every target in the repository: - -```sh -tools/dx test //... -``` - -## Rules - -`load` brings rules into a `BUILD.bazel` file. Load the ones you use from `@rules_dx//astro:defs.bzl`: - -```python -load("@rules_dx//astro:defs.bzl", "astro_library", "astro_build", "astro_test") -``` - -### `astro_library` - -```python -astro_library(name, srcs, visibility = None, **kwargs) -``` - -Minimal wrapper over js_library for Astro components. - -### `astro_build` - -```python -astro_build(name, srcs, config, node_modules, package_json = None, public = None, ssr_entry = None, deps = None, visibility = None, **kwargs) -``` - -Builds one Astro site into a bundled web app tree and an optional SSR tree. - -### `astro_test` - -```python -astro_test(name, *, srcs, node_modules, data = None, **kwargs) -``` - -Runs jest over Astro components, compiled by the linked @astrojs/compiler-rs. - -### `astro_doc_shard` - -```python -astro_doc_shard(name, srcs, tsconfig, entry_points, package, node_modules, package_json = None, deps = [], **kwargs) -``` - -Declares a component metadata run over one Astro project and its DocIr shard. - -## Tools and package files - -dx runs these tools and reads these package files for Astro: - -| | | -| --- | --- | -| Tools | `eslint` | -| Ecosystems | npm | -| Manifests | `package.json` | -| Lockfiles | `pnpm-lock.yaml` | - -## Platforms - -Astro builds and tests on: - -- Linux arm64 -- Linux x86_64 -- macOS arm64 -- Windows arm64 -- Windows x86_64 - -## API docs - -`tools/dx docs` builds the API docs with `astro-compiler`; see [docs](../cli/commands/docs.md). - -To declare a docs target yourself, load the rule behind it: - -```python -load("@rules_dx//astro:defs.bzl", "astro_doc_shard") -``` diff --git a/docs/languages/avro.md b/docs/languages/avro.md deleted file mode 100644 index baac22802c..0000000000 --- a/docs/languages/avro.md +++ /dev/null @@ -1,126 +0,0 @@ -# Avro - - - -This page helps you build, test and check Avro code with rules_dx. - -## Quick start - -`MODULE.bazel` sits at the root of your repository and lists the Bazel modules, meaning external dependencies, that your project uses. Add `rules_dx` to it: - -```python -bazel_dep(name = "rules_dx", version = "") -``` - -Then let dx set up the rest, as in the [Quickstart](../../README.md#quickstart): - -```sh -bazel run @rules_dx//dx/launch:dx -- init --apply -``` - -For a Avro project, `MODULE.bazel` then looks like this: - -```python -module(name = "my_project") - -bazel_dep(name = "rules_dx", version = "") -include("//third_party/rules_dx:rules_dx.MODULE.bazel") -``` - -A `BUILD.bazel` file declares targets: the libraries, binaries and tests that Bazel builds. This one is a small Avro package from [`avro/tests/consumer`](https://github.com/devhusdk/rules_dx/blob/main/avro/tests/consumer/BUILD.bazel): - -```python -load("@rules_dx//avro:defs.bzl", "avro_library") - -avro_library( - name = "my_project", - srcs = ["point.avsc"], - visibility = ["//visibility:public"], -) -``` - -Build and test everything. `//...` means every target in the repository: - -```sh -tools/dx test //... -``` - -## Rules - -`load` brings rules into a `BUILD.bazel` file. Load the ones you use from `@rules_dx//avro:defs.bzl`: - -```python -load("@rules_dx//avro:defs.bzl", "avro_library", "avro_cc_library", "avro_java_library") -``` - -### `avro_library` - -Owns Apache Avro schemas for dx lint. - -| Attribute | Type | Required | Description | -| --- | --- | --- | --- | -| `srcs` | `label_list` | no | Avro schema files of this package. | -| `deps` | `label_list` | no | avro_library targets whose schemas these import. | - -### `avro_cc_library` - -One C++ header with every type of the avro_library deps and their imports, and the runtime. - -| Attribute | Type | Required | Description | -| --- | --- | --- | --- | -| `deps` | `label_list` | no | avro_library targets to generate C++ for. | -| `namespace` | `string` | no | C++ namespace passed to avrogencpp. | -| `_avro_union` | `label` | no | | -| `_avrogencpp` | `label` | no | | -| `_runtime` | `label` | no | | - -### `avro_java_library` - -Java classes for the schemas of avro_library deps and their imports, compiled once. - -| Attribute | Type | Required | Description | -| --- | --- | --- | --- | -| `deps` | `label_list` | no | avro_library targets to generate Java for. | -| `_avro_union` | `label` | no | | -| `_avro_tools` | `label` | no | | -| `_runtime` | `label` | no | | -| `_zipper` | `label` | no | | - -### `avro_doc_shard` - -```python -avro_doc_shard(name, avro, package = "", **kwargs) -``` - -Declares the DocIr shard of one avro_library. - -## Tools and package files - -dx runs these tools and reads these package files for Avro: - -| | | -| --- | --- | -| Tools | `avro_tools`, `prettier` | -| Ecosystems | none | -| Manifests | none | -| Lockfiles | none | - -## Platforms - -Avro builds and tests on: - -- Linux arm64 -- Linux x86_64 -- macOS arm64 -- Windows arm64 -- Windows x86_64 - -## API docs - -`tools/dx docs` builds the API docs with `avro-tools`; see [docs](../cli/commands/docs.md). - -To declare a docs target yourself, load the rule behind it: - -```python -load("@rules_dx//avro:defs.bzl", "avro_doc_shard") -``` diff --git a/docs/languages/bicep.md b/docs/languages/bicep.md deleted file mode 100644 index 61be94bb26..0000000000 --- a/docs/languages/bicep.md +++ /dev/null @@ -1,96 +0,0 @@ -# Bicep - - - -This page helps you build, test and check Bicep code with rules_dx. - -## Quick start - -`MODULE.bazel` sits at the root of your repository and lists the Bazel modules, meaning external dependencies, that your project uses. Add `rules_dx` to it: - -```python -bazel_dep(name = "rules_dx", version = "") -``` - -Then let dx set up the rest, as in the [Quickstart](../../README.md#quickstart): - -```sh -bazel run @rules_dx//dx/launch:dx -- init --apply -``` - -For a Bicep project, `MODULE.bazel` then looks like this: - -```python -module(name = "my_project") - -bazel_dep(name = "rules_dx", version = "") -include("//third_party/rules_dx:rules_dx.MODULE.bazel") -``` - -A `BUILD.bazel` file declares targets: the libraries, binaries and tests that Bazel builds. This one is a small Bicep package from [`bicep/tests/consumer`](https://github.com/devhusdk/rules_dx/blob/main/bicep/tests/consumer/BUILD.bazel): - -```python -load("@rules_dx//bicep:defs.bzl", "bicep_library") - -bicep_library( - name = "bicep", - srcs = ["main.bicep"], - visibility = ["//visibility:public"], -) -``` - -Build and test everything. `//...` means every target in the repository: - -```sh -tools/dx test //... -``` - -## Rules - -`load` brings rules into a `BUILD.bazel` file. Load the ones you use from `@rules_dx//bicep:defs.bzl`: - -```python -load("@rules_dx//bicep:defs.bzl", "bicep_library", "bicep_registry_module") -``` - -### `bicep_library` - -Owns the Bicep files of one package for dx quality. - -| Attribute | Type | Required | Description | -| --- | --- | --- | --- | -| `srcs` | `label_list` | no | Bicep and Bicep parameter files of this package. | -| `data` | `label_list` | no | Files read by load functions; not checked by dx quality. | -| `deps` | `label_list` | no | Bicep modules and registry modules this package depends on. | - -### `bicep_registry_module` - -A restored Bicep registry module and its cache files. - -| Attribute | Type | Required | Description | -| --- | --- | --- | --- | -| `cache_root` | `string` | no | Repository-relative root of the module cache. | -| `digest` | `string` | no | sha256 of the module manifest. | -| `ref` | `string` | yes | Module reference, br:HOST/PATH:TAG. | -| `srcs` | `label_list` | no | Cached module files. | - -## Tools and package files - -dx runs these tools and reads these package files for Bicep: - -| | | -| --- | --- | -| Tools | `bicep`, `trivy_config` | -| Ecosystems | bicep | -| Manifests | `*.bicep` | -| Lockfiles | `bicep.lock.json` | - -## Platforms - -Bicep builds and tests on: - -- Linux arm64 -- Linux x86_64 -- macOS arm64 -- Windows arm64 -- Windows x86_64 diff --git a/docs/languages/capnproto.md b/docs/languages/capnproto.md deleted file mode 100644 index 3cdfb02ac5..0000000000 --- a/docs/languages/capnproto.md +++ /dev/null @@ -1,111 +0,0 @@ -# Cap'n Proto - - - -This page helps you build, test and check Cap'n Proto code with rules_dx. - -## Quick start - -`MODULE.bazel` sits at the root of your repository and lists the Bazel modules, meaning external dependencies, that your project uses. Add `rules_dx` to it: - -```python -bazel_dep(name = "rules_dx", version = "") -``` - -Then let dx set up the rest, as in the [Quickstart](../../README.md#quickstart): - -```sh -bazel run @rules_dx//dx/launch:dx -- init --apply -``` - -For a Cap'n Proto project, `MODULE.bazel` then looks like this: - -```python -module(name = "my_project") - -bazel_dep(name = "rules_dx", version = "") -include("//third_party/rules_dx:rules_dx.MODULE.bazel") -``` - -A `BUILD.bazel` file declares targets: the libraries, binaries and tests that Bazel builds. This one is a small Cap'n Proto package from [`capnproto/tests/consumer`](https://github.com/devhusdk/rules_dx/blob/main/capnproto/tests/consumer/BUILD.bazel): - -```python -load("@rules_dx//capnproto:defs.bzl", "capnproto_library") - -capnproto_library( - name = "my_project", - srcs = ["hello.capnp"], - visibility = ["//visibility:public"], -) -``` - -Build and test everything. `//...` means every target in the repository: - -```sh -tools/dx test //... -``` - -## Rules - -`load` brings rules into a `BUILD.bazel` file. Load the ones you use from `@rules_dx//capnproto:defs.bzl`: - -```python -load("@rules_dx//capnproto:defs.bzl", "capnproto_cc_library", "capnproto_java_library", "capnproto_library") -``` - -### `capnproto_cc_library` - -C++ code and runtime for capnproto_library schemas. Each library is generated and compiled once, by its own aspect. - -| Attribute | Type | Required | Description | -| --- | --- | --- | --- | -| `deps` | `label_list` | no | capnproto_library targets to generate C++ for. | -| `_runtime` | `label` | no | | - -### `capnproto_java_library` - -Java classes and runtime for capnproto_library schemas. Each library is generated and compiled once, by its own aspect. Every schema needs the $Java.package annotation from /capnp/java.capnp. - -| Attribute | Type | Required | Description | -| --- | --- | --- | --- | -| `deps` | `label_list` | no | capnproto_library targets to generate Java for. | -| `_runtime` | `label` | no | | - -### `capnproto_library` - -Owns Cap'n Proto schemas for dx lint. Imports resolve only from deps, relative to the importing file within its package or from the workspace root, plus the bundled /capnp/*.capnp schemas. - -| Attribute | Type | Required | Description | -| --- | --- | --- | --- | -| `srcs` | `label_list` | no | Cap'n Proto schema files of this package. | -| `deps` | `label_list` | no | capnproto_library targets whose schemas these import. | -| `_std` | `label` | no | | - -### `capnproto_rust_library` - -```python -capnproto_rust_library(name, library, crate_name = None, deps = None, codegen_path = None, **kwargs) -``` - -Rust crate for one capnproto_library. - -## Tools and package files - -dx runs these tools and reads these package files for Cap'n Proto: - -| | | -| --- | --- | -| Tools | none | -| Ecosystems | none | -| Manifests | none | -| Lockfiles | none | - -## Platforms - -Cap'n Proto builds and tests on: - -- Linux arm64 -- Linux x86_64 -- macOS arm64 -- Windows arm64 -- Windows x86_64 diff --git a/docs/languages/cc.md b/docs/languages/cc.md deleted file mode 100644 index 43f4c0a6a2..0000000000 --- a/docs/languages/cc.md +++ /dev/null @@ -1,380 +0,0 @@ -# C and C++ - - - -This page helps you build, test and check C and C++ code with rules_dx. - -## Quick start - -`MODULE.bazel` sits at the root of your repository and lists the Bazel modules, meaning external dependencies, that your project uses. Add `rules_dx` to it: - -```python -bazel_dep(name = "rules_dx", version = "") -``` - -Then let dx set up the rest, as in the [Quickstart](../../README.md#quickstart): - -```sh -bazel run @rules_dx//dx/launch:dx -- init --apply -``` - -For a C and C++ project, `MODULE.bazel` then looks like this: - -```python -module(name = "my_project") - -bazel_dep(name = "rules_dx", version = "") -include("//third_party/rules_dx:rules_dx.MODULE.bazel") -dx_licenses = use_extension("@rules_dx//core:extensions.bzl", "dx_licenses") -dx_licenses.accept(ids = ["visual-studio-build-tools"], terms_sha256 = {"visual-studio-build-tools": "9284a30da91bfdf5c56a681a6c007a0376cec75f069596dc6d28c3218c9e23d3"}) -``` - -A `BUILD.bazel` file declares targets: the libraries, binaries and tests that Bazel builds. This one is a small C and C++ package from [`cc/tests/consumer`](https://github.com/devhusdk/rules_dx/blob/main/cc/tests/consumer/BUILD.bazel): - -```python -load("@rules_dx//cc:defs.bzl", "cc_library", "cc_test") - -cc_library( - name = "my_project", - srcs = ["greet.cc"], - hdrs = ["greet.h"], - visibility = ["//visibility:public"], -) - -cc_test( - name = "greet_test", - size = "small", - srcs = ["greet_test.cc"], - deps = [":my_project"], -) -``` - -Build and test everything. `//...` means every target in the repository: - -```sh -tools/dx test //... -``` - -## Dependencies - -### CMake dependencies - -`cmake_library` from `@rules_dx//cmake:defs.bzl` only formats and lints CMake -files. It never builds them. - -To build a CMake project, use the `cmake` rule from rules_foreign_cc. Add -`rules_foreign_cc` as a `bazel_dep` and pin cmake and ninja in your -`MODULE.bazel`. `tools.explicit()` turns off the fallback to a cmake -installed on the host: - -```starlark -tools = use_extension("@rules_foreign_cc//foreign_cc:extensions.bzl", "tools") -tools.explicit() -tools.cmake(mode = "binary", version = "4.0.7") -tools.ninja(mode = "binary", version = "1.13.2") -``` - -Then build the project and link it like any other library. `lib_source` is a -filegroup with the project's sources: - -```starlark -load("@rules_dx//cc:defs.bzl", "cc_binary") -load("@rules_foreign_cc//foreign_cc:defs.bzl", "cmake") - -cmake( - name = "zlib_static", - generate_args = ["-GNinja"], - lib_source = "@zlib//:all_srcs", - out_static_libs = ["libz.a"], -) - -cc_binary( - name = "app", - srcs = ["main.c"], - deps = [":zlib_static"], -) -``` - -This works on Linux x86_64 with LLVM or GCC, from Linux x86_64 to Linux arm64 -with LLVM, and on Windows x64 with MSVC through the Ninja generator. On Linux -the host needs only `bash`. - -## Quality - -### Warnings - -Warnings fail the build by default. Each rule adds the upstream -`treat_warnings_as_errors` feature to `features`. On one target, set -`warnings_as_errors = False` to allow warnings, or `True` to always fail on -them. To allow warnings in the whole repository, add this line to `.bazelrc`, -the file of Bazel flags at the root of your repository: - -```text -common --@rules_dx//config:warnings_as_errors=false -``` - -GCC and Clang get `-Wall -Wextra -Werror`. MSVC and clang-cl get `/W4 /WX`. -With warnings allowed, the same warnings still print. C sources never get a -C++-only flag. - -These warnings come on top. GCC, MinGW GCC and Clang get -`-Wpedantic -Wshadow -Wconversion -Wsign-conversion -Wcast-align -Wcast-qual --Wdouble-promotion -Wfloat-equal -Wformat=2 -Wimplicit-fallthrough --Wmissing-declarations -Wpointer-arith -Wredundant-decls -Wundef -Wvla --Wwrite-strings`. Clang also gets `-Wcomma -Wconditional-uninitialized --Wextra-semi -Wmissing-variable-declarations -Wnewline-eof -Wnull-dereference --Wthread-safety -Wunreachable-code -Wunused-exception-parameter`. GCC and MinGW -GCC also get `-Wduplicated-branches -Wduplicated-cond -Wlogical-op --Wnull-dereference`. C++ sources get `-Wnon-virtual-dtor -Wold-style-cast --Woverloaded-virtual -Wsuggest-override -Wzero-as-null-pointer-constant`, and -GCC C++ sources also get `-Wextra-semi -Wuseless-cast`. C sources get -`-Wbad-function-cast -Wmissing-prototypes -Wnested-externs --Wold-style-definition -Wstrict-prototypes`. clang-cl gets the Clang warnings of -each language through `/clang:`. MSVC gets `/permissive-`, `/Wall` and -`/external:W0`, `/external:anglebrackets` and `/external:env:INCLUDE`, with `/wd4514`, `/wd4668`, `/wd4710`, `/wd4711`, `/wd4820` and -`/wd5045` switched off. - -## Coverage - -`bazel coverage` and `dx coverage` work for `cc_test` with LLVM and with GCC. -GCC coverage runs on Linux x86_64 with the gcov that ships with the toolchain. -It fails when gcov reports a version, stamp or profile mismatch, corrupt data -or a missing notes file. MSVC builds get no coverage. - -## Bench and fuzz - -`cc_bench` builds a Google Benchmark binary for `dx bench`: - -```starlark -load("@rules_dx//cc:defs.bzl", "cc_bench") - -cc_bench( - name = "parse_bench", - srcs = ["parse_bench.cc"], -) -``` - -It links `benchmark_main` from the `google_benchmark` module, which rules_dx -brings, so you add no `bazel_dep`. `` is the test that `dx bench` runs -and `_bin` is the binary. `size`, `timeout`, `args`, `data` and `env` -go to the test. The other attributes go to the binary. The test writes -`dx-bench.json` with one row per benchmark, in real time and in the unit the -benchmark reports. - -## Toolchain - -LLVM is the default compiler. To use your own compiler instead, see -[Use your own C/C++ toolchain](../own-cc-toolchain.md). - -### Options - -`copts`, `defines`, `features`, `includes` and `linkopts` reach the compiler -exactly as you write them, `select()` values included. The language standard -is never rewritten: `-std=c++23` compiles as C++23. - -### GCC - -To build with GCC, add this line to `.bazelrc`: - -```text -common --@rules_dx//cc:compiler=gcc -``` - -Or pass the flag to one build: - -```sh -bazel build --@rules_dx//cc:compiler=gcc //pkg/... -``` - -GCC 16.2.0 builds for Linux x86_64 and Linux arm64, with a glibc 2.26 floor. -Any other target fails at analysis, the step where Bazel reads BUILD files -before it runs anything. It never falls back to LLVM. - -libstdc++ and libgcc link statically, so each shared library carries its own -copy. Do not pass `std::` types across a `.so` boundary. To link them -dynamically instead, turn on the `dynamic_libstdcxx` feature: - -```sh -bazel test --@rules_dx//cc:compiler=gcc --features=dynamic_libstdcxx //pkg:test -``` - -The feature ships the toolchain's `libstdc++.so.6` and `libgcc_s.so.1` in -runfiles, the files Bazel places next to a binary when it runs, and sets an -`$ORIGIN` rpath, so nothing loads from the host. It covers dynamically linked -targets, such as `cc_test` or a target with `linkstatic = False`. A statically -linked `cc_binary` keeps the static runtime. - -### Sanitizers - -With GCC, turn on AddressSanitizer or UndefinedBehaviorSanitizer with the -`asan` or `ubsan` feature: - -```sh -bazel test --@rules_dx//cc:compiler=gcc --features=asan //pkg:test -bazel test --@rules_dx//cc:compiler=gcc --features=ubsan //pkg:test -``` - -GCC links the runtimes statically, so nothing loads from the host. -`cc_test` sets `ASAN_OPTIONS=verify_asan_link_order=0` unless the target's -`env` sets `ASAN_OPTIONS`. For a `cc_binary` you start with `bazel run`, set -it yourself: - -```sh -ASAN_OPTIONS=verify_asan_link_order=0 bazel run --@rules_dx//cc:compiler=gcc --features=asan //pkg:app -``` - -On a macOS host, `asan`, `ubsan` and `tsan` use the Xcode toolchain, and the -runtimes load from the installed Xcode. - -### MSVC - -To build with MSVC, add this line to `.bazelrc`: - -```text -common --@rules_dx//cc:compiler=msvc -``` - -MSVC builds on a Windows x86_64 or arm64 host for Windows x86_64 or arm64. -Accept the Visual Studio Build Tools license in your root `MODULE.bazel`: - -```starlark -dx_licenses = use_extension("@rules_dx//core:extensions.bzl", "dx_licenses") -dx_licenses.accept(ids = ["visual-studio-build-tools"]) -``` - -Any other host or target fails with a message that names the supported pair. -It never falls back to clang-cl. - -### macOS - -On a macOS host, Apple targets, `macos_*` included, build with the Xcode -toolchain. On Linux and Windows hosts, macOS targets build with `@llvm` and -the pinned `@macos_sdk`. - -The minimum macOS version is 14.0 for target and host builds. To change it, -set all four flags in `.bazelrc`: - -```text -common --macos_minimum_os=15.0 -common --host_macos_minimum_os=15.0 -common --action_env=MACOSX_DEPLOYMENT_TARGET=15.0 -common --host_action_env=MACOSX_DEPLOYMENT_TARGET=15.0 -``` - -### Objective-C - -`cc_objc_library` is the upstream `objc_library` under a rules_dx name. -rules_apple resources and frameworks, and the rules_swift `module_name`, -work exactly as upstream. dx sorts `srcs`, `non_arc_srcs` and `hdrs` into -quality checks by their file paths. - -## Rules - -`load` brings rules into a `BUILD.bazel` file. Load the ones you use from `@rules_dx//cc:defs.bzl`: - -```python -load("@rules_dx//cc:defs.bzl", "cc_library", "cc_objc_library", "cc_binary") -``` - -### `cc_library` - -```python -cc_library(name, srcs = None, hdrs = None, visibility = None, **kwargs) -``` - -Minimal wrapper over cc_library. - -### `cc_objc_library` - -```python -cc_objc_library(name, visibility = None, **kwargs) -``` - -The upstream objc_library under the caller's name, so rules_apple and rules_swift see it unchanged. - -### `cc_binary` - -```python -cc_binary(name, *, srcs = None, visibility = None, **kwargs) -``` - -Minimal wrapper over cc_binary. - -### `cc_test` - -```python -cc_test(name, *, srcs = None, visibility = None, **kwargs) -``` - -Minimal wrapper over cc_test. - -### `cc_fuzz_test` - -```python -cc_fuzz_test(name, *, srcs = None, visibility = None, tags = None, copts = None, linkopts = None, **kwargs) -``` - -A libFuzzer binary with AddressSanitizer. - -### `cc_bench` - -```python -cc_bench(name, *, srcs = None, visibility = None, tags = None, deps = None, **kwargs) -``` - -A Google Benchmark binary plus a `` runner that writes dx-bench.json for `dx bench`. - -### `cc_doc_shard` - -```python -cc_doc_shard(name, lib, package = "", **kwargs) -``` - -Declares the DocIr shard of one C or C++ library. - -## Tools and package files - -dx runs these tools and reads these package files for C and C++: - -| | | -| --- | --- | -| Tools | `clang_format`, `clang_syntax`, `clang_tidy` | -| Ecosystems | none | -| Manifests | none | -| Lockfiles | none | - -## Platforms - -C and C++ builds and tests on: - -- Linux arm64 -- Linux x86_64 -- macOS arm64 -- Windows arm64 -- Windows x86_64 - -## API docs - -`tools/dx docs` builds the API docs with `doxygen`; see [docs](../cli/commands/docs.md). - -To declare a docs target yourself, load the rule behind it: - -```python -load("@rules_dx//cc:defs.bzl", "cc_doc_shard") -``` - -`dx docs` documents the public `hdrs` of each `cc_library` with the pinned -Doxygen. You need no setup. To set the package name, declare a shard: - -```starlark -load("@rules_dx//cc:defs.bzl", "cc_doc_shard") - -cc_doc_shard( - name = "docs", - lib = ":lib", - package = "mylib", -) -``` - -Doxygen has no Linux arm64 or Windows arm64 build, so those hosts get no C or -C++ API docs. diff --git a/docs/languages/cloudformation.md b/docs/languages/cloudformation.md deleted file mode 100644 index 2bf3760857..0000000000 --- a/docs/languages/cloudformation.md +++ /dev/null @@ -1,84 +0,0 @@ -# CloudFormation - - - -This page helps you build, test and check CloudFormation code with rules_dx. - -## Quick start - -`MODULE.bazel` sits at the root of your repository and lists the Bazel modules, meaning external dependencies, that your project uses. Add `rules_dx` to it: - -```python -bazel_dep(name = "rules_dx", version = "") -``` - -Then let dx set up the rest, as in the [Quickstart](../../README.md#quickstart): - -```sh -bazel run @rules_dx//dx/launch:dx -- init --apply -``` - -For a CloudFormation project, `MODULE.bazel` then looks like this: - -```python -module(name = "my_project") - -bazel_dep(name = "rules_dx", version = "") -include("//third_party/rules_dx:rules_dx.MODULE.bazel") -``` - -A `BUILD.bazel` file declares targets: the libraries, binaries and tests that Bazel builds. This one is a small CloudFormation package from [`cloudformation/tests/consumer`](https://github.com/devhusdk/rules_dx/blob/main/cloudformation/tests/consumer/BUILD.bazel): - -```python -load("@rules_dx//cloudformation:defs.bzl", "cloudformation_library") - -cloudformation_library( - name = "cloudformation", - srcs = ["template.yaml"], - visibility = ["//visibility:public"], -) -``` - -Build and test everything. `//...` means every target in the repository: - -```sh -tools/dx test //... -``` - -## Rules - -`load` brings rules into a `BUILD.bazel` file. Load the ones you use from `@rules_dx//cloudformation:defs.bzl`: - -```python -load("@rules_dx//cloudformation:defs.bzl", "cloudformation_library") -``` - -### `cloudformation_library` - -Owns the CloudFormation templates of one package for dx lint. - -| Attribute | Type | Required | Description | -| --- | --- | --- | --- | -| `srcs` | `label_list` | no | CloudFormation template files of this package; each needs a top-level Resources section. | -| `deps` | `label_list` | no | Other template libraries this package depends on. | - -## Tools and package files - -dx runs these tools and reads these package files for CloudFormation: - -| | | -| --- | --- | -| Tools | `cfn_lint`, `prettier`, `trivy_config` | -| Ecosystems | none | -| Manifests | none | -| Lockfiles | none | - -## Platforms - -CloudFormation builds and tests on: - -- Linux arm64 -- Linux x86_64 -- macOS arm64 -- Windows arm64 -- Windows x86_64 diff --git a/docs/languages/cmake.md b/docs/languages/cmake.md deleted file mode 100644 index ba3fd9095e..0000000000 --- a/docs/languages/cmake.md +++ /dev/null @@ -1,84 +0,0 @@ -# CMake - - - -This page helps you build, test and check CMake code with rules_dx. - -## Quick start - -`MODULE.bazel` sits at the root of your repository and lists the Bazel modules, meaning external dependencies, that your project uses. Add `rules_dx` to it: - -```python -bazel_dep(name = "rules_dx", version = "") -``` - -Then let dx set up the rest, as in the [Quickstart](../../README.md#quickstart): - -```sh -bazel run @rules_dx//dx/launch:dx -- init --apply -``` - -For a CMake project, `MODULE.bazel` then looks like this: - -```python -module(name = "my_project") - -bazel_dep(name = "rules_dx", version = "") -include("//third_party/rules_dx:rules_dx.MODULE.bazel") -``` - -A `BUILD.bazel` file declares targets: the libraries, binaries and tests that Bazel builds. This one is a small CMake package from [`cmake/tests/consumer`](https://github.com/devhusdk/rules_dx/blob/main/cmake/tests/consumer/BUILD.bazel): - -```python -load("@rules_dx//cmake:defs.bzl", "cmake_library") - -cmake_library( - name = "cmake", - srcs = ["CMakeLists.txt"], - visibility = ["//visibility:public"], -) -``` - -Build and test everything. `//...` means every target in the repository: - -```sh -tools/dx test //... -``` - -## Rules - -`load` brings rules into a `BUILD.bazel` file. Load the ones you use from `@rules_dx//cmake:defs.bzl`: - -```python -load("@rules_dx//cmake:defs.bzl", "cmake_library") -``` - -### `cmake_library` - -Owns the CMake files of one package for dx format (gersemi) and dx lint (cmakelint). It does not build CMake projects. - -| Attribute | Type | Required | Description | -| --- | --- | --- | --- | -| `srcs` | `label_list` | no | CMake files of this package: CMakeLists.txt or *.cmake. | -| `deps` | `label_list` | no | Other cmake libraries this package depends on. | - -## Tools and package files - -dx runs these tools and reads these package files for CMake: - -| | | -| --- | --- | -| Tools | `cmakelint`, `gersemi` | -| Ecosystems | none | -| Manifests | `CMakeLists.txt` | -| Lockfiles | none | - -## Platforms - -CMake builds and tests on: - -- Linux arm64 -- Linux x86_64 -- macOS arm64 -- Windows arm64 -- Windows x86_64 diff --git a/docs/languages/csharp.md b/docs/languages/csharp.md deleted file mode 100644 index 87e38df560..0000000000 --- a/docs/languages/csharp.md +++ /dev/null @@ -1,218 +0,0 @@ -# C# - - - -This page helps you build, test and check C# code with rules_dx. - -## Quick start - -`MODULE.bazel` sits at the root of your repository and lists the Bazel modules, meaning external dependencies, that your project uses. Add `rules_dx` to it: - -```python -bazel_dep(name = "rules_dx", version = "") -``` - -Then let dx set up the rest, as in the [Quickstart](../../README.md#quickstart): - -```sh -bazel run @rules_dx//dx/launch:dx -- init --apply -``` - -For a C# project, `MODULE.bazel` then looks like this: - -```python -module(name = "my_project") - -bazel_dep(name = "rules_dx", version = "") -include("//third_party/rules_dx:rules_dx.MODULE.bazel") -``` - -A `BUILD.bazel` file declares targets: the libraries, binaries and tests that Bazel builds. This one is a small C# package from [`csharp/tests/consumer`](https://github.com/devhusdk/rules_dx/blob/main/csharp/tests/consumer/BUILD.bazel): - -```python -load("@rules_dx//csharp:defs.bzl", "csharp_library", "csharp_test") - -csharp_library( - name = "my_project", - srcs = ["Greet.cs"], - visibility = ["//visibility:public"], -) - -csharp_test( - name = "greet_test", - size = "small", - srcs = ["GreetTest.cs"], - deps = [":my_project"], -) -``` - -Build and test everything. `//...` means every target in the repository: - -```sh -tools/dx test //... -``` - -## Dependencies - -### NuGet packages - -List your packages in a `paket.dependencies` file. `dx update --apply` locks -them into `nuget.lock.json`. Then declare the lock in your `MODULE.bazel`: - -```python -nuget = use_extension("@rules_dx//csharp:extensions.bzl", "nuget") -nuget.lock( - name = "nuget", - lock = "//third_party/dotnet:nuget.lock.json", -) -use_repo(nuget, "nuget") -``` - -Depend on a package as `@nuget//`. `dx update nuget` -moves the pins to newer versions. - -`csharp_proto_library` needs Google.Protobuf. Add -`nuget Google.Protobuf 3.37.0-rc3` to `paket.dependencies` and put -`@nuget//google.protobuf` in `deps`. - -## Generate - -`dx generate` writes `csharp_library`, `csharp_binary` and `csharp_test` -targets from your `.cs` files and their `using` directives. A `using` of a -namespace that a local library declares resolves to that library. Any other -namespace resolves to the package in `paket.lock` named after it, so -`Newtonsoft.Json.Linq` resolves to `newtonsoft.json`. - -The `csharp/tests/fixtures/adopt_csharp` tree shows a full run. - -## Quality - -`csharpier` formats, `roslyn` lints and `csc` typechecks. dx fetches all -three, so you install nothing: - -```sh -bazel run @rules_dx//dx/launch:dx -- format //app/... -bazel run @rules_dx//dx/launch:dx -- lint //app/... -bazel run @rules_dx//dx/launch:dx -- typecheck //app/... -``` - -`roslyn` analyzes every framework in a `target_frameworks` list, for the host -runtime only. A finding that only some frameworks report ends with those -frameworks, such as `[net8.0]`. When `target_frameworks` is a `select()`, -only the framework it resolves to is analyzed. - -`roslyn` reads a `.globalconfig` bound with `roslyn_config`. Name it -`.globalconfig` and put it at the root: the C# Dev Kit picks it up by that -name, so your editor and `dx` report the same findings. Start from -`core/quality/configs/roslyn/config.globalconfig`. - -`csc` reports only compiler diagnostics (`CS*`), from the same per-framework -compile that `roslyn` uses, so no extra compile runs. Analyzer findings come -from `roslyn`. See the -[quality config table](https://github.com/devhusdk/rules_dx/blob/main/docs/cli/commands/quality.md). - -## Coverage - -`bazel coverage` and `dx coverage` run C# tests under coverlet and write LCOV. -They cover the first-party assemblies that match `--instrumentation_filter`. -The test assembly counts only with `--instrument_test_targets`. Tag a test -`no-coverage` to skip it under coverage. - -## Rules - -`load` brings rules into a `BUILD.bazel` file. Load the ones you use from `@rules_dx//csharp:defs.bzl`: - -```python -load("@rules_dx//csharp:defs.bzl", "csharp_library", "csharp_binary", "csharp_test") -``` - -### `csharp_proto_library` - -Load it from `@rules_dx//csharp:proto.bzl`. - -```python -csharp_proto_library(name, proto, deps = None, visibility = None, **kwargs) -``` - -Compiles a proto_library to C# with protoc; deps should hold Google.Protobuf. - -### `csharp_library` - -```python -csharp_library(name, srcs = None, visibility = None, **kwargs) -``` - -Minimal wrapper over csharp_library; target_frameworks defaults to net10.0, out defaults to name and warnings are errors. - -### `csharp_binary` - -```python -csharp_binary(name, *, srcs = None, visibility = None, upstream_visibility = None, **kwargs) -``` - -Binary with target_frameworks net10.0; warnings as errors follow the repo config. - -### `csharp_test` - -```python -csharp_test(name, *, srcs = None, visibility = None, **kwargs) -``` - -Test with target_frameworks net10.0, warnings as errors following the repo config, size small; srcs required. - -### `csharp_bench` - -```python -csharp_bench(name, *, srcs, deps = None, tags = None, **kwargs) -``` - -A csharp_test that runs the [Benchmark] classes in srcs with BenchmarkDotNet and writes dx-bench.json. - -### `csharp_fuzz_test` - -```python -csharp_fuzz_test(name, *, srcs, deps = None, visibility = None, tags = None, **kwargs) -``` - -A SharpFuzz harness plus a `_run` runner for `dx fuzz`. - -### `csharp_doc_shard` - -```python -csharp_doc_shard(name, library, package = "", **kwargs) -``` - -Declares the DocIr shard of one C# library. - -## Tools and package files - -dx runs these tools and reads these package files for C#: - -| | | -| --- | --- | -| Tools | `csc`, `csharpier`, `roslyn` | -| Ecosystems | nuget | -| Manifests | `paket.dependencies` | -| Lockfiles | `nuget.lock.json`, `paket.lock` | - -## Platforms - -C# builds and tests on: - -- Linux arm64 -- Linux x86_64 -- macOS arm64 -- Windows arm64 -- Windows x86_64 - -See the [support matrix](https://github.com/devhusdk/rules_dx/blob/main/docs/support-matrix.md). - -## API docs - -`tools/dx docs` builds the API docs with `csharp doc driver`; see [docs](../cli/commands/docs.md). - -To declare a docs target yourself, load the rule behind it: - -```python -load("@rules_dx//csharp:defs.bzl", "csharp_doc_shard") -``` diff --git a/docs/languages/cuda.md b/docs/languages/cuda.md deleted file mode 100644 index 6060830935..0000000000 --- a/docs/languages/cuda.md +++ /dev/null @@ -1,318 +0,0 @@ -# CUDA - - - -This page helps you build, test and check CUDA code with rules_dx. - -## Quick start - -`MODULE.bazel` sits at the root of your repository and lists the Bazel modules, meaning external dependencies, that your project uses. Add `rules_dx` to it: - -```python -bazel_dep(name = "rules_dx", version = "") -``` - -Then let dx set up the rest, as in the [Quickstart](../../README.md#quickstart): - -```sh -bazel run @rules_dx//dx/launch:dx -- init --apply -``` - -For a CUDA project, `MODULE.bazel` then looks like this: - -```python -module(name = "my_project") - -bazel_dep(name = "rules_dx", version = "") -include("//third_party/rules_dx:rules_dx.MODULE.bazel") -dx_licenses = use_extension("@rules_dx//core:extensions.bzl", "dx_licenses") -dx_licenses.accept(ids = ["cuda-eula", "visual-studio-build-tools"], terms_sha256 = {"cuda-eula": "d6de69eacd5644f0f84d2289a54d07d29017377d37ab28d0227b3df3509b1a60", "visual-studio-build-tools": "9284a30da91bfdf5c56a681a6c007a0376cec75f069596dc6d28c3218c9e23d3"}) -``` - -A `BUILD.bazel` file declares targets: the libraries, binaries and tests that Bazel builds. This one is a small CUDA package from [`cuda/tests/consumer`](https://github.com/devhusdk/rules_dx/blob/main/cuda/tests/consumer/BUILD.bazel): - -```python -load("@rules_dx//cuda:defs.bzl", "cuda_library") - -cuda_library( - name = "my_project_cuda", - srcs = ["kernel.cu"], - gpu_archs = ["sm_89"], - visibility = ["//visibility:public"], -) -``` - -Build and test everything. `//...` means every target in the repository: - -```sh -tools/dx test //... -``` - -## Dependencies - -### Library components - -The pinned stanza declares cuBLAS 13.8.0.4, cuFFT 12.4.0.43 and cuRAND -10.4.4.72 next to the compiler components, from the CUDA 13.4.3 -redistributable manifest. Bazel fetches an archive only when a target uses it -(cuBLAS 877 MB, cuFFT 249 MB, cuRAND 87 MB). - -Depend on the pinned labels: - -```python -cuda_library( - name = "gemm", - srcs = ["gemm.cu"], - gpu_archs = ["sm_89"], - deps = ["@rules_dx//cuda:cublas"], # or :cufft, :curand -) -``` - -These targets fail unless the files come from the pinned redistributable. Never depend on `@cuda//:cublas`, which skips the -check, or on `@cuda//:cuda_headers` or `@cuda//:cuda_all_files`, which fetch -every component. The `cufft` and `curand` targets are tagged `manual`. - -See `cuda/tests/fixtures/cublas`. - -## Quality - -### Warnings - -nvcc warnings fail the build by default. `cuda_library`, `cuda_objects`, -`cuda_binary` and `cuda_test` pass nvcc these flags: - -```text --Werror=all-warnings,cross-execution-space-call --Wreorder -Wdefault-stream-launch -Wmissing-launch-bounds --Wext-lambda-captures-this --display-error-number -``` - -So give every kernel `__launch_bounds__` and every launch an explicit stream: - -```cuda -__global__ void __launch_bounds__(256) saxpy(int n, float a, const float* x, float* y); - -saxpy<<<(n + 255) / 256, 256, 0, stream>>>(n, a, x, y); -``` - -On one target, set `warnings_as_errors = False` to keep the warnings but not -fail on them. To allow warnings in the whole repository, add this line to -`.bazelrc`: - -```text -common --@rules_dx//config:warnings_as_errors=false -``` - -`copts` and `host_copts` may not hide warnings or relax device code. Analysis -fails on `-w`, `--disable-warnings`, `-Wno-*`, `--diag-suppress`, -`--expt-relaxed-constexpr` and `--use_fast_math`, also when passed to the host -compiler through `-Xcompiler`. Fix the code instead. - -### GPU tests - -```python -load("@rules_dx//cuda:defs.bzl", "cuda_test") - -cuda_test( - name = "saxpy_gpu_test", - srcs = ["saxpy_gpu_test.cu"], - gpu_archs = ["compute_89:compute_89,sm_89", "sm_120"], - min_compute_capability = "8.9", - min_driver = "13.0", - deps = [":saxpy"], -) -``` - -A machine with a GPU declares it with three flags, for example in its `user.bazelrc`: - -```text -common --@rules_dx//cuda:gpu_compute_capability=12.0 -common --@rules_dx//cuda:gpu_driver=13.4 -common --local_resources=gpu=1 -``` - -- `gpu_compute_capability`: compute capability of the device, `X.Y`. -- `gpu_driver`: CUDA driver version of the machine, `X.Y`. -- `--local_resources=gpu=`: number of GPU tests that run at once. - -Set both `gpu_` flags or neither. Without them every GPU `cuda_test` is incompatible, so `bazel test //...` skips it. - -```sh -bazel test //:saxpy_gpu_test --test_output=streamed -``` - -The test source implements `int dx_gpu_test_main(void)` from -`dx/gpu_check.h`. Run the kernels there, compute a CPU -reference, and record each comparison with -`dx_gpu_check(name, want, got, n, abs_tol, rel_tol)`. Pass `got = NULL` -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. - -- `gpu_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 `gpu_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. - -Every GPU `cuda_test` gets the tags `requires-gpu` and `resources:gpu:1`. -It runs sandboxed and its result is cached. The declared device, the -minimums and the runtime version are inputs of the test. - -Each run prints one `dx-gpu-facts: {...}` line and writes -`gpu_facts.json` to `bazel-testlogs///test.outputs/` -(as `outputs.zip` when Bazel zips undeclared outputs; pass -`--nozip_undeclared_test_outputs` for the plain file). -The file has the schema `dx.cuda.gpu_facts.v1` and records the status, -the reason, the declared versions and device, the driver, the runtime, the device -name, compute capability and memory, and every check. - -| Status | Meaning | Exit code | -| --- | --- | --- | -| `pass` | Every recorded check is within tolerance. | 0 | -| `fail` | A check failed, no check ran, a declared value is missing, or the device or driver is not the declared one. | 1 | -| `unavailable` | A device is declared, but there is no GPU, no driver, or a CUDA call failed. | 1 | -| `unsupported` | The device or driver is below the minimum, or the runtime differs. | 1 | - -When the status is not `pass`, the first stderr line is -`: `. - -## Toolchain - -nvcc uses the hermetic clang as its host compiler. The build needs no CUDA -install and no GPU. - -### Setup - -The CUDA rules load from `@rules_dx//cuda:defs.bzl`. rules_dx declares the -pinned toolkit and the nvcc toolchain. Add this to the root `MODULE.bazel`: - -```python -dx_licenses = use_extension("@rules_dx//core:extensions.bzl", "dx_licenses") -dx_licenses.accept(ids = ["cuda-eula"]) -``` - -### Toolchain - -rules_dx declares the pinned nvcc toolchain; a consumer adds no -`register_toolchains` line. The one tag a consumer adds is -`dx_licenses.accept(ids = ["cuda-eula"])`. - -### Errors - -| Message | Fix | -| --- | --- | -| `dx_cuda: the CUDA Toolkit EULA (https://docs.nvidia.com/cuda/eula/index.html) is not accepted; add dx_licenses.accept(ids = ["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: gpu_archs is empty; set gpu_archs, for example gpu_archs = ["sm_89"]` | Set `gpu_archs`. | -| `dx_cuda: arch '' is not supported by nvcc 13.4; supported: ...` | Use an arch from the list. | -| `dx_cuda: copt '' silences warnings or relaxes device code; fix the code instead` | Remove the flag from `copts`, `host_copts` or `cuda_copts` and fix the warning. | -| `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 ''); remove your own rules_cuda cuda.redist_json and cuda.toolkit tags` | Remove your own rules_cuda `cuda.redist_json` and `cuda.toolkit` tags. | -| `dx_cuda: the CUDA toolkit is ; dx CUDA targets need 13.4` | Use the versions from Setup. | -| `dx_cuda: no nvcc toolchain for this target; dx CUDA targets build for linux_x86_64, linux_arm64, windows_x86_64, windows_arm64` | Build for one of the listed platforms. | -| nvcc fails with `unsupported clang version!` | Move the stanza before `register_toolchains("@llvm//toolchain:all")`. | - -## License - -The CUDA Toolkit is licensed under the -[NVIDIA CUDA EULA](https://docs.nvidia.com/cuda/eula/index.html). -`dx_licenses.accept(ids = ["cuda-eula"])` accepts it for this build. -Only the root module's tag counts. Without it, fetching the CUDA redistributables fails. `cuda-eula` is the only license name. - -Accepting the license here does not grant you one. You still need your own from NVIDIA. - -## Rules - -`load` brings rules into a `BUILD.bazel` file. Load the ones you use from `@rules_dx//cuda:defs.bzl`: - -```python -load("@rules_dx//cuda:defs.bzl", "cuda_library", "cuda_binary", "cuda_test") -``` - -### `cuda_library` - -```python -cuda_library(name, srcs, gpu_archs, hdrs = None, visibility = None, tags = None, target_compatible_with = None, rdc = False, **kwargs) -``` - -Minimal wrapper over rules_cuda cuda_library; gpu_archs is required and rdc enables relocatable device code. - -### `cuda_binary` - -```python -cuda_binary(name, *, srcs, gpu_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_test` - -```python -cuda_test(name, *, srcs, gpu_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. - -### `cuda_objects` - -```python -cuda_objects(name, srcs, gpu_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_component_library` - -Forwards one pinned CUDA library component after the pin check. - -| Attribute | Type | Required | Description | -| --- | --- | --- | --- | -| `component` | `label` | yes | The rules_cuda component target, for example @cuda//:cublas. | -| `component_name` | `string` | yes | rules_cuda short name of the component. | - -### `cuda_doc_shard` - -```python -cuda_doc_shard(name, lib, package = "", **kwargs) -``` - -Declares the DocIr shard of one CUDA library. - -## Tools and package files - -dx runs these tools and reads these package files for CUDA: - -| | | -| --- | --- | -| Tools | `clang_format`, `clang_tidy`, `nvcc_syntax` | -| Ecosystems | none | -| Manifests | none | -| Lockfiles | none | - -## Platforms - -CUDA builds and tests on: - -- Linux arm64 -- Linux x86_64 -- Windows arm64 -- Windows x86_64 - -See the [support matrix](https://github.com/devhusdk/rules_dx/blob/main/docs/support-matrix.md). - -On Windows, nvcc compiles with `cl.exe` from the hermetic Visual Studio Build Tools, so you don't set `--//cc:compiler`. `cuda_binary` and `cuda_test` build and link everything in them with `cl.exe`. Link a `cuda_library` into a `cuda_binary` or `cuda_test`: on Windows a `cc_binary` or `cc_test` only takes one under `--//cc:compiler=msvc`. Accept both licenses in the root `MODULE.bazel`: `dx_licenses.accept(ids = ["cuda-eula", "visual-studio-build-tools"])`. - -`bazel coverage` reports CUDA on Linux only. The host side of a `.cu` file is -reported against that `.cu` file. - -## API docs - -`tools/dx docs` builds the API docs with `doxygen`; see [docs](../cli/commands/docs.md). - -To declare a docs target yourself, load the rule behind it: - -```python -load("@rules_dx//cuda:defs.bzl", "cuda_doc_shard") -``` diff --git a/docs/languages/d.md b/docs/languages/d.md deleted file mode 100644 index ff001aa41e..0000000000 --- a/docs/languages/d.md +++ /dev/null @@ -1,243 +0,0 @@ -# D - - - -This page helps you build, test and check D code with rules_dx. - -## Quick start - -`MODULE.bazel` sits at the root of your repository and lists the Bazel modules, meaning external dependencies, that your project uses. Add `rules_dx` to it: - -```python -bazel_dep(name = "rules_dx", version = "") -``` - -Then let dx set up the rest, as in the [Quickstart](../../README.md#quickstart): - -```sh -bazel run @rules_dx//dx/launch:dx -- init --apply -``` - -For a D project, `MODULE.bazel` then looks like this: - -```python -module(name = "my_project") - -bazel_dep(name = "rules_dx", version = "") -include("//third_party/rules_dx:rules_dx.MODULE.bazel") -``` - -A `BUILD.bazel` file declares targets: the libraries, binaries and tests that Bazel builds. This one is a small D package from [`d/tests/consumer`](https://github.com/devhusdk/rules_dx/blob/main/d/tests/consumer/BUILD.bazel): - -```python -load("@rules_dx//d:defs.bzl", "d_library", "d_test") - -d_library( - name = "my_project", - srcs = [ - "greet.d", - "greet_test.d", - ], - visibility = ["//visibility:public"], -) - -d_test( - name = "my_project_test", - size = "small", - srcs = [ - "greet.d", - "greet_test.d", - ], -) -``` - -Build and test everything. `//...` means every target in the repository: - -```sh -tools/dx test //... -``` - -## Dependencies - -### DUB packages - -List your dependencies in `dub.json`. Then: - -1. Run `dx update --apply`. It resolves exact versions from the - `code.dlang.org` API, downloads each archive and writes `dub.lock.json` - and the state file `dub.selections.json`. Packages that did not change - are kept without a download. -2. Run `dx generate --apply`. With `dub.lock.json` beside the root - `dub.json`, it adds the `dub.lock` stanza for the `@dub` hub to - `MODULE.bazel`. A hub is one Bazel repository that holds a target for - every locked package. -3. Put the package in the `deps` of a `d_library`, `d_binary` or `d_test`, - as `@dub//`, for example `@dub//silly`. - -How each package builds: - -- Its own `dependencies` become its deps. -- `sourcePaths`, `sourceFiles`, `importPaths` and `stringImportPaths` in its - `dub.json` set the sources and imports. -- Without `sourcePaths`, the `source` or `src` directory is used. -- Without `stringImportPaths`, the `views` directory is used if it exists. - -Only registry versions work. A `path` or `repository` dependency fails, and -so does a package that has a `dub.sdl` instead of a `dub.json`. - -## Generate - -`dx generate` writes one `d_library` per directory of D modules. -`gazelle/d/testdata/modules/README.md` shows how modules map to targets. - -Next to a `dub.json`: - -- Generation reads the import roots: `importPaths`, else `sourcePaths`, - else `source` or `src`. It fails when a package's modules need a - different root. -- With `"targetType": "executable"`, the package of the root that defines - `main` becomes a `d_binary`. -- An import resolves to `@dub//` when its first segment names a - dependency in `dub.json` (with `-` read as `_`) and `dub.selections.json` - pins it. - -Two directives change resolution. Put them in a BUILD file: - -- `# gazelle:dx_external dub dub.json ` names the hub something other - than `dub`, for example `dub_packages`. -- `# gazelle:resolve d