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

bazel_7: 7.4.0 -> 7.4.1 #355723

Merged
merged 4 commits into from
Nov 17, 2024
Merged

bazel_7: 7.4.0 -> 7.4.1 #355723

merged 4 commits into from
Nov 17, 2024

Conversation

boltzmannrain
Copy link
Contributor

@boltzmannrain boltzmannrain commented Nov 13, 2024

Things done

  • Built on platform(s)
    • x86_64-linux
    • aarch64-linux
    • x86_64-darwin
    • aarch64-darwin
  • For non-Linux: Is sandboxing enabled in nix.conf? (See Nix manual)
    • sandbox = relaxed
    • sandbox = true
  • Tested, as applicable:
  • Tested compilation of all packages that depend on this change using nix-shell -p nixpkgs-review --run "nixpkgs-review rev HEAD". Note: all changes have to be committed, also see nixpkgs-review usage
  • Tested basic functionality of all binary files (usually in ./result/bin/)
  • 24.11 Release Notes (or backporting 23.11 and 24.05 Release notes)
    • (Package updates) Added a release notes entry if the change is major or breaking
    • (Module updates) Added a release notes entry if the change is significant
    • (Module addition) Added a release notes entry if adding a new NixOS module
  • Fits CONTRIBUTING.md.

Add a 👍 reaction to pull requests you find important.

@boltzmannrain
Copy link
Contributor Author

@ofborg build bazel_7

@boltzmannrain boltzmannrain mentioned this pull request Nov 13, 2024
13 tasks
@boltzmannrain
Copy link
Contributor Author

@ofborg build bazel_7

@boltzmannrain boltzmannrain marked this pull request as ready for review November 13, 2024 22:29
@nix-owners nix-owners bot requested a review from Profpatsch November 13, 2024 22:30
@FlyingWombat
Copy link
Contributor

FlyingWombat commented Nov 14, 2024

build fails at patchPhase.

bazel> Running phase: unpackPhase
bazel> unpacking source archive /nix/store/9dh7hw9x3jw35s0xjb2zinlkh3ckr0yw-bazel-7.4.1-dist.zip
...
bazel> applying patch /nix/store/9857sd4kzzpl1xcx81hwh98ldma58ya3-nix-hacks.patch
...
bazel> patching file src/main/java/com/google/devtools/build/lib/rules/repository/RepositoryDelegatorFunction.java
bazel> Hunk #1 FAILED at 178.
bazel> Hunk #2 succeeded at 634 (offset 24 lines).
bazel> 1 out of 2 hunks FAILED -- saving rejects to file src/main/java/com/google/devtools/build/lib/rules/repository/RepositoryDelegatorFunction.java.rej

based on nixos-unstable-small 18979df

@boltzmannrain
Copy link
Contributor Author

Looks like build with enableNixHacks=true was broken on 7.3.1 update too, and there's no test on bazel_7 itself that checks that. The only package using buildBazelPackage with bazel = bazel_7 seems to be fcitx5-mozc.

So that's indeed a regression but small-scale. Patch needs to be updated, originally the conflicting part about markers seems to be coming from #186106 Not yet sure what's it should do and how to do it on latest bazel codebase, will try to have a look

@boltzmannrain
Copy link
Contributor Author

And looks like the marker hack is required for buildBazelPackage to work, removing that patch yields

