Julia Pkg rules
Rules
Module Extensions
julia_pkg_compiler
load("@rules_julia//julia/pkg:defs.bzl", "julia_pkg_compiler")
julia_pkg_compiler(name, manifest_bazel_json, manifest_toml, project_toml)
A rule for generating Manifest.toml and Manifest.bazel.json from Project.toml using Julia's Pkg manager.
This rule uses Julia's native package manager to resolve dependencies and generate
a Manifest.toml lockfile and a Manifest.bazel.json file with SHA256 hashes. The
Manifest.bazel.json can then be used with the pkg module extension to fetch and
build Julia packages hermetically with cryptographic verification.
The manifest_bazel_json attribute is optional. If not specified, the Manifest.bazel.json
file will be written next to the Manifest.toml file.
Note that when setting this target up for the first time, an empty Manifest.toml file
will need to be created. If you specify manifest_bazel_json, that file should also be
created as an empty JSON object {}.
Example:
julia_pkg_compiler(
name = "pkg_update",
project_toml = "Project.toml",
manifest_toml = "Manifest.toml",
# manifest_bazel_json is optional - defaults to Manifest.bazel.json next to Manifest.toml
)
Then run:
bazel run //:pkg_update
This will update Manifest.toml with resolved package versions and Manifest.bazel.json with SHA256 hashes for all packages and their dependency graph.
ATTRIBUTES
| Name | Description | Type | Mandatory | Default |
|---|---|---|---|---|
| name | A unique name for this target. | Name | required | |
| manifest_bazel_json | The location of the Manifest.bazel.json lockfile to generate/update with SHA256 hashes. If not specified, defaults to Manifest.bazel.json next to the manifest_toml file. | Label | optional | None |
| manifest_toml | The location of the Manifest.toml lockfile to generate/update. | Label | required | |
| project_toml | The Project.toml file describing dependencies. | Label | required |
julia_pkg_test
load("@rules_julia//julia/pkg:defs.bzl", "julia_pkg_test")
julia_pkg_test(name, compiler)
A test rule that verifies Manifest.bazel.json is in sync with Manifest.toml.
This test ensures that the lockfile generated by pkg_compiler contains the correct package versions, UUIDs, and dependencies that match the Manifest.toml file.
The test will fail if:
- A package is missing from the lockfile
- Versions don't match between the two files
- UUIDs don't match
- The git-tree-sha1 is not in the package URL
- SHA256 hashes are missing
Example:
julia_pkg_compiler(
name = "pkg_update",
project_toml = "Project.toml",
manifest_toml = "Manifest.toml",
# Normally optional but required for the `julia_pkg_test` target.
manifest_bazel_json = "Manifest.bazel.json",
)
julia_pkg_test(
name = "pkg_sync_test",
compiler = ":pkg_update",
)
Then run:
bazel test //:pkg_sync_test
This will verify that both manifest files are synchronized. If they're out of sync, the test will fail with detailed error messages indicating what needs to be fixed.
ATTRIBUTES
| Name | Description | Type | Mandatory | Default |
|---|---|---|---|---|
| name | A unique name for this target. | Name | required | |
| compiler | The julia_pkg_compiler target | Label | required |
pkg
pkg = use_extension("@rules_julia//julia/pkg:defs.bzl", "pkg")
pkg.install(name, lockfile, manifest)
pkg.pkg_annotation(dep, patch_args, patch_tool, patches)
A module for defining Julia package dependencies.
TAG CLASSES
install
Attributes
| Name | Description | Type | Mandatory | Default |
|---|---|---|---|---|
| name | The name of the module to create | Name | required | |
| lockfile | The Manifest.bazel.json lockfile with SHA256 hashes for all packages. | Label | required | |
| manifest | The Manifest.toml lockfile associated with Project.toml (deprecated, use lockfile instead). | Label | optional | None |
pkg_annotation
Attributes
| Name | Description | Type | Mandatory | Default |
|---|---|---|---|---|
| dep | The name of the package to annotate | String | required | |
| patch_args | Arguments to pass to the patch tool. See http_archive.patch_args | List of strings | optional | [] |
| patch_tool | The patch tool to use. See http_archive.patch_tool | String | optional | "" |
| patches | List of patch files to apply to the package. See http_archive.patches | List of labels | optional | [] |