mojox-build
PEP 517 + PEP 660 build backend that compiles Mojo libraries into platform-tagged wheels.
Declare it in [build-system] and let uv build or pip wheel handle the rest.
Quickstart
# pyproject.toml
[project]
name = "boucle"
version = "0.2.0"
description = "Async event loop primitives for Mojo"
readme = "README.md"
license = "Apache-2.0"
requires-python = ">=3.10"
dependencies = ["mojox", "mojo-compiler>=1.0,<2"]
[build-system]
requires = ["mojox-build>=0.4", "mojo-compiler>=1.0,<2"]
build-backend = "mojox_build"
[tool.mojox]
packages = ["boucle"]
uv build # -> dist/boucle-0.2.0-py3-none-manylinux_2_43_x86_64.whl
uv publish # uploads to PyPI
The wheel places compiled .mojoc packages under mojo_packages/, which mojox discovers at runtime.
[tool.mojox] reference
The full [tool.mojox] table is owned by mojox-core and shared with the CLI. Keys relevant to the build backend:
| Key | Type | Default | Purpose |
|---|---|---|---|
package-root |
str | "src" |
Directory containing top-level package dirs to compile |
packages |
list[str] | (auto-scan package-root) |
Explicit list of source directories. Each becomes one .mojoc |
build-profile |
str | "release" |
Which profile to use for wheel builds |
native-libs |
list[str] | [] |
Pre-built .so/.dylib files to copy into mojo_packages/lib/ |
defines |
table | {} |
-D KEY=VALUE flags passed to mojo precompile |
flags |
list[str] | [] |
Extra flags appended to every compile invocation |
source-include |
list[str] | (sensible default) | Glob patterns of files to include in the sdist |
source-exclude |
list[str] | [] |
Glob patterns to exclude from the sdist |
wheel-exclude |
list[str] | [] |
Glob patterns to exclude from the wheel |
How it works
- A PEP 517 frontend (
uv build,pip wheel) callsbuild_wheel(),build_sdist(), orbuild_editable(). - The hook reads
pyproject.tomlviamojox-core's manifest parser. - Policy is resolved from the active build profile (defaults to
release). mojo precompileruns for each package directory, producing.mojocfiles.- The compiled packages, native libs, and metadata are assembled into a wheel tagged with the host platform.
Architecture
Five modules, roughly 1100 lines total:
__init__.pyre-exports the PEP 517 hook surface._hooks.pyimplements PEP 517 + PEP 660 hooks (thin glue that wires config, preflight, and build together)._build.pyhandles compilation, wheel assembly, sdist assembly, and editable installs._metadata.pyrenders PEP 621 / PEP 643 METADATA and PEP 427 WHEEL files._preflight.pyvalidates the build environment before compilation starts.
Config parsing, policy resolution, and toolchain detection live in mojox-core. The only runtime dependency beyond the stdlib is packaging (for platform tags).
Features
- Platform-tagged wheels. Compiled packages are native code. Wheels are tagged with the host platform (
manylinux_2_34_x86_64,macosx_13_0_arm64, etc.), so cross-platform installs are correctly rejected by the resolver. - Native lib bundling. List
.so/.dylibpaths innative-libs. They ship inmojo_packages/lib/, wheremojoxadds them toLD_LIBRARY_PATHat runtime. - PEP 660 editable installs.
uv pip install -e .works. For rebuild-on-change semantics, addcache-keys = [{ file = "pyproject.toml" }, { file = "**/*.mojo" }]to[tool.uv]. - Per-distribution editable files. Two mojox projects installed editable into the same venv do not clobber each other.
- Reproducible builds. ZIP and tar timestamps respect
SOURCE_DATE_EPOCH. - Parallel compilation. Multi-package repos compile concurrently, capped at 8 workers.
- Preflight checks. Missing
mojo, missing dirs, missing native libs, bad config -- one clean error message, not a compiler stderr dump. - Full PEP 621 / PEP 639 metadata. Authors, maintainers, urls, keywords, classifiers, optional-dependencies, license-files all flow into wheel METADATA.
- Compiler pin. When packages are compiled,
Requires-Dist: mojo-compiler==<version>is emitted in the wheel METADATA so the resolver enforces compiler compatibility. - Content-based platform tags. Wheels with native libs or binaries get a platform tag; pure-metadata wheels stay
any. --config-setting verbose=true. Streams compiler output during builds for debugging.
Limitations
- Dynamic
project.versionis not supported. Declare it statically. - Editable installs rebuild the full wheel on every invocation. There is no source-import fast path because the package is compiled bytecode.
- Cross-compilation is not exposed. Wheels are host-platform only.
See also
- mojox-core -- manifest parsing, policy resolution, toolchain detection
- mojox -- CLI for running, testing, and managing Mojo projects
License
MIT
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 mojox_build-0.5.0.tar.gz.
File metadata
- Download URL: mojox_build-0.5.0.tar.gz
- Upload date:
- Size: 15.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
uv/0.12.5 {"installer":{"name":"uv","version":"0.12.5","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
46592f42acc84b9c1d923069eade3738e6db92b8c96d7289c88a4638d1e2cc49
|
|
| MD5 |
9c4e490a5dde826f888180ee16e0db76
|
|
| BLAKE2b-256 |
b49f895d2db3226473d27b8458928cdf6bf6c53000d5f1f708040a010b9e40b1
|
File details
Details for the file mojox_build-0.5.0-py3-none-any.whl.
File metadata
- Download URL: mojox_build-0.5.0-py3-none-any.whl
- Upload date:
- Size: 14.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
uv/0.12.5 {"installer":{"name":"uv","version":"0.12.5","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
96b28036b3e194442694442aa2e29f6dab84f12b1e5015d0d8d37b0604b13fb5
|
|
| MD5 |
f10912d1d519107e446fe163d9e5bd9f
|
|
| BLAKE2b-256 |
4b48f60c3cb984c27086a3a94f04b2d47c9ad79e938a506879c4c8d719daf5f1
|