error: builder for '/nix/store/rbjk3i01a5np4zi3s21w138agwrgn2ff-fcitx5-mozc-2.30.5544.102.drv' failed with exit code 1;
       last 10 log lines:
       >   /build/source/src/WORKSPACE.bazel:44:13: in <toplevel>
       > Repository rule http_archive defined at:
       >   /build/output/external/bazel_tools/tools/build_defs/repo/http.bzl:387:31: in <toplevel>
       > ERROR: /build/output/external/bazel_tools/tools/build_defs/repo/http.bzl:136:45: An error occurred during the fetch of repository 'bazel_skylib':
       >    Traceback (most recent call last):
       >     File "/build/output/external/bazel_tools/tools/build_defs/repo/http.bzl", line 136, column 45, in _http_archive_impl
       >           download_info = ctx.download_and_extract(
       > Error in download_and_extract: java.io.IOException: Error downloading [https://mirror.bazel.build/github.com/bazelbuild/bazel-skylib/releases/download/1.4.1/bazel-skylib-1.4.1.tar.gz, https://github.com/bazelbuild/bazel-skylib/releases/download/1.4.1/bazel-skylib-1.4.1.tar.gz] to /build/output/external/bazel_skylib/temp15662579802079223249/bazel-skylib-1.4.1.tar.gz: Unknown host: github.com
       > ERROR: Error computing the main repository mapping: no such package '@@bazel_skylib//': java.io.IOException: Error downloading [https://mirror.bazel.build/github.com/bazelbuild/bazel-skylib/releases/download/1.4.1/bazel-skylib-1.4.1.tar.gz, https://github.com/bazelbuild/bazel-skylib/releases/download/1.4.1/bazel-skylib-1.4.1.tar.gz] to /build/output/external/bazel_skylib/temp15662579802079223249/bazel-skylib-1.4.1.tar.gz: Unknown host: github.com
       > 
       For full logs, run 'nix-store -l /nix/store/rbjk3i01a5np4zi3s21w138agwrgn2ff-fcitx5-mozc-2.30.5544.102.drv'.

@boltzmannrain
Copy link
Contributor Author

But if we also remove removal of .marker files from buildBazelPackage deps outputs it seems to be building fcitx5-mozc
boltzmannrain@14d715d on this commit build succeeded, maybe we don't need that hack anymore?

@RossComputerGuy
Copy link
Member

This is preventing me from upgrading my systems to the NixOS 24.11 pre-release. I'll review this and backport it.

@RossComputerGuy RossComputerGuy added the backport staging-24.11 Backport PR automatically label Nov 14, 2024
@RossComputerGuy
Copy link
Member

Result of nixpkgs-review pr 355723 run on aarch64-linux 1

2 packages failed to build:
  • fcitx5-mozc
  • fcitx5-mozc-ut
1 package built:
  • bazel_7

@boltzmannrain
Copy link
Contributor Author

This PR itself doesn't fix fcitx5-mozc build (buildBazelBackage with bazel=bazel-7), I don't yet fully understand the patch used there to update it.

Found a little more background on the markers hack here #65374

It seems that removing a section of failing patch + some more changes may work for fcitx5-mozc as in boltzmannrain@14d715d#diff-fd4e3dd34e0c6b6d8da7ac1dc25530696d40844760fd3aebf103e2444c55c6a8R163

But I don't know if that change to buildBazelPackage setup works for other packages, maybe for bazel 5/6 we should keep existing behavior of removing markers to be on the safe side (building tensorflow might be a good test)

Additionally if we decide to change buildBazelPackage behavior it probably makes sense to invalidate fixed output derivations, similarly how they get invalidated on bazel version changes in
https://github.com/NixOS/nixpkgs/blob/master/pkgs/build-support/build-bazel-package/default.nix#L219

@musjj
Copy link
Contributor

musjj commented Nov 14, 2024

This PR itself doesn't fix fcitx5-mozc build

Yeah, it looks like the problem is the patch from buildBazelPackage. It's just patch failure, so you just need to adjust and create a separate patch for 7.x.x, but I guess you also need to add a version check to make sure the right patch gets applied to the right bazel version.

Copy link
Contributor

@musjj musjj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you try this patch:

nix-hacks-7.patch
diff --git a/src/main/java/com/google/devtools/build/lib/rules/repository/RepositoryDelegatorFunction.java b/src/main/java/com/google/devtools/build/lib/rules/repository/RepositoryDelegatorFunction.java
index 53e6494..09052cd 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/repository/RepositoryDelegatorFunction.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/repository/RepositoryDelegatorFunction.java
@@ -55,6 +55,7 @@ import com.google.devtools.build.skyframe.SkyFunctionException.Transience;
 import com.google.devtools.build.skyframe.SkyKey;
 import com.google.devtools.build.skyframe.SkyValue;
 import java.io.IOException;
+import java.util.Collections;
 import java.util.Map;
 import java.util.Optional;
 import java.util.TreeMap;
@@ -193,18 +194,8 @@ public final class RepositoryDelegatorFunction implements SkyFunction {
       }
 
       if (shouldUseCachedRepos(env, handler, repoRoot, rule)) {
-        // Make sure marker file is up-to-date; correctly describes the current repository state
-        byte[] markerHash = digestWriter.areRepositoryAndMarkerFileConsistent(handler, env);
-        if (env.valuesMissing()) {
-          return null;
-        }
-        if (markerHash != null) { // repo exist & up-to-date
-          return RepositoryDirectoryValue.builder()
-              .setPath(repoRoot)
-              .setDigest(markerHash)
-              .setExcludeFromVendoring(excludeRepoFromVendoring)
-              .build();
-        }
+        // Nix hack: Always consider cached dirs as up-to-date
+        return RepositoryDirectoryValue.builder().setPath(repoRoot).setDigest(digestWriter.writeMarkerFile(Collections.emptyMap())).build();
       }
 
       /* At this point: This is a force fetch, a local repository, OR The repository cache is old or
@@ -634,11 +625,12 @@ public final class RepositoryDelegatorFunction implements SkyFunction {
         builder.append(escape(key)).append(" ").append(escape(value)).append("\n");
       }
       String content = builder.toString();
-      try {
-        FileSystemUtils.writeContent(markerPath, UTF_8, content);
-      } catch (IOException e) {
-        throw new RepositoryFunctionException(e, Transience.TRANSIENT);
-      }
+      // Nix hack: Do not write these pesky marker files
+      //try {
+      //  FileSystemUtils.writeContent(markerPath, UTF_8, content);
+      //} catch (IOException e) {
+      //  throw new RepositoryFunctionException(e, Transience.TRANSIENT);
+      //}
       return new Fingerprint().addString(content).digestAndReset();
     }
 
diff --git a/src/main/java/com/google/devtools/build/lib/shell/JavaSubprocessFactory.java b/src/main/java/com/google/devtools/build/lib/shell/JavaSubprocessFactory.java
index 649647c..64d05b5 100644
--- a/src/main/java/com/google/devtools/build/lib/shell/JavaSubprocessFactory.java
+++ b/src/main/java/com/google/devtools/build/lib/shell/JavaSubprocessFactory.java
@@ -165,7 +165,6 @@ public class JavaSubprocessFactory implements SubprocessFactory {
     }
     builder.command(argv);
     if (params.getEnv() != null) {
-      builder.environment().clear();
       builder.environment().putAll(params.getEnv());
     }

You can conditionally import it just for 7.x.x like this:

# See enableNixHacks argument above.
++ lib.optional enableNixHacks (
  if versionAtLeast version "7" then ./nix-hacks-7.patch else ./nix-hacks.patch
);

I'm not really sure if the Collections.emptyMap() hack here have any serious implications, but fcitx5 does build now.

The problem was that we need to get the recorded inputs via readMarkerFile and markerPath now, but they're both private. Maybe we could patch areRepositoryAndMarkerFileConsistent to make sure it always succeeds, but I'm not sure if it'd have any unwanted side effects.

@RossComputerGuy
Copy link
Member

Please don't use substring to check versions, we have lib.versionAtLeast and lib.versionOlder.

@FlyingWombat
Copy link
Contributor

Do we still need the patch? fcit5-mozc is the only package explicitly depending on bazel_7, and the build succeeds with this commit that removes the patch and .marker file removal. boltzmannrain@14d715d

We could try migrating other packages to bazel_7 to see if it works, but they might break on bazel_7 regardless.

@musjj
Copy link
Contributor

musjj commented Nov 15, 2024

Do we still need the patch?

I'm not really sure either, but I've had experiences where bazel builds ok once, but fails in subsequent builds (due to hash changes). The PR you linked seems to imply that.

Can you try clearing your cache and rebuilding it to see if it works?

fcit5-mozc is the only package explicitly depending on bazel_7

Yes for now. fcitx5-mozc doesn't actually need bazel 7 right now, but it will be a hard requirement for both fcitx5-mozc and mozc on the next version bump (because it uses local.bzl).

@musjj musjj mentioned this pull request Nov 16, 2024
13 tasks
@boltzmannrain boltzmannrain mentioned this pull request Nov 16, 2024
13 tasks
boltzmannrain added a commit to boltzmannrain/nixpkgs that referenced this pull request Nov 16, 2024
`bazel_7` upgrade to 7.3.1+ had a regression breaking `buildBazelPackage { bazel = bazel_7; }`.
See some discussion in NixOS#355723

`fcitx5-mozc` package should be currently buildable with bazel 6
NixOS#355723 (comment)
Hopefully by the time it requires 7+ `buildBazelPackage` will be fixed

So let's downgrade bazel for now to 6.x for this package to unblock the 24.11 release

Should fix NixOS#355852
@boltzmannrain
Copy link
Contributor Author

Can you try this patch:
nix-hacks-7.patch

You can conditionally import it just for 7.x.x like this:

# See enableNixHacks argument above.
++ lib.optional enableNixHacks (
  if versionAtLeast version "7" then ./nix-hacks-7.patch else ./nix-hacks.patch
);

I'm not really sure if the Collections.emptyMap() hack here have any serious implications, but fcitx5 does build now.

The problem was that we need to get the recorded inputs via readMarkerFile and markerPath now, but they're both private. Maybe we could patch areRepositoryAndMarkerFileConsistent to make sure it always succeeds, but I'm not sure if it'd have any unwanted side effects.

Collections.emptyMap() version applies & compiles for me, I'm too unsure if there any implications.
Since for now it's only one package (within nixpkgs at least) regressions are yet to be discovered.

It feels safer though to use bazel_6 for fcitx5-mozc, created a PR here #356590
But also updating the hash in this PR, once one of PRs is merged the other will need to rebase and fix conflicts

For bazel_7&buildBazelPackage see following items to be improved

  • investigate whether nix-hacks.patch is still needed and whether current version is good enough
  • add some tests under bazel_7.passthru.tests
  • make sure buildBazelPackage is covered by tests too, ideally ("ofborg build bazel_7" or PR with "bazel_7: ..." title should trigger them)
  • in buildBazelPackage use same bazel with hacks for fetchAttrs deps build and for package build, seems odd that currently fetchAttrs uses bazel without enableNixHacks

@boltzmannrain boltzmannrain requested a review from musjj November 17, 2024 11:53
Comment on lines +23 to +31
+ {
+ // Nix hack: Always consider cached dirs as up-to-date
return RepositoryDirectoryValue.builder()
.setPath(repoRoot)
- .setDigest(markerHash)
- .setExcludeFromVendoring(shouldExcludeRepoFromVendoring(handler, rule))
- .build();
- }
+ // Nix hack: Always consider cached dirs as up-to-date
+ return RepositoryDirectoryValue.builder().setPath(repoRoot).setDigest(digestWriter.writeMarkerFile()).build();
}

/* At this point: This is a force fetch, a local repository, OR The repository cache is old or
@@ -610,11 +600,12 @@ public final class RepositoryDelegatorFunction implements SkyFunction {
builder.append(escape(key)).append(" ").append(escape(value)).append("\n");
- .setExcludeFromVendoring(excludeRepoFromVendoring)
+ .setDigest(digestWriter.writeMarkerFile(Collections.emptyMap()))
.build();
}
Copy link
Contributor

@musjj musjj Nov 17, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have you tested if the patch works? It seems to generate an extra scope:

if (shouldUseCachedRepos(env, handler, repoRoot, rule)) {
  {
    // Nix hack: Always consider cached dirs as up-to-date
    return RepositoryDirectoryValue.builder()
        .setPath(repoRoot)
        .setDigest(digestWriter.writeMarkerFile(Collections.emptyMap()))
        .build();
  }
}

Does this actually return from the function or just from the scope (not really familiar with Java)?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Extra nested block creates a nested lexical scope but return still refers to the enclosing function as there's no block-level returns. Added it to reduce formatting indentation diff against bazel upstream

Copy link
Contributor

@musjj musjj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok LGTM. It should be fine to downgrade bazel for fcitx5-mozc for now.

@philiptaron

This comment was marked as outdated.

@philiptaron
Copy link
Contributor

nixpkgs-review result

Generated using nixpkgs-review.

Command: nixpkgs-review pr 355723


x86_64-linux

✅ 1 package built:
  • bazel_7

@philiptaron philiptaron merged commit 6c33d76 into NixOS:master Nov 17, 2024
10 of 11 checks passed
Copy link
Contributor

Successfully created backport PR for staging-24.11:

@olebedev olebedev removed their request for review November 18, 2024 09:21
paschoal pushed a commit to paschoal/nixpkgs that referenced this pull request Nov 22, 2024
`bazel_7` upgrade to 7.3.1+ had a regression breaking `buildBazelPackage { bazel = bazel_7; }`.
See some discussion in NixOS#355723

`fcitx5-mozc` package should be currently buildable with bazel 6
NixOS#355723 (comment)
Hopefully by the time it requires 7+ `buildBazelPackage` will be fixed

So let's downgrade bazel for now to 6.x for this package to unblock the 24.11 release

Should fix NixOS#355852
github-actions bot pushed a commit that referenced this pull request Nov 25, 2024
`bazel_7` upgrade to 7.3.1+ had a regression breaking `buildBazelPackage { bazel = bazel_7; }`.
See some discussion in #355723

`fcitx5-mozc` package should be currently buildable with bazel 6
#355723 (comment)
Hopefully by the time it requires 7+ `buildBazelPackage` will be fixed

So let's downgrade bazel for now to 6.x for this package to unblock the 24.11 release

Should fix #355852

(cherry picked from commit 186054d)
CHN-beta pushed a commit to CHN-beta/nixpkgs that referenced this pull request Nov 25, 2024
`bazel_7` upgrade to 7.3.1+ had a regression breaking `buildBazelPackage { bazel = bazel_7; }`.
See some discussion in NixOS#355723

`fcitx5-mozc` package should be currently buildable with bazel 6
NixOS#355723 (comment)
Hopefully by the time it requires 7+ `buildBazelPackage` will be fixed

So let's downgrade bazel for now to 6.x for this package to unblock the 24.11 release

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

Successfully merging this pull request may close these issues.

5 participants