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

Crate fails to build and need clarification on when OUT_DIR is or should be defined #1823

Closed
vectronic opened this issue Sep 6, 2022 · 2 comments

Comments

@vectronic
Copy link

Crate name

flowscripter_template_deno_rust_library

Build failure link

https://docs.rs/crate/flowscripter_template_deno_rust_library/1.0.9/builds/624001

Additional details

This is caused by an attempted write by a deno_bindgen macro to a read-only directory as per the info:

Most of the sandbox is a read-only file system, including the source directory of your crate and its dependencies. If your build.rs generates files that are relevant for documentation, consider writing to the cargo output directory, passed in the environment variable OUT_DIR.

Based on the above I submitted a patch to deno_bindgen which now checks for the OUT_DIR env var and uses that when outputting a bindings.json file as part of the build.

Change is here: https://github.com/denoland/deno_bindgen/pull/82/files#diff-6894d37ad1be13438ddf87f7ca5e444601fd2a3ad62196b5044885b89c0ec730R35

This change is in deno_bindgen 0.6.0 which I am now using.

However the problem still persists...

It looks like OUT_DIR is not defined when the deno_bindgen macro is run as part of the cargo doc build but I am clueless as to whether I should expect it to be set or whether I should somehow set it...?

I have followed local test procedures documented here:

https://blog.rust-lang.org/2019/09/18/upcoming-docsrs-changes.html

and by setting the OUT_DIR env var as follows:

export OUT_DIR=target
time cargo doc --no-deps

I can see the bindings.json file is written to the target folder instead of the base folder of the build which causes the error.

@Nemo157
Copy link
Member

Nemo157 commented Sep 6, 2022

OUT_DIR is configured for build scripts, not proc-macros. There is afaik no intended way for proc-macros to output anything other than the token stream they return (because of the compilation model side-effects from proc-macros are not guaranteed).

vectronic added a commit to flowscripter/template-deno-rust-library that referenced this issue Sep 7, 2022
vectronic added a commit to flowscripter/template-deno-rust-library that referenced this issue Sep 7, 2022
vectronic pushed a commit to flowscripter/template-deno-rust-library that referenced this issue Sep 7, 2022
## [1.0.10](v1.0.9...v1.0.10) (2022-09-07)

### Bug Fixes

* workaround for this rust-lang/docs.rs#1823 ([#52](#52)) ([1ef4183](1ef4183))
@vectronic
Copy link
Author

Thank you very much for your prompt reply.

Your explanation made perfect sense and led me to find this discussion:

rust-lang/cargo#9084

(It seems like I am not the only one using tooling that relies on procedural macros which output auxiliary information to the filesystem.)

Based on that discussion, I tried again with an empty build.rs and this did the trick:

https://docs.rs/crate/flowscripter_template_deno_rust_library/latest

It's a bit of a hacky workaround but I think it is the only option I have.

Again thanks.

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

No branches or pull requests

2 participants