# Rust FFI + Mojo Package: Released as an independent package using mojopkg, then importing it results in a compilation error

**URL:** <https://forum.modular.com/t/rust-ffi-mojo-package-released-as-an-independent-package-using-mojopkg-then-importing-it-results-in-a-compilation-error/632>\
**Category:** Mojo\
**Tags:** discussion, mojo-compiler, 24\_6\
**Created:** [February 24, 2025, 5:51am UTC](https://forum.modular.com/t/rust-ffi-mojo-package-released-as-an-independent-package-using-mojopkg-then-importing-it-results-in-a-compilation-error/632 "2025-02-24T05:51:57Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![henry](https://avatars.discourse-cdn.com/v4/letter/h/df705f/32.png) [@henry](https://forum.modular.com/u/henry)\
**Post date:** [February 24, 2025, 5:51am UTC](https://forum.modular.com/t/rust-ffi-mojo-package-released-as-an-independent-package-using-mojopkg-then-importing-it-results-in-a-compilation-error/632/1 "2025-02-24T05:51:58Z")

</div>

## 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:

1. 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.

2. 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 via `rust ffi`.

> uuid-ffi(base on uuid-rs + rust ffi):

> **[disc/packages/uuid-ffi at main · better-mojo/disc](https://github.com/better-mojo/disc/tree/main/packages/uuid-ffi)**
>
> mojo utils monorepo. Contribute to better-mojo/disc development by creating an account on GitHub.

> uuid mojo:

> **[disc/packages/uuid-mojo at main · better-mojo/disc](https://github.com/better-mojo/disc/tree/main/packages/uuid-mojo)**
>
> mojo utils monorepo. Contribute to better-mojo/disc development by creating an account on GitHub.

> mojo example:

> **[disc/packages/uuid-mojo/examples/try-uuid at main · better-mojo/disc](https://github.com/better-mojo/disc/tree/main/packages/uuid-mojo/examples/try-uuid)**
>
> mojo utils monorepo. Contribute to better-mojo/disc development by creating an account on GitHub.

## Published Pacages:

> uuid ffi:

- [libuuid\_ffi - better-ffi](https://prefix.dev/channels/better-ffi/packages/libuuid_ffi)

> uuid mojo:

- [uuid - better-mojo](https://prefix.dev/channels/better-mojo/packages/uuid)

## 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:

```bash

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:

```ruby

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

```

 ![image](https://us1.discourse-cdn.com/flex001/uploads/modular/original/1X/38dc67c1c0f6c029667ff32a7f2a2753f0dbfe2f.png)

- example

 ![image](https://us1.discourse-cdn.com/flex001/uploads/modular/original/1X/702b468fc336a381aaaac37b9729838b903c6ae8.png)

---

<div class="post-metadata">

**Author:** ![henry](https://avatars.discourse-cdn.com/v4/letter/h/df705f/32.png) [@henry](https://forum.modular.com/u/henry)\
**Post date:** [February 24, 2025, 5:57am UTC](https://forum.modular.com/t/rust-ffi-mojo-package-released-as-an-independent-package-using-mojopkg-then-importing-it-results-in-a-compilation-error/632/2 "2025-02-24T05:57:35Z")

</div>

## By the way:

- The `uuid-mojo` library, if used in a way that `copies the source code`, is `perfectly normal`.

- This project(uuid-mojo) gives several ways to convert the interface of Rust FFI, and welcomes more people to refer to this idea and extend more rust libraries for Mojo to use.

- Based on the Rust project [GitHub - getditto/safer\_ffi: Write safer FFI code in Rust without polluting it with unsafe code](https://github.com/getditto/safer_ffi), it’s very easy to make FFI libraries.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex001/uploads/modular/original/1X/2751e0fbdc595a99718b216730957e9db4448cfd.jpeg) [@system](https://forum.modular.com/u/system)\
**Post date:** [August 23, 2025, 5:58am UTC](https://forum.modular.com/t/rust-ffi-mojo-package-released-as-an-independent-package-using-mojopkg-then-importing-it-results-in-a-compilation-error/632/3 "2025-08-23T05:58:01Z")

</div>

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.
