Julia Pkg rules

Rules

Functions

Module Extensions

julia_pkg_resolve

load("@rules_julia//julia/pkg:defs.bzl", "julia_pkg_resolve")

julia_pkg_resolve(name, manifest_bazel_json, manifests, project_toml)

A rule for resolving Julia manifests from Project.toml using Julia's Pkg manager.

Running the target resolves the project once per manifest listed in manifests, each time with a Julia toolchain of the version the manifest is declared for, and writes the results in place. Pkg resolves against one Julia version (its standard libraries, compat bounds and manifest format), so a project supporting several Julia minor versions carries one manifest per version, following Pkg's own Manifest-v<major>.<minor>.toml convention. Pass the manifests to the pkg module extension via pkg.from_manifest(manifests = ...); no additional lockfile is required.

Optionally, manifest_bazel_json may be set (with a single manifest) to also write a Manifest.bazel.json containing package URLs, integrity values and artifacts. Pass that file to pkg.from_manifest(lockfile = ...) for modules consumed by other Bazel modules, since module extension facts are only persisted in the root module's MODULE.bazel.lock.

Note that when setting this target up for the first time, empty manifest files need to be created. If you specify manifest_bazel_json, that file should also be created as an empty JSON object {}.

Example:

julia_pkg_resolve(
    name = "pkg_update",
    project_toml = "Project.toml",
    manifests = {
        "Manifest-v1.10.toml": "1.10",
        "Manifest-v1.12.toml": "1.12",
    },
)

Then run:

bazel run //:pkg_update

Packages can be added to Project.toml at the same time:

bazel run //:pkg_update -- --add JSON

ATTRIBUTES

NameDescriptionTypeMandatoryDefault
nameA unique name for this target.Namerequired
manifest_bazel_jsonAn optional Manifest.bazel.json lockfile to generate/update with package URLs, integrity values and artifacts. Only supported with a single manifest.LabeloptionalNone
manifestsJulia manifests keyed by the Julia version each is resolved with, e.g. {"Manifest-v1.10.toml": "1.10", "Manifest-v1.12.toml": "1.12"}. A project supporting a single Julia version lists one Manifest.toml. Each manifest is resolved and verified under a registered toolchain of that version (the newest known patch release when only a minor version is given), regardless of --@rules_julia//julia/settings:version.Dictionary: Label -> Stringrequired
project_tomlThe Project.toml file describing dependencies.Labelrequired

julia_pkg_resolve_test

load("@rules_julia//julia/pkg:defs.bzl", "julia_pkg_resolve_test")

julia_pkg_resolve_test(name, resolver)

A test rule that verifies the manifests managed by julia_pkg_resolve are up to date.

Every manifest is checked under a Julia toolchain of the version it is declared for, by comparing the manifest's recorded project_hash with the hash of the current Project.toml. Pkg's hash algorithm differs between Julia minor versions, which is why the resolver's declaration drives which Julia runs each check. When the resolver also tracks a Manifest.bazel.json, that file is checked against the manifest as well.

The test will fail if:

  • A manifest is out of date with respect to Project.toml
  • A manifest was resolved with a different Julia minor version than declared
  • A package is missing from Manifest.bazel.json
  • Versions or UUIDs don't match between the manifest and Manifest.bazel.json
  • The git-tree-sha1 is not in the package URL
  • Integrity values are missing

Example:

julia_pkg_resolve(
    name = "pkg_update",
    project_toml = "Project.toml",
    manifests = {"Manifest.toml": "1.12"},
)

julia_pkg_resolve_test(
    name = "pkg_sync_test",
    resolver = ":pkg_update",
)

Then run:

bazel test //:pkg_sync_test

If the files are out of sync the test fails with details on what needs to be regenerated.

ATTRIBUTES

NameDescriptionTypeMandatoryDefault
nameA unique name for this target.Namerequired
resolverThe julia_pkg_resolve target whose manifests are checked.Labelrequired

julia_pkg_compiler

load("@rules_julia//julia/pkg:defs.bzl", "julia_pkg_compiler")

julia_pkg_compiler(name, **kwargs)

Resolve Julia manifests from Project.toml; the former name of julia_pkg_resolve.

PARAMETERS

