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 can't build offline #606

Closed
0xngold opened this issue Mar 16, 2021 · 7 comments
Closed

Crate can't build offline #606

0xngold opened this issue Mar 16, 2021 · 7 comments

Comments

@0xngold
Copy link

0xngold commented Mar 16, 2021

Summary

Expected behavior: windows-rs builds successfully offline with a local-registry
Actual behavior: windows-rs build fails with a cryptic error message

It seems there are three sub-bugs here:

  • cargo metadata doesn't work offline, even if windows-rs was supplying --offline (see cargo metadata --offline requires Internet access rust-lang/cargo#9273).
  • windows-rs discards the errors from the cargo metadata invocation. This makes debugging tricky.
  • Given that cargo metadata doesn't currently work offline, is there another place we can get this workspace_root from?

Details

Error example

error: proc macro panicked
 --> C:\Users\some_user\.cargo\registry\src\-b20c50870c528e96\windows-0.3.1\build.rs:2:5
2 |     windows_macros::build!();
  |     ^^^^^^^^^^^^^^^^^^^^^^^^^

  = help: message: Cargo metadata \\?\C:\src\.rustup\toolchains\stable-x86_64-pc-windows-msvc\bin\cargo.exe did not contain `workspace_root` key. Got stdout . Got stderr     
          Updating crates.io index
          warning: spurious network error (2 tries remaining): failed to send request: The server name or address could not be resolved
          ; class=Os (2)
          warning: spurious network error (1 tries remaining): failed to send request: The server name or address could not be resolved
          ; class=Os (2)
          error: failed to get `const-sha1` as a dependency of package `windows v0.3.1 (C:\Users\some_user\.cargo\registry\src\-b20c50870c528e96\windows-0.3.1)`

          Caused by:
            failed to load source for dependency `const-sha1`

          Caused by:
            Unable to update registry `https://github.com/rust-lang/crates.io-index`

          Caused by:
            failed to fetch `https://github.com/rust-lang/crates.io-index`

          Caused by:
            failed to send request: The server name or address could not be resolved
            ; class=Os (2)

          .
   Ran from "C:\\Users\\some_user\\.cargo\\registry\\src\\-b20c50870c528e96\\windows-0.3.1"

error: aborting due to previous error

Repro steps

  1. Create a binary crate C that depends on windows-rs.
  2. Use cargo local-registry to create a local registry for C's dependencies.
  3. Try to build C with the local registry replacing crates.io. The build should fail with a cryptic error from the windows-rs build. To reproduce the error message I have above, modifying this line inside the local registry's copy of windows_winmd crate. There is almost certainly a simpler repro, but a repro shouldn't be strictly necessary to verify this bug has been fixed.
@kennykerr
Copy link
Collaborator

kennykerr commented Mar 16, 2021

Unfortunately, I'm not aware of any other way to get the workspace dir. I had hoped there would be an environment variable, as there is for OUT_DIR, CARGO_MANIFEST_DIR, and so on. Reading the result of cargo metadata is certainly not ideal, but that's all I could find.

From what I can tell, there have been attempts to add such an environment variable but it has always run into blocking issues. So it may be best to fix the offline bug in cargo metadata that you mentioned.

@rylev
Copy link
Contributor

rylev commented Mar 16, 2021

cargo metadata has an offline flag we can pass it which will not go to the network. It still has the workspace dir available.

@kennykerr
Copy link
Collaborator

@rylev the original issue mentions that the offline flag doesn't work.

@rylev
Copy link
Contributor

rylev commented Mar 16, 2021

Whoops, sorry totally missed that!

@kennykerr
Copy link
Collaborator

I did however just try running cargo metadata --format-version=1 --no-deps without an internet connection and it works fine for me using cargo 1.52.0-nightly.

@kennykerr
Copy link
Collaborator

I have added the --offline flag for good measure, but it doesn't appear to make a difference. Anyway, I don't think there's anything else I can do from my end.

@0xngold
Copy link
Author

0xngold commented Mar 22, 2021

Thanks! Version 0.5.0 fixes the issue for me (the only change there seems to be adding --format-version=1 --no-deps; previously I was on 0.3.1).

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

3 participants