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

NameDescriptionTypeMandatoryDefault
nameA unique name for this target.Namerequired
manifest_bazel_jsonThe 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.LabeloptionalNone
manifest_tomlThe location of the Manifest.toml lockfile to generate/update.Labelrequired
project_tomlThe Project.toml file describing dependencies.Labelrequired

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

NameDescriptionTypeMandatoryDefault
nameA unique name for this target.Namerequired
compilerThe julia_pkg_compiler targetLabelrequired

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

NameDescriptionTypeMandatoryDefault
nameThe name of the module to createNamerequired
lockfileThe Manifest.bazel.json lockfile with SHA256 hashes for all packages.Labelrequired
manifestThe Manifest.toml lockfile associated with Project.toml (deprecated, use lockfile instead).LabeloptionalNone

pkg_annotation

Attributes

NameDescriptionTypeMandatoryDefault
depThe name of the package to annotateStringrequired
patch_argsArguments to pass to the patch tool. See http_archive.patch_argsList of stringsoptional[]
patch_toolThe patch tool to use. See http_archive.patch_toolStringoptional""
patchesList of patch files to apply to the package. See http_archive.patchesList of labelsoptional[]