FFI
Hi,
I'm working on FFI and I've got two small questions :
1 - what is the equivalent of size_t in Mojo ?
2 - Dynamic linking is easy but I haven't found a way to proceed with a static library (.a file). Is there a clean and official way to do that ?
Thanks.
14 Replies
I think size_t equivalent is Int (or maybe UInt?) which is the size of the pointer in your machine.
thanks. It should be UInt since size_t is supposed to be unsigned
UInt was only recently introduced, so maybe it's not as complete as Int.
yeah, I've start to feel the pain with this. I've found nothing to convert to/from Int and even a basic & doesn't seems to exist 😋
Guess, it will be Int for now
I'm working on improving UInt but feel free to send PRs! It's pretty easy to get started with the stdlib 🙂
It's basically mapping those operations: https://mlir.llvm.org/docs/Dialects/IndexOps/ to dunder methods, while being careful to use the unsigned operations whenever available
'index' Dialect - MLIR
Multi-Level IR Compiler Framework
Hi @FSaez static linking isn't officialy supported yet, there is a hacky way to do it here until we add it though: https://github.com/ihnorton/mojo-ffi/tree/ffi-demo/mojo-exe-link-c-static
GitHub
mojo-ffi/mojo-exe-link-c-static at ffi-demo · ihnorton/mojo-ffi
Contribute to ihnorton/mojo-ffi development by creating an account on GitHub.
For
size_t
for our interop we've used Int
for that in the stdlib, but UInt
is more correct I haven't personally tried it yet with interop thoughthanks. I've already found this and it's why I've asked for a "clean and official" way 😋
Congrats @FSaez, you just advanced to level 1!
thanks. I'm "plumbing" Mojo with the libjpeg and I'll dive into MLIR after that
another question but I guess I know the answer. Any plan for LTO/PGO/BOLT ? BOLT could be the easier to enable as it usually rely on a LDFLAGS.
LTO is already done at the MLIR level, for the other two this was a comment from an engineer:
thanks.
BOLT doesn't work, at least on my setup, that's why I've asked.
I've got this error :
It's usually solved with something like "-Wl,--emit-relocs" in the LDFLAGS.
but it's no big deal, really.
Cool thanks for letting me know, there's interest on this internally, will let you know if someone gets it working