Hatch build hook for compiling Mojo sources into Python and native artifacts
Project description
hatch-mojo
A Hatch build hook plugin that compiles Mojo sources during package builds.
Supports Python extension modules and standalone artifacts (shared libraries, executables, etc.).
Installation
uv add hatch-mojo
Quickstart
Add the hook to your pyproject.toml:
[build-system]
build-backend = "hatchling.build"
requires = ["hatchling", "hatch-mojo"]
[tool.hatch.build.targets.wheel.hooks.mojo]
targets = ["wheel"]
[[tool.hatch.build.targets.wheel.hooks.mojo.jobs]]
name = "core"
input = "src/mo/my_pkg/core.mojo"
emit = "python-extension"
module = "my_pkg._core"
include-dirs = ["src/mo"]
Then build:
hatch build -t wheel
Configuration
All configuration lives under [tool.hatch.build.targets.wheel.hooks.mojo] in pyproject.toml.
Global options
[tool.hatch.build.targets.wheel.hooks.mojo]
mojo-bin = "/opt/mojo/bin/mojo" # path to mojo binary (default: $HATCH_MOJO_BIN or "mojo")
parallel = true # compile jobs in parallel
fail-fast = true # stop on first failure (only with parallel)
clean-before-build = false # remove build-dir before compiling
clean-after-build = false # remove build-dir after compiling
skip-editable = true # skip Mojo compilation for editable installs
build-dir = "build/mojo" # working directory for compiled artifacts
targets = ["wheel"] # hatch build targets that trigger this hook
include = ["src/mo/**/*.mojo"] # git-style globs to include
exclude = ["**/experimental*.mojo"] # git-style globs to exclude
Profiles
Profiles define reusable sets of job options. Jobs reference them by name, and profile values are merged into the job config.
[tool.hatch.build.targets.wheel.hooks.mojo.profiles.default]
include-dirs = ["src/mo"]
flags = ["-I", "vendor/include"]
[[tool.hatch.build.targets.wheel.hooks.mojo.jobs]]
name = "core"
profiles = ["default"]
input = "src/mo/my_pkg/core.mojo"
emit = "python-extension"
module = "my_pkg._core"
Jobs
Each job compiles a single Mojo source into an output artifact.
Python extension:
[[tool.hatch.build.targets.wheel.hooks.mojo.jobs]]
name = "core"
input = "src/mo/my_pkg/core.mojo"
emit = "python-extension"
module = "my_pkg._core"
include-dirs = ["src/mo"]
Non-Python artifact (requires an install mapping):
[[tool.hatch.build.targets.wheel.hooks.mojo.jobs]]
name = "cli"
input = "src/mo/my_pkg/cli.mojo"
emit = "executable"
install = { kind = "scripts", path = "my-cli" }
Job options reference
| Option | Type | Description |
|---|---|---|
name |
string | Unique identifier for the job |
input |
string | Path to the Mojo source file (supports globs) |
emit |
string | python-extension, shared-lib, static-lib, object, executable |
output |
string | Explicit output path (overrides default) |
module |
string | Dotted import path (required for python-extension) |
install |
object | Install mapping for non-Python artifacts: { kind, path } |
profiles |
list | Profile names to inherit settings from |
include-dirs |
list | Additional include directories passed as -I |
defines |
list | Values passed as -D flags to the compiler |
flags |
list | Extra flags passed to mojo build |
env |
object | Environment variables set during compilation |
platforms |
list | Restrict job to specific sys.platform values |
arch |
list | Restrict job to specific platform.machine() values |
marker |
string | PEP 508 marker expression for conditional inclusion |
depends-on |
list | Job names that must complete before this one |
Supported install kinds: package, data, scripts, root, force-include
Troubleshooting
| Error | Fix |
|---|---|
mojo executable not found |
Set mojo-bin, HATCH_MOJO_BIN, or add mojo to PATH |
No build jobs resolved |
Check input paths, include/exclude globs, and targets |
unknown dependencies |
Ensure depends-on references valid job names |
| Wheel missing binaries | Set module for extension jobs or install for non-Python jobs |
License
MIT
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file hatch_mojo-0.1.2.tar.gz.
File metadata
- Download URL: hatch_mojo-0.1.2.tar.gz
- Upload date:
- Size: 114.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d94128a3550c07dda82c1a3933568eed12a8c4f8b4cf707fc9820269db148e64
|
|
| MD5 |
e7ef913538608b48c2a27d2ef7b48a81
|
|
| BLAKE2b-256 |
b562a210c7ef9da3864828888dbb6aff190c95fdc20bd2f667541bc896512dd7
|
Provenance
The following attestation bundles were made for hatch_mojo-0.1.2.tar.gz:
Publisher:
publish.yml on cofin/hatch-mojo
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
hatch_mojo-0.1.2.tar.gz -
Subject digest:
d94128a3550c07dda82c1a3933568eed12a8c4f8b4cf707fc9820269db148e64 - Sigstore transparency entry: 992697323
- Sigstore integration time:
-
Permalink:
cofin/hatch-mojo@ac7b238e6521e8af0d8a4aa7de2815d35d4dddd5 -
Branch / Tag:
refs/tags/v0.1.2 - Owner: https://github.com/cofin
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@ac7b238e6521e8af0d8a4aa7de2815d35d4dddd5 -
Trigger Event:
release
-
Statement type:
File details
Details for the file hatch_mojo-0.1.2-py3-none-any.whl.
File metadata
- Download URL: hatch_mojo-0.1.2-py3-none-any.whl
- Upload date:
- Size: 12.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
387bef6928a6119b5f3e07785b11d088c8bc0c8ef625f85e7139cd76d8c42b6e
|
|
| MD5 |
b6abd7a2f0904a41f70a11388e4ea231
|
|
| BLAKE2b-256 |
378e67a79e0dbf2f01775291652c60d72686c0fc28ca66e2c4c4143ab8cbe27d
|
Provenance
The following attestation bundles were made for hatch_mojo-0.1.2-py3-none-any.whl:
Publisher:
publish.yml on cofin/hatch-mojo
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
hatch_mojo-0.1.2-py3-none-any.whl -
Subject digest:
387bef6928a6119b5f3e07785b11d088c8bc0c8ef625f85e7139cd76d8c42b6e - Sigstore transparency entry: 992697327
- Sigstore integration time:
-
Permalink:
cofin/hatch-mojo@ac7b238e6521e8af0d8a4aa7de2815d35d4dddd5 -
Branch / Tag:
refs/tags/v0.1.2 - Owner: https://github.com/cofin
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@ac7b238e6521e8af0d8a4aa7de2815d35d4dddd5 -
Trigger Event:
release
-
Statement type: