Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions .github/actions/setup-decimo/action.yml
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
name: Setup Decimo with Pixi
description: Install pixi (cached), activate the Mojo environment, and download the prebuilt decimo.mojopkg artifact into tests/.
description: Install pixi (cached), activate the Mojo environment, and download the prebuilt decimo.mojoc artifact into tests/.

runs:
using: composite
steps:
- uses: prefix-dev/setup-pixi@v0.9.5
with:
activate-environment: true
- name: Download decimo.mojopkg artifact
- name: Download decimo.mojoc artifact
uses: actions/download-artifact@v4
with:
name: decimo-mojopkg
name: decimo-mojoc
path: .
- name: Stage package next to tests
shell: bash
run: cp decimo.mojopkg tests/
run: cp decimo.mojoc tests/
34 changes: 17 additions & 17 deletions .github/workflows/run_tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ defaults:
shell: bash

# The `build` job is the gate: format check, doc generation, and the
# `decimo.mojopkg` build all run once. The package is uploaded as an
# `decimo.mojoc` build all run once. The package is uploaded as an
# artifact so downstream test jobs can download it instead of rebuilding
# (saves ~30s of `mojo package` per job × 10 jobs). The pixi environment
# (saves ~30s of `mojo precompile` per job × 10 jobs). The pixi environment
# is cached by `prefix-dev/setup-pixi@v0.9.5`, so test jobs no longer
# `curl | sh` and `pixi install` from scratch.

Expand All @@ -41,7 +41,7 @@ jobs:
run: |
for attempt in 1 2 3; do
echo "=== build attempt $attempt ==="
if pixi run mojo package src/decimo; then
if pixi run mojo precompile src/decimo -o decimo.mojoc; then
echo "=== build succeeded on attempt $attempt ==="
break
fi
Expand All @@ -52,13 +52,13 @@ jobs:
echo "=== build crashed, retrying in 5s... ==="
sleep 5
done
- name: Stage decimo.mojopkg next to tests
- name: Stage decimo.mojoc next to tests
# `pixi run doc` documents `src/cli/calculator`, which imports
# `decimo.*`. Mojo 1.0.0b1 cannot resolve those qualified
# `decimo.*`. Mojo cannot resolve those qualified
# references when re-traversing the source tree via `-I src`,
# so the doc task uses `-I tests` against the prebuilt
# `decimo.mojopkg`. Stage it here before invoking doc.
run: cp decimo.mojopkg tests/
# `decimo.mojoc`. Stage it here before invoking doc.
run: cp decimo.mojoc tests/
- name: Generate docs (with retry for Mojo compiler intermittent crashes)
run: |
for attempt in 1 2 3; do
Expand All @@ -74,13 +74,13 @@ jobs:
echo "=== doc crashed, retrying in 5s... ==="
sleep 5
done
- name: Verify decimo.mojopkg was produced
run: test -f decimo.mojopkg
- name: Upload decimo.mojopkg artifact
- name: Verify decimo.mojoc was produced
run: test -f decimo.mojoc
- name: Upload decimo.mojoc artifact
uses: actions/upload-artifact@v4
with:
name: decimo-mojopkg
path: decimo.mojopkg
name: decimo-mojoc
path: decimo.mojoc
retention-days: 1
if-no-files-found: error

Expand Down Expand Up @@ -287,7 +287,7 @@ jobs:
done

# ── Test: CLI ────────────────────────────────────────────────────────────────
# The CLI test needs a freshly built binary, not the .mojopkg, so we
# The CLI test needs a freshly built binary, not the .mojoc, so we
# invoke `pixi run buildcli` here. Uses cached pixi env (no curl install,
# no second `pixi install` from scratch).
test-cli:
Expand Down Expand Up @@ -316,13 +316,13 @@ jobs:
echo "=== build crashed, retrying in 5s... ==="
sleep 5
done
- name: Stage decimo.mojopkg next to tests
- name: Stage decimo.mojoc next to tests
# `tests/test.sh run_cli` and `run_bigfloat` use `-I tests` to load
# the prebuilt `decimo.mojopkg` (Mojo 1.0.0b1's `mojo run/build`
# the prebuilt `decimo.mojoc` (Mojo's `mojo run/build`
# cannot resolve `decimo.X.Y.foo` qualified references when
# re-traversing source via `-I src`). `pixi run buildcli` produces
# the package at `temp/decimo.mojopkg`, so stage a copy here.
run: cp temp/decimo.mojopkg tests/
# the package at `temp/decimo.mojoc`, so stage a copy here.
run: cp temp/decimo.mojoc tests/
- name: Run tests (with retry for Mojo compiler intermittent crashes)
run: |
for attempt in 1 2 3; do
Expand Down
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@
.magic
magic.lock

