denoland / deno_bindgen

Write high-level Deno FFI libraries in Rust.
MIT License
274 stars 28 forks source link

Revert non-working fix aiming to support docs.rs #104

Open vectronic opened 1 year ago

vectronic commented 1 year ago

I originally provided a PR https://github.com/denoland/deno_bindgen/pull/82 (merged) for this issue: https://github.com/denoland/deno_bindgen/issues/72

I have since discovered more about Rust compilation and procedural macros and realised my "fix" doesn't work as per this: https://github.com/rust-lang/docs.rs/issues/1823

The two issues with attempting to use OUT_DIR:

I also see that my "fix" introduced another issue which was fixed here: https://github.com/denoland/deno_bindgen/pull/89

After learning more and understanding more... I humbly submit a PR which:

On my journey, I have also discovered that the issue of procedural macros having side-effects has been discussed elsewhere: https://github.com/rust-lang/cargo/issues/9084

It would seem this issue is a general issue with using procedural macros for outputting auxiliary data and out of my league in terms of resolving.

I am not sure what the solution is, but for now I will have to put up with the fact that when my project makes use of deno_bindgen I can't refer to the generated Rust docs on docs.rs...

zifeo commented 1 year ago

@vectronic Would not it be better to keep the environment variables but having it freed from cargo system?

vectronic commented 1 year ago

@zifeo thanks for the response. The issue I have is that there doesn't seem to be anyway to specify env vars when a build (for docs) is performed on docs.rs.

The only way possibly to go down that route would be to use env vars that OPT IN to the bindings.json being produced. This would make the bindgen_macro a 'no-op' by default and things would work on docs.rs.

Then the deno_bindgen CLI could potentially spawn the cargo build with the env var set when it is desired to output bindings.json In this scenario the env-var could just be used as an 'emit' flag and output to the current project root as it does now.

This therefore creates a breaking change from the point of view of the Rust code, but a non-breaking change from the point of view of the Deno code....