NameDescriptionDefault Value
nameThe name of the target.none
kwargsForwarded to julia_pkg_resolve.none

DEPRECATED

Use julia_pkg_resolve. The rule was renamed because "package compiler" means PackageCompiler.jl to Julia users, and this rule runs Pkg's resolver. This alias will be removed in a future release.

julia_pkg_test

load("@rules_julia//julia/pkg:defs.bzl", "julia_pkg_test")

julia_pkg_test(name, compiler, **kwargs)

Check that manifests are up to date; the former name of julia_pkg_resolve_test.

PARAMETERS

NameDescriptionDefault Value
nameThe name of the target.none
compilerThe julia_pkg_resolve (formerly julia_pkg_compiler) target to check; passed on as resolver.none
kwargsForwarded to julia_pkg_resolve_test.none

DEPRECATED

Use julia_pkg_resolve_test with resolver in place of compiler. This alias will be removed in a future release.

pkg

pkg = use_extension("@rules_julia//julia/pkg:defs.bzl", "pkg")
pkg.from_manifest(name, lockfile, manifest, manifests, pkg_server)
pkg.install(name, lockfile, manifest, manifests, pkg_server)
pkg.pkg_annotation(dep, patch_args, patch_tool, patches)

A module extension for defining Julia package dependencies.

pkg = use_extension("@rules_julia//julia/pkg:extensions.bzl", "pkg")
pkg.from_manifest(
    name = "my_deps",
    manifests = ["//:Manifest.toml"],
)
use_repo(pkg, "my_deps")

Each package in the manifests becomes a julia_library target available as @my_deps//:<PackageName>. See the from_manifest tag for how integrity values and multiple Julia versions are handled.

TAG CLASSES

from_manifest

Fetch the Julia packages recorded in one or more Manifest.toml files, or in a Manifest.bazel.json.

Exactly one of manifests (or the single-file alias manifest) or lockfile must be set.

With manifests, the stock Manifest.toml files written by Pkg are the only lockfiles. Each manifest records the Julia version that resolved it; its packages are built for that Julia minor version and marked incompatible with others, and the hub selects among manifests with @rules_julia//julia/settings:version. A project supporting several Julia versions lists one manifest per minor version (Pkg's Manifest-v<major>.<minor>.toml convention); julia_pkg_resolve resolves them all. Package tarballs are fetched from pkg_server using the UUID and git tree hash recorded for each package. On Bazel 9 and newer the integrity value of every tarball and the artifacts each package declares are persisted in the facts section of MODULE.bazel.lock, so after the first evaluation no network access is needed to evaluate the extension. On older Bazel versions the generated repositories are recorded in MODULE.bazel.lock instead.

With lockfile, a Manifest.bazel.json produced by julia_pkg_resolve provides URLs, integrity values and artifacts up front and the extension never touches the network. The lockfile carries no Julia version, so its packages are available under every version. Prefer this for modules consumed by others, since facts are only persisted in the root module's lockfile.

Pkg itself never runs: the manifest is parsed in Starlark and every package is fetched by its recorded hash.

Attributes

NameDescriptionTypeMandatoryDefault
nameThe name of the hub repository to create.Namerequired
lockfileA Manifest.bazel.json lockfile produced by julia_pkg_resolve. Mutually exclusive with manifests.LabeloptionalNone
manifestA single Manifest.toml; shorthand for manifests = [...].LabeloptionalNone
manifestsManifest.toml files, one per supported Julia minor version. Mutually exclusive with lockfile.List of labelsoptional[]
pkg_serverThe Julia package server to fetch tarballs from when manifests is set.Stringoptional"https://pkg.julialang.org"

install

Deprecated alias of from_manifest, kept for one release.

Attributes

NameDescriptionTypeMandatoryDefault
nameThe name of the hub repository to create.Namerequired
lockfileA Manifest.bazel.json lockfile produced by julia_pkg_resolve. Mutually exclusive with manifests.LabeloptionalNone
manifestA single Manifest.toml; shorthand for manifests = [...].LabeloptionalNone
manifestsManifest.toml files, one per supported Julia minor version. Mutually exclusive with lockfile.List of labelsoptional[]
pkg_serverThe Julia package server to fetch tarballs from when manifests is set.Stringoptional"https://pkg.julialang.org"

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[]