# mojopkg files
# mojo pre-compiled files
*.mojopkg
*.mojoc

# Editor environments
.vscode
Expand Down
6 changes: 6 additions & 0 deletions docs/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ This is a list of changes for the Decimo package (formerly DeciMojo).

## Unreleased

1. **Migrated the codebase to Mojo v1.0.0b2.** Bumped the Pixi `mojo`
dependency to `>=1.0.0b2` and `argmojo` to `0.7.0`. Switched packaging
from the deprecated `mojo package` / `.mojopkg` to `mojo precompile` /
`.mojoc` across Pixi tasks, CI workflows, and helper scripts, and
updated the `Decimal128` string formatter to the
`StringSlice(unsafe_from_utf8=Span(...))` constructor (PR #257).
1. **Renamed `BigDecimal` rounding APIs to `*_inplace`.**
The free function `decimo.bigdecimal.rounding.round_to_precision` and
the `BigDecimal.round_to_precision` method were renamed to
Expand Down
6 changes: 3 additions & 3 deletions docs/plans/gmp_integration.md
Original file line number Diff line number Diff line change
Expand Up @@ -813,8 +813,8 @@ Link against whichever is present. The stub library lets Decimo compile and run

**Phase 1 (immediate)**: Use **Option A** — compile-time feature flag. Build two package variants:

- `decimo.mojopkg` — native only (default)
- `decimo_gmp.mojopkg` — with GMP backend
- `decimo.mojoc` — native only (default)
- `decimo_gmp.mojoc` — with GMP backend

**Phase 2 (when Mojo matures)**: Migrate to **Option B** with `DLHandle` when available, enabling true runtime detection.

Expand Down Expand Up @@ -1132,7 +1132,7 @@ build-gmp-wrapper = """

package-with-gmp = { depends-on = ["build-gmp-wrapper"] }
package-with-gmp.cmd = """
mojo package src/decimo -o decimo.mojopkg && \
mojo precompile src/decimo -o decimo.mojoc && \
cp src/decimo/gmp/libgmp_wrapper.dylib .
"""
```
Expand Down
6 changes: 3 additions & 3 deletions docs/plans/mojo4py.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

Modular has introduced a beta mechanism that allows Mojo code to be exposed as a standard CPython extension module (`.so` / `.dylib`). This means a Python user can write `import decimo` and get access to Mojo-native `Decimal128`, `BigDecimal`, `BigInt`, and `BigUint` types at near-native speed, without rewriting anything in Python.

**Feasibility verdict: Possible but non-trivial.** The main (no surprise) blocker is that decimo is a *packaged* Mojo library (`.mojopkg`), not a single `.mojo` file. The Mojo importer hook (the easy dev-time path) does not support custom import paths for non-stdlib Mojo packages. The `.so` build path (the distribution path) works fine. This means the developer workflow is slightly more manual, but distribution is fully viable.
**Feasibility verdict: Possible but non-trivial.** The main (no surprise) blocker is that decimo is a *packaged* Mojo library (`.mojoc`), not a single `.mojo` file. The Mojo importer hook (the easy dev-time path) does not support custom import paths for non-stdlib Mojo packages. The `.so` build path (the distribution path) works fine. This means the developer workflow is slightly more manual, but distribution is fully viable.

---

Expand All @@ -25,7 +25,7 @@ Modular has introduced a beta mechanism that allows Mojo code to be exposed as a
| **Source import hook** | `import mojo.importer` in Python, then `import mojo_module` (auto-compiles `.mojo` → `.so` into `__mojocache__/`) | Dev prototyping with single-file modules only |
| **Pre-built `.so`** | `mojo build mojo_module.mojo --emit shared-lib -o mojo_module.so` | Production, packages with dependencies, CI/CD |

For decimo, **only the pre-built `.so` path is viable** because the binding code will `import decimo` (the `.mojopkg`), and the importer hook cannot resolve that path.
For decimo, **only the pre-built `.so` path is viable** because the binding code will `import decimo` (the `.mojoc`), and the importer hook cannot resolve that path.

### 2.2 The Binding Pattern

Expand Down Expand Up @@ -183,7 +183,7 @@ tpy = "clear && pixi run testpy"
wheel = "cd python && pixi run python -m build --wheel"
```

- `pixi run buildpy` — compiles the Mojo binding directly into the installable package at `python/src/decimo/_decimo.so`. No need to pre-package `decimo.mojopkg`; the `-I src` flag resolves `import decimo` to `src/decimo/`.
- `pixi run buildpy` — compiles the Mojo binding directly into the installable package at `python/src/decimo/_decimo.so`. No need to pre-package `decimo.mojoc`; the `-I src` flag resolves `import decimo` to `src/decimo/`.
- `pixi run testpy` — builds then runs the Python test suite.
- `pixi run wheel` — produces a pure-Python placeholder wheel in `python/dist/` (no `.so` included); suitable for PyPI name reservation.

Expand Down
6 changes: 3 additions & 3 deletions docs/readme_unreleased.md
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,7 @@ Bug reports and feature requests are welcome! If you encounter issues, please [f
```text
decimo/
├── src/ # All source code
│ ├── decimo/ # Core library (mojo package)
│ ├── decimo/ # Core library (mojo precompile)
│ │ ├── bigdecimal/ # Arbitrary-precision decimal (Decimal)
│ │ ├── bigint/ # Arbitrary-precision signed integer (Integer)
│ │ ├── bigint10/ # Base-10 signed integer (BigInt10)
Expand All @@ -409,7 +409,7 @@ decimo/
│ │ └── ... # Shared utilities (str, errors, rounding)
│ └── cli/ # CLI calculator application
│ ├── main.mojo # Entry point (ArgMojo CLI)
│ └── calculator/ # Calculator engine (mojo package)
│ └── calculator/ # Calculator engine (mojo precompile)
│ ├── tokenizer.mojo # Lexer: expression → tokens
│ ├── parser.mojo # Shunting-yard: infix → RPN
│ └── evaluator.mojo # RPN evaluator using Decimal
Expand All @@ -425,7 +425,7 @@ decimo/
└── pixi.toml # Project configuration and tasks
```

`src/decimo/` is a Mojo package — it is compiled with `mojo package` and can be imported by external projects. The TOML parser (`decimo.toml`) is included as a subpackage. `src/cli/` is an application that consumes the `decimo` package and compiles to a standalone binary via `mojo build`.
`src/decimo/` is a Mojo package — it is compiled with `mojo precompile` and can be imported by external projects. The TOML parser (`decimo.toml`) is included as a subpackage. `src/cli/` is an application that consumes the `decimo` package and compiles to a standalone binary via `mojo build`.

## Tests and benches

Expand Down
10 changes: 5 additions & 5 deletions examples/run_bigfloat.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#
# What it does:
# 1. Ensures the GMP/MPFR C wrapper (libdecimo_gmp_wrapper) is built.
# 2. Ensures tests/decimo.mojopkg is available (built on demand).
# 2. Ensures tests/decimo.mojoc is available (built on demand).
# 3. Builds <file.mojo> with `-I tests`, debug info, and ASSERT=all,
# linking against the C wrapper. Output binary goes to temp/<name>.
# 4. Executes the binary with DYLD_LIBRARY_PATH / LD_LIBRARY_PATH set
Expand Down Expand Up @@ -43,10 +43,10 @@ if [[ ! -f "$WRAPPER_LIB" ]]; then
bash "$WRAPPER_DIR/build_gmp_wrapper.sh"
fi

# 2. Ensure decimo.mojopkg exists for `-I tests`.
if [[ ! -f tests/decimo.mojopkg ]]; then
echo "==> Building tests/decimo.mojopkg..."
pixi run mojo package src/decimo -o tests/decimo.mojopkg
# 2. Ensure decimo.mojoc exists for `-I tests`.
if [[ ! -f tests/decimo.mojoc ]]; then
echo "==> Building tests/decimo.mojoc..."
pixi run mojo precompile src/decimo -o tests/decimo.mojoc
fi

# 3. Build the user's .mojo file into temp/<basename>.
Expand Down
Loading
Loading