Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How can I generate bindings from proc_macros? #49

Open
pacu opened this issue Jun 4, 2024 · 5 comments
Open

How can I generate bindings from proc_macros? #49

pacu opened this issue Jun 4, 2024 · 5 comments
Labels
question Further information is requested

Comments

@pacu
Copy link

pacu commented Jun 4, 2024

I'm trying to generate go bindings for a project I'm working on, but I can't seem to be able to do so from proc_macros

According to help this would be possible

uniffi-bindgen 0.2.1+v0.25.0

USAGE:
    uniffi-bindgen-go [OPTIONS] <SOURCE>

ARGS:
    <SOURCE>    Path to the UDL file, or cdylib if `library-mode` is specified

OPTIONS:
    -c, --config <CONFIG>        Path to optional uniffi config file. This config will be merged
                                 on top of default `uniffi.toml` config in crate root. The merge
                                 recursively upserts TOML keys into the default config
        --crate <CRATE_NAME>     When `--library` is passed, only generate bindings for one crate.
                                 When `--library` is not passed, use this as the crate name instead
                                 of attempting to locate and parse Cargo.toml
    -h, --help                   Print help information
    -l, --lib-file <LIB_FILE>    Extract proc-macro metadata from a native lib (cdylib or staticlib)
                                 for this crate
        --library                Pass in a cdylib path rather than a UDL file
    -n, --no-format              Do not try to format the generated bindings
    -o, --out-dir <OUT_DIR>      Directory in which to write generated files. Default is same folder
                                 as .udl file
    -V, --version                Print version information

but when I try something like

uniffi-bindgen-go -l 'frost-uniffi-sdk/target/universal-ios/release/libfrost_uniffi_sdk.a' frost-uniffi-sdk

fails with Error: UDL file has no grand-parent folder!

how can I achieve it?

Context: this is the project I'm working on https://github.com/pacu/frost-uniffi-sdk

@arg0d
Copy link
Collaborator

arg0d commented Jun 4, 2024

I'm guessing you want to generate bindings straight from the library, without touching UDL files. In that case, you should use:

uniffi-bindgen-go --library frost-uniffi-sdk/target/universal-ios/release/libfrost_uniffi_sdk.a

The --lib-file API you are trying to use expects you to give a path UDL file, though the error is a bit cryptic :( I'm guessing your project doesn't even have a UDL file.

uniffi-bindgen-go --lib-file path/to/library.a path/to/library.udl

@pacu
Copy link
Author

pacu commented Jun 4, 2024

Thank you for your quick response @arg0d.

I'm guessing you want to generate bindings straight from the library, without touching UDL files. In that case, you should use:

Yes I'm actually generating the bindings for swift using proc macros like the docs say so https://mozilla.github.io/uniffi-rs/latest/proc_macro/index.html here using cargo swift see project

I want to achieve something similar for GoLang but I can't seem to be able to figure it out. I'm trying what you suggested

uniffi-bindgen-go --library 'frost-uniffi-sdk/target/universal-ios/
release/libfrost_uniffi_sdk.a' --out-dir .
Error: Failed to extract data from archive member `frost_uniffi_sdk-9ff18b138f383e0a.frost_uniffi_sdk.a7d54b623a26d530-cgu.0.rcgu.o`

Caused by:
    Unknown library format

I guess I could create a UDL file but I'd fancy not to.

@pacu
Copy link
Author

pacu commented Jun 4, 2024

Update:

I was able to generate the bindings from a cdylib instead.

I had to add it to my [lib] section of the Cargo.toml

[lib]
crate-type = ["lib","staticlib", "cdylib"]
name = "frost_uniffi_sdk"

then the command uniffi-bindgen-go --library 'frost-uniffi-sdk/target/debug/libfrost_uniffi_sdk.dylib' --out-dir . worked.

@arg0d
Copy link
Collaborator

arg0d commented Jun 6, 2024

--library doesn't work with a static library?

@arg0d arg0d added the question Further information is requested label Jun 6, 2024
@pacu
Copy link
Author

pacu commented Jun 7, 2024

--library doesn't work with a static library?

Apparently not

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants