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

Musl cross compiling example can't build cross-platform #2843

Closed
UebelAndre opened this issue Sep 6, 2024 · 4 comments
Closed

Musl cross compiling example can't build cross-platform #2843

UebelAndre opened this issue Sep 6, 2024 · 4 comments

Comments

@UebelAndre
Copy link
Collaborator

While working on #2841 I noticed that I was unable to produce a crate_universe output that worked on both Linux and MacOS for the musl-cross_compiling example. On MacOS, I generated the following diff to the lock file.

diff --git a/examples/musl_cross_compiling/Cargo.Bazel.lock.json b/examples/musl_cross_compiling/Cargo.Bazel.lock.json
index 5c3474a8..e9227b46 100644
--- a/examples/musl_cross_compiling/Cargo.Bazel.lock.json
+++ b/examples/musl_cross_compiling/Cargo.Bazel.lock.json
@@ -1,5 +1,5 @@
 {
-  "checksum": "fc8d0cce009897974859e6a3690ba7dade4f6ad225670f87eafb72a9c14632b2",
+  "checksum": "012c077f40c6def2a7ba6a1f1a8235c5b9adb0beaee7b2486697fec8e2c58f2e",
   "crates": {
     "aes 0.8.4": {
       "name": "aes",
@@ -4625,7 +4625,7 @@
         {
           "Library": {
             "crate_name": "musl_cross_compiling",
-            "crate_root": "../../../../../../dev/null",
+            "crate_root": "../../../../../../../../dev/null",
             "srcs": {
               "allow_empty": true,
               "include": [

However, this fails CI with

ERROR: An error occurred during the fetch of repository 'cu':
   Traceback (most recent call last):
	File "/var/lib/buildkite-agent/.cache/bazel/_bazel_buildkite-agent/4521dda2175db4332f201db7aa8123f5/external/rules_rust/crate_universe/private/crates_repository.bzl", line 45, column 28, in _crates_repository_impl
		repin = determine_repin(
	File "/var/lib/buildkite-agent/.cache/bazel/_bazel_buildkite-agent/4521dda2175db4332f201db7aa8123f5/external/rules_rust/crate_universe/private/generate_utils.bzl", line 422, column 13, in determine_repin
		fail(msg)
Error in fail: Error: Digests do not match: Current Digest("012c077f40c6def2a7ba6a1f1a8235c5b9adb0beaee7b2486697fec8e2c58f2e") != Expected Digest("e5e2509cc5dbd6ae948c2c9260f6cc04d60cbcc9b1ace79e80c841983de3556a")
The current `lockfile` is out of date for 'cu'. Please re-run bazel using `CARGO_BAZEL_REPIN=true` if this is expected and the lockfile should be updated.
ERROR: no such package '@@cu//': Error: Digests do not match: Current Digest("012c077f40c6def2a7ba6a1f1a8235c5b9adb0beaee7b2486697fec8e2c58f2e") != Expected Digest("e5e2509cc5dbd6ae948c2c9260f6cc04d60cbcc9b1ace79e80c841983de3556a")
The current `lockfile` is out of date for 'cu'. Please re-run bazel using `CARGO_BAZEL_REPIN=true` if this is expected and the lockfile should be updated.

When enabling CARGO_BAZEL_DEBUG I can see a difference between the outputs on MacOS vs Linux

--- macos.log	2024-09-06 11:49:20
+++ linux.log	2024-09-06 11:49:09
@@ -1,7 +1,7 @@
 Query DEBUG cargo_bazel::lockfile: cargo-bazel version hash: ef009193262ad048e8890de3f6c4c66f8f26584396e9b6f544894b337ab951ce
-Query DEBUG cargo_bazel::lockfile: lockfile context hash: b1f6708c723a384ff6c57202fd845f7155bac978a83216999c465c346d0b9010
+Query DEBUG cargo_bazel::lockfile: lockfile context hash: de05fe88c0a9d32ae90936e16ecb1f23ee22b0b0d0aaa06cc4d045c72a5b2570
 Query DEBUG cargo_bazel::lockfile: workspace config hash: cb23d5c520f46a52d4eafdbb886b34c5b49dbe161d69fd7274c40d96677e4968
 Query DEBUG cargo_bazel::lockfile: splicing manifest hash: 70a890c01bcd729ab8a9b456562da0c45d83ac6c4064366a563c14793fe301c6
-Query DEBUG cargo_bazel::lockfile: Cargo version hash: 8520bbc057b3e7174845066f361879e5e75abb81f9e41dcb63d6be39dad482b5
-Query DEBUG cargo_bazel::lockfile: Rustc version hash: 4a88d82bb95e896d4afa722e04ca05dabee5ec69f52722b038e8d8880ef2462c
-Query DEBUG cargo_bazel::lockfile: Digest hash: 012c077f40c6def2a7ba6a1f1a8235c5b9adb0beaee7b2486697fec8e2c58f2e
+Query DEBUG cargo_bazel::lockfile: Cargo version hash: 56a097b157ad136a3e188cdf46a07188e79b59ad7c279058015c00d6c2d95100
+Query DEBUG cargo_bazel::lockfile: Rustc version hash: a80571782099c29396b91f5eee1a2f6733618054b0a07ad7c066c7801400df38
+Query DEBUG cargo_bazel::lockfile: Digest hash: 43c81042a860df9293da9de1b4f3eae93ff5367ca1b0eef59ade1cdd65aedbf2

We should understand this issue.

@UebelAndre
Copy link
Collaborator Author

UebelAndre commented Sep 6, 2024

I wonder if this is related to #2775

cc @illicitonion

@marvin-hansen
Copy link
Contributor

I ran full tilt into this issue while porting the MUSL example from WORKSPACE to Bazelmod.
Same error related to lockfile.

Repro:
https://github.com/marvin-hansen/rules_rust_fork/tree/bzlmod-musl/examples/bzlmod/musl_hello_world

Furthermore, another example I made today that is a bit more complex than hello world also fails to cross compile.

Repro:
https://github.com/marvin-hansen/rules_rust_fork/tree/bzlmod-musl/examples/bzlmod/musl_scratch

@illicitonion
Copy link
Collaborator

It looks like there are two differences:

  1. We're currently using /dev/null as a placeholder fake source file in a few Cargo.toml files. We shouldn't. We should use a package-relative path like fake.rs as we do elsewhere. Otherwise the lockfile is sensitive to how deep in your filesystem your git clone is. Use fake.rs not /dev/null as fake source file #2851 fixes this.
  2. It looks from your log like cargo and rustc are giving different --version outputs, which reminds me of
    // TODO: There is a bug in the linux binary for Cargo 1.60.0 where
    // the commit hash reported by the version is shorter than what's
    // reported on other platforms. This conditional here is a hack to
    // correct for this difference and ensure lockfile hashes can be
    // computed consistently. If a new binary is released then this
    // condition should be removed
    // https://github.com/rust-lang/cargo/issues/10547
    let corrections = BTreeMap::from([
    (
    "cargo 1.60.0 (d1fd9fe 2022-03-01)",
    "cargo 1.60.0 (d1fd9fe2c 2022-03-01)",
    ),
    (
    "cargo 1.61.0 (a028ae4 2022-04-29)",
    "cargo 1.61.0 (a028ae42f 2022-04-29)",
    ),
    ]);
    - I manually ran cargo --version and rustc --version on macOS and Linux for 1.81.0 and they were identical... Can you try debugging that on your end?

@illicitonion
Copy link
Collaborator

Fixed in #2841 :)

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

No branches or pull requests

3 participants