mozilla / cbindgen

A project for generating C bindings from Rust code
Mozilla Public License 2.0
2.29k stars 294 forks source link

Cargo expand fails on windows within deeply nested folders #903

Closed TomzBench closed 3 months ago

TomzBench commented 7 months ago

Hello,

Cargo-expand fails on windows when building the project in a deeply nested folder. I noticed this issue first on a CI for which i do not easily control the directories used, so i can't simply change my directory to work around the issue.

It seems like every build script.exe file is failing to link. Speaking in chat with somebody alluded to the fact that large link commands will some times fail. I suspect something like this is happening. Im not sure.

I created a minimum repository which reproduces the issue here.

Clone the repository into a pretty deep folder on a windows system. (For example C:\Users\tom\Git\gitlab-runners\atx-zdk\GjRA6MGh9\0\software-engineering\this\is\a\superlong\dir) and run the command cargo build --target thumbv7em-none-eabi --no-default-features --release. You will see some cargo-expand failure with error code 1104 file not found errors. And note that build_script.exe's are not found.

Run the same command in a more sensible windows directory, and the project will compile fine...

TomzBench commented 7 months ago

This workaround seems to work for me.

from: https://github.com/mozilla/cbindgen/issues/347

    let crate_dir = env::var("CARGO_MANIFEST_DIR").expect("invalid manifest dir");
    env::set_var("CARGO_EXPAND_TARGET_DIR", crate_dir.clone());

Could be a cargo expand issue perhaps, or the way cbindgen is invoking cargo-expand 🤷‍♂️

emilio commented 3 months ago

Yeah this seems unlikely to be a cbindgen bug per se, and more of a windows limitation with long command line arguments / paths...

TomzBench commented 3 months ago

Yeah this seems unlikely to be a cbindgen bug per se, and more of a windows limitation with long command line arguments / paths...

ya. I run into permutations of this in various different ways in rust/javascript ecosystems. Should windows "be better"... Of course. Will it? ...no

emilio commented 3 months ago

I don't think this is actionable on cbindgen's side unless we can somehow shorten the window paths or something... If you think there's anything we could do better here let me know and we can re-open / fix it :)