mojo-bindgen 0.2.1__tar.gz → 0.3.2__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {mojo_bindgen-0.2.1 → mojo_bindgen-0.3.2}/.gitignore +4 -0
- mojo_bindgen-0.3.2/CHANGELOG.md +163 -0
- {mojo_bindgen-0.2.1 → mojo_bindgen-0.3.2}/PKG-INFO +80 -29
- {mojo_bindgen-0.2.1 → mojo_bindgen-0.3.2}/README.md +79 -28
- mojo_bindgen-0.3.2/mojo_bindgen/analysis/__init__.py +120 -0
- mojo_bindgen-0.3.2/mojo_bindgen/analysis/cir/__init__.py +1 -0
- mojo_bindgen-0.3.2/mojo_bindgen/analysis/cir/cir_canonicalizer.py +319 -0
- mojo_bindgen-0.3.2/mojo_bindgen/analysis/cir/reachability.py +166 -0
- mojo_bindgen-0.3.2/mojo_bindgen/analysis/cir/reference_validation.py +75 -0
- {mojo_bindgen-0.2.1/mojo_bindgen/analysis → mojo_bindgen-0.3.2/mojo_bindgen/analysis/cir}/validate_ir.py +27 -26
- mojo_bindgen-0.3.2/mojo_bindgen/analysis/facts/__init__.py +1 -0
- mojo_bindgen-0.3.2/mojo_bindgen/analysis/facts/alias_classification.py +120 -0
- {mojo_bindgen-0.2.1/mojo_bindgen/analysis → mojo_bindgen-0.3.2/mojo_bindgen/analysis/facts}/bitfield_layout.py +88 -44
- mojo_bindgen-0.3.2/mojo_bindgen/analysis/facts/context.py +84 -0
- mojo_bindgen-0.3.2/mojo_bindgen/analysis/facts/dependency_graph.py +66 -0
- mojo_bindgen-0.3.2/mojo_bindgen/analysis/facts/indexes.py +82 -0
- {mojo_bindgen-0.2.1/mojo_bindgen/analysis → mojo_bindgen-0.3.2/mojo_bindgen/analysis/facts}/record_layout.py +92 -48
- mojo_bindgen-0.3.2/mojo_bindgen/analysis/facts/record_storage.py +507 -0
- mojo_bindgen-0.3.2/mojo_bindgen/analysis/mojo/__init__.py +1 -0
- mojo_bindgen-0.3.2/mojo_bindgen/analysis/mojo/alias_mapping.py +49 -0
- mojo_bindgen-0.3.2/mojo_bindgen/analysis/mojo/const_expr_mapping.py +87 -0
- mojo_bindgen-0.3.2/mojo_bindgen/analysis/mojo/const_value_mapping.py +54 -0
- mojo_bindgen-0.3.2/mojo_bindgen/analysis/mojo/decl_mapping.py +216 -0
- mojo_bindgen-0.3.2/mojo_bindgen/analysis/mojo/macro_mapping.py +142 -0
- mojo_bindgen-0.3.2/mojo_bindgen/analysis/mojo/mapping_support.py +95 -0
- {mojo_bindgen-0.2.1/mojo_bindgen/analysis → mojo_bindgen-0.3.2/mojo_bindgen/analysis/mojo}/mojo_emit_options.py +6 -3
- {mojo_bindgen-0.2.1/mojo_bindgen/analysis → mojo_bindgen-0.3.2/mojo_bindgen/analysis/mojo}/record_policies.py +17 -25
- mojo_bindgen-0.2.1/mojo_bindgen/analysis/struct_lowering.py → mojo_bindgen-0.3.2/mojo_bindgen/analysis/mojo/struct_mapping.py +174 -87
- mojo_bindgen-0.2.1/mojo_bindgen/analysis/type_lowering.py → mojo_bindgen-0.3.2/mojo_bindgen/analysis/mojo/type_mapping.py +67 -67
- mojo_bindgen-0.3.2/mojo_bindgen/analysis/mojo/union_mapping.py +175 -0
- mojo_bindgen-0.3.2/mojo_bindgen/analysis/mojo/unit_mapping.py +113 -0
- mojo_bindgen-0.3.2/mojo_bindgen/analysis/pipeline.py +117 -0
- mojo_bindgen-0.3.2/mojo_bindgen/analysis/traversal.py +162 -0
- {mojo_bindgen-0.2.1 → mojo_bindgen-0.3.2}/mojo_bindgen/analysis/type_walk.py +1 -1
- mojo_bindgen-0.3.2/mojo_bindgen/cli.py +391 -0
- {mojo_bindgen-0.2.1 → mojo_bindgen-0.3.2}/mojo_bindgen/codegen/mojo_ir_printer.py +245 -112
- mojo_bindgen-0.3.2/mojo_bindgen/codegen/mojo_support_templates.py +199 -0
- {mojo_bindgen-0.2.1 → mojo_bindgen-0.3.2}/mojo_bindgen/codegen/normalize_mojo_module.py +77 -55
- mojo_bindgen-0.3.2/mojo_bindgen/ir.py +1565 -0
- {mojo_bindgen-0.2.1 → mojo_bindgen-0.3.2}/mojo_bindgen/layout_tests/generator.py +29 -24
- {mojo_bindgen-0.2.1 → mojo_bindgen-0.3.2}/mojo_bindgen/orchestrator.py +60 -8
- mojo_bindgen-0.3.2/mojo_bindgen/parsing/doc_comments.py +35 -0
- {mojo_bindgen-0.2.1 → mojo_bindgen-0.3.2}/mojo_bindgen/parsing/frontend.py +118 -21
- {mojo_bindgen-0.2.1 → mojo_bindgen-0.3.2}/mojo_bindgen/parsing/lowering/__init__.py +7 -2
- {mojo_bindgen-0.2.1 → mojo_bindgen-0.3.2}/mojo_bindgen/parsing/lowering/const_expr.py +264 -20
- {mojo_bindgen-0.2.1 → mojo_bindgen-0.3.2}/mojo_bindgen/parsing/lowering/decl_lowering.py +86 -16
- {mojo_bindgen-0.2.1 → mojo_bindgen-0.3.2}/mojo_bindgen/parsing/lowering/macro_env.py +11 -9
- {mojo_bindgen-0.2.1 → mojo_bindgen-0.3.2}/mojo_bindgen/parsing/lowering/record_lowering.py +79 -12
- {mojo_bindgen-0.2.1 → mojo_bindgen-0.3.2}/mojo_bindgen/parsing/lowering/type_lowering.py +11 -4
- {mojo_bindgen-0.2.1 → mojo_bindgen-0.3.2}/mojo_bindgen/parsing/parser.py +40 -2
- {mojo_bindgen-0.2.1 → mojo_bindgen-0.3.2}/mojo_bindgen/parsing/registry.py +7 -17
- {mojo_bindgen-0.2.1 → mojo_bindgen-0.3.2}/mojo_bindgen/serde.py +0 -2
- {mojo_bindgen-0.2.1 → mojo_bindgen-0.3.2}/mojo_bindgen/utils.py +2 -1
- {mojo_bindgen-0.2.1 → mojo_bindgen-0.3.2}/pyproject.toml +1 -2
- mojo_bindgen-0.2.1/CHANGELOG.md +0 -83
- mojo_bindgen-0.2.1/mojo_bindgen/analysis/__init__.py +0 -81
- mojo_bindgen-0.2.1/mojo_bindgen/analysis/cir_canonicalizer.py +0 -39
- mojo_bindgen-0.2.1/mojo_bindgen/analysis/const_lowering.py +0 -95
- mojo_bindgen-0.2.1/mojo_bindgen/analysis/decl_lowerer.py +0 -294
- mojo_bindgen-0.2.1/mojo_bindgen/analysis/lowering_support.py +0 -103
- mojo_bindgen-0.2.1/mojo_bindgen/analysis/orchestrator.py +0 -79
- mojo_bindgen-0.2.1/mojo_bindgen/analysis/reachability.py +0 -205
- mojo_bindgen-0.2.1/mojo_bindgen/analysis/union_lowering.py +0 -145
- mojo_bindgen-0.2.1/mojo_bindgen/analysis/unit_lowering.py +0 -186
- mojo_bindgen-0.2.1/mojo_bindgen/cli.py +0 -166
- mojo_bindgen-0.2.1/mojo_bindgen/ir.py +0 -809
- mojo_bindgen-0.2.1/mojo_bindgen/mojo_ir.py +0 -735
- {mojo_bindgen-0.2.1 → mojo_bindgen-0.3.2}/LICENSE +0 -0
- {mojo_bindgen-0.2.1 → mojo_bindgen-0.3.2}/mojo_bindgen/__init__.py +0 -0
- {mojo_bindgen-0.2.1 → mojo_bindgen-0.3.2}/mojo_bindgen/analysis/common.py +0 -0
- {mojo_bindgen-0.2.1/mojo_bindgen/analysis → mojo_bindgen-0.3.2/mojo_bindgen/analysis/facts}/type_layout.py +0 -0
- {mojo_bindgen-0.2.1 → mojo_bindgen-0.3.2}/mojo_bindgen/codegen/__init__.py +0 -0
- {mojo_bindgen-0.2.1 → mojo_bindgen-0.3.2}/mojo_bindgen/layout_tests/__init__.py +0 -0
- {mojo_bindgen-0.2.1 → mojo_bindgen-0.3.2}/mojo_bindgen/parsing/__init__.py +0 -0
- {mojo_bindgen-0.2.1 → mojo_bindgen-0.3.2}/mojo_bindgen/parsing/diagnostics.py +0 -0
- {mojo_bindgen-0.2.1 → mojo_bindgen-0.3.2}/mojo_bindgen/parsing/lowering/literal_resolver.py +0 -0
- {mojo_bindgen-0.2.1 → mojo_bindgen-0.3.2}/mojo_bindgen/parsing/lowering/primitive.py +0 -0
- {mojo_bindgen-0.2.1 → mojo_bindgen-0.3.2}/mojo_bindgen/parsing/target_abi.py +0 -0
- {mojo_bindgen-0.2.1 → mojo_bindgen-0.3.2}/mojo_bindgen/py.typed +0 -0
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to this project are documented in this file.
|
|
4
|
+
|
|
5
|
+
## [0.3.2] - 2026-06-23
|
|
6
|
+
|
|
7
|
+
### Changed
|
|
8
|
+
|
|
9
|
+
- Simplify and clarify the CLI surface: keep `--public-header` and
|
|
10
|
+
`--clang-arg`, add conventional `-o`, `-I`, `-D`, and `-U` forms, make
|
|
11
|
+
layout-test output explicit with `--layout-tests PATH`, and hide maintainer
|
|
12
|
+
debug sidecars from normal help.
|
|
13
|
+
- Improve CLI help grouping and wording for input headers, Clang pass-through
|
|
14
|
+
flags, output, linking, diagnostics, and the current transitive `#include`
|
|
15
|
+
behavior.
|
|
16
|
+
- Make `owned_dl_handle` dynamic-library loading portable by trying generated
|
|
17
|
+
and generic environment overrides, Pixi/Conda environment locations, and
|
|
18
|
+
Linux/macOS fallback names, and move generated Mojo support blocks into
|
|
19
|
+
reusable codegen templates.
|
|
20
|
+
|
|
21
|
+
- Avoid invalid Mojo in `owned_dl_handle` wrappers when a C parameter name
|
|
22
|
+
collides with the generated function-pointer local, and use a clearer
|
|
23
|
+
`_bindgen_c_fn` internal name.
|
|
24
|
+
|
|
25
|
+
- Added new emission model for `owned_dl_handle` were functions are now non-raising and the `OwnedDLHandle` is stored globally to avoid the overhead of its creation on every function call.
|
|
26
|
+
|
|
27
|
+
- Update generated Mojo bindings, layout-test sidecars, and example smoke tests
|
|
28
|
+
for Mojo 1.0.0b2 syntax changes, including `def`, explicit `abi("C")`,
|
|
29
|
+
`reflect[T]`, and the new `UntrackedOrigin` / `UnsafeAnyOrigin` spelling
|
|
30
|
+
family.
|
|
31
|
+
|
|
32
|
+
## [0.3] 2026-06-01
|
|
33
|
+
|
|
34
|
+
### Added
|
|
35
|
+
|
|
36
|
+
- Capture C documentation comments from libclang and emit them into generated
|
|
37
|
+
Mojo bindings, with `--doc-comments` / `--no-doc-comments` control.
|
|
38
|
+
- Add repeatable `--include-header` support for parsing multiple public entry
|
|
39
|
+
headers through a virtual umbrella translation unit.
|
|
40
|
+
- Add an opt-in Clang macro fallback for unsupported integer macro expressions,
|
|
41
|
+
broader macro constant folding for logical/comparison/ternary forms, string
|
|
42
|
+
literal concatenation and escape decoding, and regression coverage for macro
|
|
43
|
+
closure and canonicalization behavior.
|
|
44
|
+
- Handle repeated field types in anonymous unions by still lowering them to
|
|
45
|
+
`UnsafeUnion`, (@WolfDan; PR #9).
|
|
46
|
+
- Lower flexible array member declarations as `InlineArray[T, 0]` instead of
|
|
47
|
+
deriving their size from the containing struct, (@WolfDan; PR #9).
|
|
48
|
+
- Detect trailing C99 flexible array members (`[]`) and GNU zero-length tail
|
|
49
|
+
arrays (`[0]`) explicitly during record lowering, carry their metadata
|
|
50
|
+
through CIR and MojoIR, and emit generated tail-access helpers plus runtime
|
|
51
|
+
coverage for both forms.
|
|
52
|
+
|
|
53
|
+
### Changed
|
|
54
|
+
|
|
55
|
+
- Generate layout-test sidecars with `TestSuite.discover_tests[__functions_in_module()]().run()`
|
|
56
|
+
in `main` and import `TestSuite` from `std.testing` so the generated module
|
|
57
|
+
runs its own discovered tests directly.
|
|
58
|
+
- Resolve layout-test reflection offsets from emitted Mojo member order instead
|
|
59
|
+
of CIR field indices, so generated checks stay aligned when padding members
|
|
60
|
+
are inserted before named fields or bitfield groups.
|
|
61
|
+
- Lower named C enums to scalar Mojo type aliases plus typed top-level
|
|
62
|
+
enumerator constants, preferring typedef names as the primary emitted alias,
|
|
63
|
+
emitting collision-free tag aliases when possible, and keeping anonymous
|
|
64
|
+
enums on the existing constants-only path.
|
|
65
|
+
- Emit top-level declarations and source-backed macros from the parsed
|
|
66
|
+
translation unit instead of filtering to configured header paths, including
|
|
67
|
+
transitive include declarations and macros.
|
|
68
|
+
- Keep source-backed macro folding aligned with emission: object-like macros
|
|
69
|
+
from the emitted translation-unit macro set are available for expansion, while
|
|
70
|
+
compiler/predefined no-file macros are neither emitted nor used for folding.
|
|
71
|
+
- Treat integer macro literals as signed by default when no suffix, parsed cast,
|
|
72
|
+
or Clang-provided type information says otherwise, while preserving explicit
|
|
73
|
+
unsigned suffixes and Clang-resolved integer types.
|
|
74
|
+
- Prune empty source macros from the parsed IR and suppress any empty macro
|
|
75
|
+
declarations that reach Mojo lowering, so they no longer emit placeholder
|
|
76
|
+
comments or aliases.
|
|
77
|
+
- Rename the orphan-record reachability repair to signature-only record stub
|
|
78
|
+
materialization, and keep it only for references like
|
|
79
|
+
`int f(struct opaque *p);` that have no standalone top-level record cursor.
|
|
80
|
+
- Retain documentation comments from system headers during parsing when
|
|
81
|
+
doc-comment emission is enabled, while preserving the default probed include
|
|
82
|
+
search path so header-heavy examples like SQLite continue to parse.
|
|
83
|
+
- Treat structs with flexible tail arrays as memory-only header-prefix types,
|
|
84
|
+
reject by-value embedding of such structs from typed layout lowering, and
|
|
85
|
+
keep one-element tail arrays (`[1]`) as ordinary fixed arrays.
|
|
86
|
+
|
|
87
|
+
### Removed
|
|
88
|
+
|
|
89
|
+
- Remove parser-side embedded-record materialization and primary-header cursor
|
|
90
|
+
compatibility aliases now that the parser lowers translation-unit cursors
|
|
91
|
+
directly.
|
|
92
|
+
|
|
93
|
+
## [0.2.1] - 2026-05-01
|
|
94
|
+
|
|
95
|
+
### Changed
|
|
96
|
+
|
|
97
|
+
- Bump the package version to `0.2.1` and update the release tag naming to use
|
|
98
|
+
the `compiler` suffix.
|
|
99
|
+
|
|
100
|
+
## [0.2] - 2026-05-01
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
### Added
|
|
104
|
+
|
|
105
|
+
- added CIRCanoncanlizer pass, for now only deduplicates IR nodes. [f9b4156](https://github.com/MoSafi2/mojo_bindgen/commit/f9b4156d5be1d8123c6256a68966d23c8778246c)
|
|
106
|
+
- Generate optional Mojo record-layout test sidecars from normalized CIR facts,
|
|
107
|
+
including `--layout-tests`, `--no-layout-tests`, `--layout-test-output`, and
|
|
108
|
+
the `generate_mojo_artifacts` Python API.
|
|
109
|
+
|
|
110
|
+
### Changed
|
|
111
|
+
|
|
112
|
+
- Split bindgen into explicit parsing, analysis, codegen, and top-level
|
|
113
|
+
orchestration layers. The new public surface is
|
|
114
|
+
`BindgenOptions` / `BindgenOrchestrator` / `BindgenResult` / `bindgen`, and
|
|
115
|
+
the old `MojoGenerator` / `generate_mojo` / `generate_mojo_artifacts` /
|
|
116
|
+
`analyze_to_mojo_module` APIs are removed.
|
|
117
|
+
- Unify MojoIR callable signatures under `FunctionPtr` so function-pointer
|
|
118
|
+
lowering, callback typedefs, and callback aliases all share the same schema.
|
|
119
|
+
This removes the separate `CallbackType` / `CallbackParam` MojoIR shape.
|
|
120
|
+
- Make synthesized bitfield accessors branch at comptime on
|
|
121
|
+
`std.sys.info.is_little_endian()` / `is_big_endian()` while keeping target
|
|
122
|
+
byte order in `TargetABI` for ABI metadata instead of printer-side selection.
|
|
123
|
+
- Lower exact-width stdint typedef aliases such as `int32_t`, `uint32_t`,
|
|
124
|
+
`int64_t`, and `uint64_t` to Mojo fixed-width integer types while preserving
|
|
125
|
+
ordinary C ABI scalar aliases such as `c_int` and `c_long`.
|
|
126
|
+
- Lower `size_t` and `ssize_t` typedef aliases to Mojo native `UInt` and `Int`
|
|
127
|
+
respectively instead of emitting FFI scalar builtins.
|
|
128
|
+
- Render synthesized struct padding as aligned Mojo integer fields so padded
|
|
129
|
+
records can remain register-passable when their real fields are passable.
|
|
130
|
+
- Remove the stale, unused `ffi_scalar_style` emit option and public
|
|
131
|
+
`FFIScalarStyle` export.
|
|
132
|
+
- Lower named CIR enums into `StructDecl(kind=ENUM)` in MojoIR instead of a
|
|
133
|
+
separate `EnumDecl` shape.
|
|
134
|
+
- Add struct-local `comptime` members to MojoIR so enum constants and similar
|
|
135
|
+
in-struct aliases can be represented and rendered directly from `StructDecl`.
|
|
136
|
+
- Replace MojoIR module capability toggles with a concrete dependency container
|
|
137
|
+
that records imports and support helpers explicitly for normalization and
|
|
138
|
+
printing.
|
|
139
|
+
- Render C data pointers as `Optional[UnsafePointer[...]]` or optional opaque
|
|
140
|
+
pointer aliases so generated Mojo signatures represent nullable C pointers
|
|
141
|
+
explicitly.
|
|
142
|
+
- Update generated layout-test sidecars to use the newer Mojo reflection API
|
|
143
|
+
(`reflect[T]()` with `field_offset[...]()`) instead of the legacy
|
|
144
|
+
`offset_of[...]()` form.
|
|
145
|
+
|
|
146
|
+
## [0.1.1a] - 2026-04-24
|
|
147
|
+
|
|
148
|
+
### Added
|
|
149
|
+
|
|
150
|
+
- First public alpha release of `mojo-bindgen`.
|
|
151
|
+
- CLI packaging for `mojo-bindgen`, including PyPI metadata, MIT license, and
|
|
152
|
+
`py.typed`.
|
|
153
|
+
- `libclang`-based C parsing and structured lowering through CIR and Mojo IR.
|
|
154
|
+
- Mojo code generation for both `external_call` and `owned_dl_handle` linking modes.
|
|
155
|
+
- Support for core C surfaces including scalars, typedef chains, pointers,
|
|
156
|
+
arrays, structs, unions, enums, bitfields, callbacks, globals, constants,
|
|
157
|
+
and a supported subset of object-like macros.
|
|
158
|
+
- Numeric lowering for Mojo-native constructs including `SIMD[...]`,
|
|
159
|
+
`ComplexSIMD[...]`, and representable `Atomic[...]`.
|
|
160
|
+
- JSON IR output support for debugging and downstream tooling.
|
|
161
|
+
- Worked examples for SQLite, Cairo, libpng, and zlib.
|
|
162
|
+
- Development tooling and automation: Ruff, Pyright, Pixi tasks, CI validation,
|
|
163
|
+
and release publishing workflow.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: mojo-bindgen
|
|
3
|
-
Version: 0.2
|
|
3
|
+
Version: 0.3.2
|
|
4
4
|
Summary: Generate Mojo FFI bindings from C headers using libclang
|
|
5
5
|
Project-URL: Homepage, https://github.com/MoSafi2/mojo_bindgen
|
|
6
6
|
Project-URL: Repository, https://github.com/MoSafi2/mojo_bindgen
|
|
@@ -98,15 +98,28 @@ For development setup, checks, and Pixi workflows, see
|
|
|
98
98
|
Generate bindings from a primary header:
|
|
99
99
|
|
|
100
100
|
```bash
|
|
101
|
-
mojo-bindgen path/to/header.h -o bindings.mojo --
|
|
101
|
+
mojo-bindgen path/to/header.h -o bindings.mojo --link-mode external-call
|
|
102
102
|
```
|
|
103
103
|
|
|
104
|
-
Pass
|
|
104
|
+
Pass common Clang inputs with structured flags:
|
|
105
105
|
|
|
106
106
|
```bash
|
|
107
107
|
mojo-bindgen include/mylib.h \
|
|
108
|
-
|
|
109
|
-
|
|
108
|
+
-I ./include \
|
|
109
|
+
-D MYLIB_FEATURE=1 \
|
|
110
|
+
--std c11 \
|
|
111
|
+
-o mylib_bindings.mojo
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
Add sibling public headers with repeated `--public-header`. The primary header
|
|
115
|
+
and public headers are included in an internal umbrella header. Transitive
|
|
116
|
+
`#include` files are parsed by Clang and can still contribute declarations
|
|
117
|
+
because source-file filtering is not applied yet:
|
|
118
|
+
|
|
119
|
+
```bash
|
|
120
|
+
mojo-bindgen include/mylib.h \
|
|
121
|
+
--public-header include/mylib_extra.h \
|
|
122
|
+
-I ./include \
|
|
110
123
|
-o mylib_bindings.mojo
|
|
111
124
|
```
|
|
112
125
|
|
|
@@ -114,7 +127,13 @@ By default the parser uses `-std=gnu11` when no C standard is provided. Pin a
|
|
|
114
127
|
standard explicitly if your header requires one:
|
|
115
128
|
|
|
116
129
|
```bash
|
|
117
|
-
mojo-bindgen include/mylib.h --
|
|
130
|
+
mojo-bindgen include/mylib.h --std c99 -o mylib_bindings.mojo
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
Use `--clang-arg` for raw Clang flags that do not have a structured option:
|
|
134
|
+
|
|
135
|
+
```bash
|
|
136
|
+
mojo-bindgen include/mylib.h --clang-arg=-fms-extensions -o mylib_bindings.mojo
|
|
118
137
|
```
|
|
119
138
|
|
|
120
139
|
## Linking modes
|
|
@@ -132,12 +151,12 @@ Examples:
|
|
|
132
151
|
|
|
133
152
|
```bash
|
|
134
153
|
# default
|
|
135
|
-
mojo-bindgen include/mylib.h --
|
|
154
|
+
mojo-bindgen include/mylib.h --link-mode external-call -o mylib_bindings.mojo
|
|
136
155
|
|
|
137
156
|
# runtime-loaded shared library
|
|
138
157
|
mojo-bindgen include/mylib.h \
|
|
139
|
-
--
|
|
140
|
-
--library-path
|
|
158
|
+
--link-mode owned-dl-handle \
|
|
159
|
+
--library-path /usr/lib/libmylib.so \
|
|
141
160
|
-o mylib_bindings_dl.mojo
|
|
142
161
|
```
|
|
143
162
|
|
|
@@ -149,24 +168,24 @@ generating bindings.
|
|
|
149
168
|
|
|
150
169
|
Current support includes:
|
|
151
170
|
|
|
152
|
-
- **Parsing and
|
|
171
|
+
- **Parsing and mapping:** real C parsing through `libclang`, repeatable `--clang-arg`
|
|
153
172
|
support, and a structured IR pipeline rather than text-only generation.
|
|
154
173
|
- **Primitive types:** scalar types, typedef chains, pointers with const-aware
|
|
155
174
|
mutability, fixed arrays, incomplete-array decay cases, complex values,
|
|
156
175
|
vector extension types, and representable atomics.
|
|
157
|
-
- **Mojo-native numeric
|
|
158
|
-
values
|
|
176
|
+
- **Mojo-native numeric mapping:** vector types map to `SIMD[...]`, complex
|
|
177
|
+
values map to `ComplexSIMD[...]`, and representable atomics map to
|
|
159
178
|
`Atomic[...]`.
|
|
160
179
|
- **Records:** structs, anonymous members, mixed layouts that combine plain
|
|
161
180
|
fields and bitfields, synthesized padding, and custom alignment emission
|
|
162
181
|
where Mojo can represent the layout faithfully.
|
|
163
182
|
- **Bitfields:** bitfields are emitted through explicit storage fields plus
|
|
164
183
|
synthesized getter and setter methods.
|
|
165
|
-
- **Unions:** eligible unions
|
|
184
|
+
- **Unions:** eligible unions map to `UnsafeUnion[...]`; unions that cannot
|
|
166
185
|
be represented safely fall back to opaque `InlineArray[...]` storage with
|
|
167
186
|
diagnostics to preserve layout.
|
|
168
187
|
- **Opaque and difficult layouts:** incomplete records, packed layouts, and
|
|
169
|
-
alignment-sensitive record
|
|
188
|
+
alignment-sensitive record storages are preserved conservatively as opaque byte
|
|
170
189
|
storage when a faithful typed layout is not possible.
|
|
171
190
|
- **Callbacks and function pointers:** callback typedefs, function-pointer
|
|
172
191
|
fields, and function-pointer parameters and returns are preserved in Mojo via
|
|
@@ -174,14 +193,14 @@ Current support includes:
|
|
|
174
193
|
- **Functions:** thin wrappers are generated for non-variadic functions under
|
|
175
194
|
both `external_call` and `owned_dl_handle` link modes.
|
|
176
195
|
- **Globals and constants:** because Mojo does not currently expose native C
|
|
177
|
-
globals directly, supported globals
|
|
196
|
+
globals directly, supported globals map through generated `GlobalVar` /
|
|
178
197
|
`GlobalConst` helper structs with synthesized `load()` / `store()` methods;
|
|
179
|
-
constants and supported object-like macros
|
|
198
|
+
constants and supported object-like macros map to `comptime` declarations.
|
|
180
199
|
- **Macros:** integer, float, string, and char literal macros, foldable macro
|
|
181
200
|
chains, supported casts, and `sizeof(type)` expressions are emitted as Mojo
|
|
182
201
|
code.
|
|
183
|
-
- **
|
|
184
|
-
|
|
202
|
+
- **Debug IR output:** the CLI has hidden maintainer flags for serialized parser
|
|
203
|
+
and Mojo IR sidecars.
|
|
185
204
|
|
|
186
205
|
## Current limitations
|
|
187
206
|
|
|
@@ -208,10 +227,10 @@ verify emitted layouts and symbols against your target toolchain.
|
|
|
208
227
|
- **Linkage and compiler edge cases:** `inline`, compiler-specific linkage
|
|
209
228
|
hints, and other extension-heavy cases can still require manual review and
|
|
210
229
|
may lead to symbol mismatches at runtime.
|
|
211
|
-
- **
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
230
|
+
- **Public-header model:** the primary header and any `--public-header` values
|
|
231
|
+
are included in an internal umbrella header. Transitive `#include` files are
|
|
232
|
+
also visible to Clang and may contribute declarations because source-file
|
|
233
|
+
filtering is not applied yet.
|
|
215
234
|
|
|
216
235
|
## Real-world examples
|
|
217
236
|
|
|
@@ -221,9 +240,12 @@ The repository includes worked examples and smoke programs for:
|
|
|
221
240
|
- Cairo: [examples/cairo](examples/cairo)
|
|
222
241
|
- libpng: [examples/libpng](examples/libpng)
|
|
223
242
|
- zlib: [examples/zlib](examples/zlib)
|
|
243
|
+
- globals/constants: [examples/global_consts](examples/global_consts)
|
|
224
244
|
|
|
225
245
|
These examples do more than generate bindings: their `generate.sh` scripts also
|
|
226
|
-
build
|
|
246
|
+
build smoke artifacts or run small functional tests to check the usability of
|
|
247
|
+
the generated bindings. They pass `--layout-tests` explicitly when they need
|
|
248
|
+
layout-test sidecars.
|
|
227
249
|
|
|
228
250
|
The test suite also has end-to-end runtime coverage for:
|
|
229
251
|
|
|
@@ -243,15 +265,44 @@ matrix.
|
|
|
243
265
|
|
|
244
266
|
### The generated module is empty or missing declarations
|
|
245
267
|
|
|
246
|
-
`mojo-bindgen`
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
268
|
+
`mojo-bindgen` parses the primary header plus any headers listed with
|
|
269
|
+
`--public-header` through an internal umbrella header. If a thin wrapper only
|
|
270
|
+
includes another header whose declarations you care about, pass that included
|
|
271
|
+
header with `--public-header` or use it as the primary header directly. Normal
|
|
272
|
+
transitive `#include` files are also visible to Clang and may appear in output.
|
|
250
273
|
|
|
251
274
|
### Parsing fails on project headers
|
|
252
275
|
|
|
253
276
|
Most parser failures are missing include paths, target flags, or defines. Add
|
|
254
|
-
the same flags your C build uses
|
|
277
|
+
the same flags your C build uses with `-I` / `--include`, `-D` / `--define`,
|
|
278
|
+
`-U` / `--undefine`, `--target`, `--sysroot`, `--std`, or repeated
|
|
279
|
+
`--clang-arg`.
|
|
280
|
+
|
|
281
|
+
### Debugging parser failures
|
|
282
|
+
|
|
283
|
+
Print the normalized Clang arguments that `mojo-bindgen` will use:
|
|
284
|
+
|
|
285
|
+
```bash
|
|
286
|
+
mojo-bindgen include/mylib.h -I ./include --print-clang-args
|
|
287
|
+
```
|
|
288
|
+
|
|
289
|
+
Write diagnostics as JSON while still generating normal output:
|
|
290
|
+
|
|
291
|
+
```bash
|
|
292
|
+
mojo-bindgen include/mylib.h \
|
|
293
|
+
--diagnostics json \
|
|
294
|
+
--diagnostics-output diagnostics.json \
|
|
295
|
+
-o mylib_bindings.mojo
|
|
296
|
+
```
|
|
297
|
+
|
|
298
|
+
Dump the preprocessed input that Clang sees:
|
|
299
|
+
|
|
300
|
+
```bash
|
|
301
|
+
mojo-bindgen include/mylib.h \
|
|
302
|
+
-I ./include \
|
|
303
|
+
--dump-preprocessed mylib.preprocessed.c \
|
|
304
|
+
-o mylib_bindings.mojo
|
|
305
|
+
```
|
|
255
306
|
|
|
256
307
|
### Build succeeds but symbols are missing at runtime
|
|
257
308
|
|
|
@@ -259,7 +310,7 @@ Double-check:
|
|
|
259
310
|
|
|
260
311
|
- `--library` and `--link-name`
|
|
261
312
|
- your Mojo link flags for `external_call`
|
|
262
|
-
- your `--library-path
|
|
313
|
+
- your `--library-path` for `owned_dl_handle`
|
|
263
314
|
- whether the original C declaration involved tricky `inline` or exotic layout that needs manual review.
|
|
264
315
|
|
|
265
316
|
## License
|
|
@@ -63,15 +63,28 @@ For development setup, checks, and Pixi workflows, see
|
|
|
63
63
|
Generate bindings from a primary header:
|
|
64
64
|
|
|
65
65
|
```bash
|
|
66
|
-
mojo-bindgen path/to/header.h -o bindings.mojo --
|
|
66
|
+
mojo-bindgen path/to/header.h -o bindings.mojo --link-mode external-call
|
|
67
67
|
```
|
|
68
68
|
|
|
69
|
-
Pass
|
|
69
|
+
Pass common Clang inputs with structured flags:
|
|
70
70
|
|
|
71
71
|
```bash
|
|
72
72
|
mojo-bindgen include/mylib.h \
|
|
73
|
-
|
|
74
|
-
|
|
73
|
+
-I ./include \
|
|
74
|
+
-D MYLIB_FEATURE=1 \
|
|
75
|
+
--std c11 \
|
|
76
|
+
-o mylib_bindings.mojo
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
Add sibling public headers with repeated `--public-header`. The primary header
|
|
80
|
+
and public headers are included in an internal umbrella header. Transitive
|
|
81
|
+
`#include` files are parsed by Clang and can still contribute declarations
|
|
82
|
+
because source-file filtering is not applied yet:
|
|
83
|
+
|
|
84
|
+
```bash
|
|
85
|
+
mojo-bindgen include/mylib.h \
|
|
86
|
+
--public-header include/mylib_extra.h \
|
|
87
|
+
-I ./include \
|
|
75
88
|
-o mylib_bindings.mojo
|
|
76
89
|
```
|
|
77
90
|
|
|
@@ -79,7 +92,13 @@ By default the parser uses `-std=gnu11` when no C standard is provided. Pin a
|
|
|
79
92
|
standard explicitly if your header requires one:
|
|
80
93
|
|
|
81
94
|
```bash
|
|
82
|
-
mojo-bindgen include/mylib.h --
|
|
95
|
+
mojo-bindgen include/mylib.h --std c99 -o mylib_bindings.mojo
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
Use `--clang-arg` for raw Clang flags that do not have a structured option:
|
|
99
|
+
|
|
100
|
+
```bash
|
|
101
|
+
mojo-bindgen include/mylib.h --clang-arg=-fms-extensions -o mylib_bindings.mojo
|
|
83
102
|
```
|
|
84
103
|
|
|
85
104
|
## Linking modes
|
|
@@ -97,12 +116,12 @@ Examples:
|
|
|
97
116
|
|
|
98
117
|
```bash
|
|
99
118
|
# default
|
|
100
|
-
mojo-bindgen include/mylib.h --
|
|
119
|
+
mojo-bindgen include/mylib.h --link-mode external-call -o mylib_bindings.mojo
|
|
101
120
|
|
|
102
121
|
# runtime-loaded shared library
|
|
103
122
|
mojo-bindgen include/mylib.h \
|
|
104
|
-
--
|
|
105
|
-
--library-path
|
|
123
|
+
--link-mode owned-dl-handle \
|
|
124
|
+
--library-path /usr/lib/libmylib.so \
|
|
106
125
|
-o mylib_bindings_dl.mojo
|
|
107
126
|
```
|
|
108
127
|
|
|
@@ -114,24 +133,24 @@ generating bindings.
|
|
|
114
133
|
|
|
115
134
|
Current support includes:
|
|
116
135
|
|
|
117
|
-
- **Parsing and
|
|
136
|
+
- **Parsing and mapping:** real C parsing through `libclang`, repeatable `--clang-arg`
|
|
118
137
|
support, and a structured IR pipeline rather than text-only generation.
|
|
119
138
|
- **Primitive types:** scalar types, typedef chains, pointers with const-aware
|
|
120
139
|
mutability, fixed arrays, incomplete-array decay cases, complex values,
|
|
121
140
|
vector extension types, and representable atomics.
|
|
122
|
-
- **Mojo-native numeric
|
|
123
|
-
values
|
|
141
|
+
- **Mojo-native numeric mapping:** vector types map to `SIMD[...]`, complex
|
|
142
|
+
values map to `ComplexSIMD[...]`, and representable atomics map to
|
|
124
143
|
`Atomic[...]`.
|
|
125
144
|
- **Records:** structs, anonymous members, mixed layouts that combine plain
|
|
126
145
|
fields and bitfields, synthesized padding, and custom alignment emission
|
|
127
146
|
where Mojo can represent the layout faithfully.
|
|
128
147
|
- **Bitfields:** bitfields are emitted through explicit storage fields plus
|
|
129
148
|
synthesized getter and setter methods.
|
|
130
|
-
- **Unions:** eligible unions
|
|
149
|
+
- **Unions:** eligible unions map to `UnsafeUnion[...]`; unions that cannot
|
|
131
150
|
be represented safely fall back to opaque `InlineArray[...]` storage with
|
|
132
151
|
diagnostics to preserve layout.
|
|
133
152
|
- **Opaque and difficult layouts:** incomplete records, packed layouts, and
|
|
134
|
-
alignment-sensitive record
|
|
153
|
+
alignment-sensitive record storages are preserved conservatively as opaque byte
|
|
135
154
|
storage when a faithful typed layout is not possible.
|
|
136
155
|
- **Callbacks and function pointers:** callback typedefs, function-pointer
|
|
137
156
|
fields, and function-pointer parameters and returns are preserved in Mojo via
|
|
@@ -139,14 +158,14 @@ Current support includes:
|
|
|
139
158
|
- **Functions:** thin wrappers are generated for non-variadic functions under
|
|
140
159
|
both `external_call` and `owned_dl_handle` link modes.
|
|
141
160
|
- **Globals and constants:** because Mojo does not currently expose native C
|
|
142
|
-
globals directly, supported globals
|
|
161
|
+
globals directly, supported globals map through generated `GlobalVar` /
|
|
143
162
|
`GlobalConst` helper structs with synthesized `load()` / `store()` methods;
|
|
144
|
-
constants and supported object-like macros
|
|
163
|
+
constants and supported object-like macros map to `comptime` declarations.
|
|
145
164
|
- **Macros:** integer, float, string, and char literal macros, foldable macro
|
|
146
165
|
chains, supported casts, and `sizeof(type)` expressions are emitted as Mojo
|
|
147
166
|
code.
|
|
148
|
-
- **
|
|
149
|
-
|
|
167
|
+
- **Debug IR output:** the CLI has hidden maintainer flags for serialized parser
|
|
168
|
+
and Mojo IR sidecars.
|
|
150
169
|
|
|
151
170
|
## Current limitations
|
|
152
171
|
|
|
@@ -173,10 +192,10 @@ verify emitted layouts and symbols against your target toolchain.
|
|
|
173
192
|
- **Linkage and compiler edge cases:** `inline`, compiler-specific linkage
|
|
174
193
|
hints, and other extension-heavy cases can still require manual review and
|
|
175
194
|
may lead to symbol mismatches at runtime.
|
|
176
|
-
- **
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
195
|
+
- **Public-header model:** the primary header and any `--public-header` values
|
|
196
|
+
are included in an internal umbrella header. Transitive `#include` files are
|
|
197
|
+
also visible to Clang and may contribute declarations because source-file
|
|
198
|
+
filtering is not applied yet.
|
|
180
199
|
|
|
181
200
|
## Real-world examples
|
|
182
201
|
|
|
@@ -186,9 +205,12 @@ The repository includes worked examples and smoke programs for:
|
|
|
186
205
|
- Cairo: [examples/cairo](examples/cairo)
|
|
187
206
|
- libpng: [examples/libpng](examples/libpng)
|
|
188
207
|
- zlib: [examples/zlib](examples/zlib)
|
|
208
|
+
- globals/constants: [examples/global_consts](examples/global_consts)
|
|
189
209
|
|
|
190
210
|
These examples do more than generate bindings: their `generate.sh` scripts also
|
|
191
|
-
build
|
|
211
|
+
build smoke artifacts or run small functional tests to check the usability of
|
|
212
|
+
the generated bindings. They pass `--layout-tests` explicitly when they need
|
|
213
|
+
layout-test sidecars.
|
|
192
214
|
|
|
193
215
|
The test suite also has end-to-end runtime coverage for:
|
|
194
216
|
|
|
@@ -208,15 +230,44 @@ matrix.
|
|
|
208
230
|
|
|
209
231
|
### The generated module is empty or missing declarations
|
|
210
232
|
|
|
211
|
-
`mojo-bindgen`
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
233
|
+
`mojo-bindgen` parses the primary header plus any headers listed with
|
|
234
|
+
`--public-header` through an internal umbrella header. If a thin wrapper only
|
|
235
|
+
includes another header whose declarations you care about, pass that included
|
|
236
|
+
header with `--public-header` or use it as the primary header directly. Normal
|
|
237
|
+
transitive `#include` files are also visible to Clang and may appear in output.
|
|
215
238
|
|
|
216
239
|
### Parsing fails on project headers
|
|
217
240
|
|
|
218
241
|
Most parser failures are missing include paths, target flags, or defines. Add
|
|
219
|
-
the same flags your C build uses
|
|
242
|
+
the same flags your C build uses with `-I` / `--include`, `-D` / `--define`,
|
|
243
|
+
`-U` / `--undefine`, `--target`, `--sysroot`, `--std`, or repeated
|
|
244
|
+
`--clang-arg`.
|
|
245
|
+
|
|
246
|
+
### Debugging parser failures
|
|
247
|
+
|
|
248
|
+
Print the normalized Clang arguments that `mojo-bindgen` will use:
|
|
249
|
+
|
|
250
|
+
```bash
|
|
251
|
+
mojo-bindgen include/mylib.h -I ./include --print-clang-args
|
|
252
|
+
```
|
|
253
|
+
|
|
254
|
+
Write diagnostics as JSON while still generating normal output:
|
|
255
|
+
|
|
256
|
+
```bash
|
|
257
|
+
mojo-bindgen include/mylib.h \
|
|
258
|
+
--diagnostics json \
|
|
259
|
+
--diagnostics-output diagnostics.json \
|
|
260
|
+
-o mylib_bindings.mojo
|
|
261
|
+
```
|
|
262
|
+
|
|
263
|
+
Dump the preprocessed input that Clang sees:
|
|
264
|
+
|
|
265
|
+
```bash
|
|
266
|
+
mojo-bindgen include/mylib.h \
|
|
267
|
+
-I ./include \
|
|
268
|
+
--dump-preprocessed mylib.preprocessed.c \
|
|
269
|
+
-o mylib_bindings.mojo
|
|
270
|
+
```
|
|
220
271
|
|
|
221
272
|
### Build succeeds but symbols are missing at runtime
|
|
222
273
|
|
|
@@ -224,7 +275,7 @@ Double-check:
|
|
|
224
275
|
|
|
225
276
|
- `--library` and `--link-name`
|
|
226
277
|
- your Mojo link flags for `external_call`
|
|
227
|
-
- your `--library-path
|
|
278
|
+
- your `--library-path` for `owned_dl_handle`
|
|
228
279
|
- whether the original C declaration involved tricky `inline` or exotic layout that needs manual review.
|
|
229
280
|
|
|
230
281
|
## License
|