Problem:
Publish a Mojo package that depends on a Rust FFI binary library, then add the Mojo package to a project and encounter a compile error, unable to find the Mojo package.
Details:
-
The binary library compiled and released by the subproject uuid-ffi based on the rust ffi implementation is libuuid_ffi, and it is completely normal to introduce this library into the subproject uuid-mojo as a dependency. The written uuid-mojo module, in src/main.mojo, is imported and used as source code, and the compilation is completely normal and as expected.
-
However, when you publish uuid-mojo as a separate mojopkg package as uuid, and then add the package to a project and then compile it, it will cause a crash during compilation and will not work properly.
Related Projects: (uuid-rs to uuid-mojo)
- Here’s a complete example project, using
uuid-rs
as the source project, binding it into an independent uuid mojo package viarust ffi
.
uuid-ffi(base on uuid-rs + rust ffi):
uuid mojo:
mojo example:
Published Pacages:
uuid ffi:
uuid mojo:
Reproduce errors:
-
This example package is small enough that only 2 sets of APIs are exported, and the implementation is very simple.
-
Anyone, based on the code I’ve provided, can easily reproduce the compile-time error (when imported as a standalone mojo package).
-
Taskfile.yml
has a full build script in it, feel free to ask me if you need any further information. I’ll keep an eye on how this issue progresses.
error logs:
packages/uuid-mojo/examples on main on ☁️
❯ ls
try-uuid try_uuid.mojo uuid.mojopkg
packages/uuid-mojo/examples on main on ☁️
❯ magic run mojo run try_uuid.mojo
Please submit a bug report to https://github.com/modular/mojo/issues and include the crash backtrace along with all the relevant source codes.
Stack dump:
0. Program arguments: /Users/dev/Documents/iSpace/better-mojo/disc/packages/uuid-mojo/.magic/envs/default/bin/mojo run try_uuid.mojo
mojo crashed!
Please file a bug report.
[88785:34351290:20250224,140458.803901:ERROR directory_reader_posix.cc:42] opendir ~/better-mojo/disc/packages/uuid-mojo/.magic/envs/default/share/max/crashdb/attachments/dc65d4f7-82ec-4c45-b4ed-c1687097c75d: No such file or directory (2)
[88785:34351289:20250224,140458.860248:WARNING crash_report_exception_handler.cc:257] UniversalExceptionRaise: (os/kern) failure (5)
❯ magic run mojo build try_uuid.mojo -o main
Please submit a bug report to https://github.com/modular/mojo/issues and include the crash backtrace along with all the relevant source codes.
Stack dump:
0. Program arguments: ~/better-mojo/disc/packages/uuid-mojo/.magic/envs/default/bin/mojo build try_uuid.mojo -o main
mojo crashed!
Please file a bug report.
[90602:34354350:20250224,140542.079822:WARNING crash_report_exception_handler.cc:257] UniversalExceptionRaise: (os/kern) failure (5)
aslo, normal case:
disc/packages/uuid-mojo on main on ☁️
❯ ls
examples magic.lock mojoproject.toml output readme.md recipes src Taskfile.yml test
disc/packages/uuid-mojo on main on ☁️
❯ magic run mojo run src/main.mojo
rust > uuid v4: 5508f795-31c9-4b37-beee-559de51fd233
rust > freeing string: "5508f795-31c9-4b37-beee-559de51fd233", raw: "5508f795-31c9-4b37-beee-559de51fd233"
rust > uuid v7: 01953691-84c3-7c61-927b-eb8e485dec64
rust > freeing string: "01953691-84c3-7c61-927b-eb8e485dec64", raw: "01953691-84c3-7c61-927b-eb8e485dec64"
rust > uuid v4: 7d50274a-c2db-41d3-ba35-4a6295f8c43a
rust > uuid v7: 01953691-84c3-7c61-927b-eb97d1b48228
5508f795-31c9-4b37-beee-559de51fd233
01953691-84c3-7c61-927b-eb8e485dec64
7d50274a-c2db-41d3-ba35-4a6295f8c43a
01953691-84c3-7c61-927b-eb97d1b48228
- example