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

Nix example switched to using crate_universe_dependencies(bootstrap=True) #2313

Merged
merged 1 commit into from
Dec 12, 2023

Conversation

rickvanprim
Copy link
Contributor

Seeing as #2279 is merged, this fixes the current Nix built cargo-bazel getting stale because it's not able to watch the source files. This should make for much better iteration speed as well, as the Nix built form has to do a clean build every time.

@rickvanprim rickvanprim force-pushed the cargo_bazel_bootstrap branch from 1f78b0e to cb917cf Compare December 11, 2023 01:30
Copy link
Collaborator

@illicitonion illicitonion left a comment

Choose a reason for hiding this comment

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

As discussed offline, repinning currently fails for me with a vanilla nix install with error: experimental Nix feature 'nix-command' is disabled; add '--extra-experimental-features nix-command' to enable it - let's make this script run cleanly out of the box. Otherwise LGTM!

@rickvanprim rickvanprim force-pushed the cargo_bazel_bootstrap branch 2 times, most recently from 160c895 to 327631e Compare December 11, 2023 17:55
echo "Visit https://nixos.org/download for installation instructions."
exit 1
fi
export NIX_CONFIG="$NIX_CONFIG\nexperimental-features = nix-command flakes"
Copy link
Collaborator

Choose a reason for hiding this comment

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

This fails if $NIX_CONFIG isn't set...

Just using ${NIX_CONFIG:-} doesn't work because nix doesn't appear to like a plain leading \n.

I changed it like this:

diff --git a/util/repin_all.sh b/util/repin_all.sh
index c7dba917..8fc9a0a2 100755
--- a/util/repin_all.sh
+++ b/util/repin_all.sh
@@ -10,7 +10,12 @@ if ! command -v nix &> /dev/null; then
     echo "Visit https://nixos.org/download for installation instructions."
     exit 1
 fi
-export NIX_CONFIG="$NIX_CONFIG\nexperimental-features = nix-command flakes"
+new_nix_config="experimental-features = nix-command flakes"
+if [[ -z "${NIX_CONFIG:-}" ]]; then
+  export NIX_CONFIG="${new_nix_config}"
+else
+  export NIX_CONFIG="${NIX_CONFIG}\n${new_nix_config}"
+fi
 
 # Re-generates all files which may need to be re-generated after changing crate_universe.
 bazel run //crate_universe/3rdparty:crates_vendor

but it still doesn't seem to work with me on my ARM Mac:

% util/repin_all.sh   
WARNING: Running Bazel server needs to be killed, because the startup options are different.
Starting local Bazel server and connecting to it...
INFO: Invocation ID: bd09af97-4b47-46c0-86d0-fba066034fcc
INFO: Analyzed target //crate_universe/3rdparty:crates_vendor (114 packages loaded, 351 targets configured).
INFO: Found 1 target...
Target //crate_universe/3rdparty:crates_vendor up-to-date:
  bazel-bin/crate_universe/3rdparty/crates_vendor.sh
INFO: Elapsed time: 3.890s, Critical Path: 0.01s
INFO: 1 process: 1 internal.
INFO: Build completed successfully, 1 total action
INFO: Running command line: bazel-bin/crate_universe/3rdparty/crates_vendor.sh
Loading: 0 packages loaded
Loading: 0 packages loaded
 checking cached actions
error: flake 'path:/Volumes/Source/github.com/bazelbuild/rules_rust/examples/nix_cross_compiling/nix' does not provide attribute 'packages.aarch64-darwin.bazel.rust', 'legacyPackages.aarch64-darwin.bazel.rust' or 'bazel.rust'
INFO: Repository nix_rust instantiated at:
  /Volumes/Source/github.com/bazelbuild/rules_rust/examples/nix_cross_compiling/WORKSPACE.bazel:17:17: in <toplevel>
  /Volumes/Source/github.com/bazelbuild/rules_rust/examples/nix_cross_compiling/bazel/nix_repositories.bzl:213:26: in nix_repositories
  /private/var/tmp/_bazel_dwagnerhall/ce461197ed3d17b80eddc01283ea4d6f/external/rules_nixpkgs_core/nixpkgs.bzl:876:27: in nixpkgs_flake_package
Repository rule _nixpkgs_flake_package defined at:
  /private/var/tmp/_bazel_dwagnerhall/ce461197ed3d17b80eddc01283ea4d6f/external/rules_nixpkgs_core/nixpkgs.bzl:795:41: in <toplevel>
ERROR: An error occurred during the fetch of repository 'nix_rust':
   Traceback (most recent call last):
	File "/private/var/tmp/_bazel_dwagnerhall/ce461197ed3d17b80eddc01283ea4d6f/external/rules_nixpkgs_core/nixpkgs.bzl", line 793, column 31, in _nixpkgs_flake_package_impl
		_nixpkgs_build_and_symlink(repository_ctx, [nix_path, "build"], expr_args, build_file_content)
	File "/private/var/tmp/_bazel_dwagnerhall/ce461197ed3d17b80eddc01283ea4d6f/external/rules_nixpkgs_core/nixpkgs.bzl", line 447, column 34, in _nixpkgs_build_and_symlink
		exec_result = execute_or_fail(
	File "/private/var/tmp/_bazel_dwagnerhall/ce461197ed3d17b80eddc01283ea4d6f/external/rules_nixpkgs_core/util.bzl", line 97, column 13, in execute_or_fail
		fail("""
Error in fail: 
  Cannot build Nix derivation for package '@nix_rust'.
    Command: "/nix/var/nix/profiles/default/bin/nix" "build" "path:/Volumes/Source/github.com/bazelbuild/rules_rust/examples/nix_cross_compiling/nix#bazel.rust" "--print-out-paths" "--out-link" "bazel-support/nix-out-link"
    Return code: 1
    Error output: 
      > error: flake 'path:/Volumes/Source/github.com/bazelbuild/rules_rust/examples/nix_cross_compiling/nix' does not provide attribute 'packages.aarch64-darwin.bazel.rust', 'legacyPackages.aarch64-darwin.bazel.rust' or 'bazel.rust'

ERROR: /Volumes/Source/github.com/bazelbuild/rules_rust/examples/nix_cross_compiling/WORKSPACE.bazel:17:17: fetching _nixpkgs_flake_package rule //external:nix_rust: Traceback (most recent call last):
	File "/private/var/tmp/_bazel_dwagnerhall/ce461197ed3d17b80eddc01283ea4d6f/external/rules_nixpkgs_core/nixpkgs.bzl", line 793, column 31, in _nixpkgs_flake_package_impl
		_nixpkgs_build_and_symlink(repository_ctx, [nix_path, "build"], expr_args, build_file_content)
	File "/private/var/tmp/_bazel_dwagnerhall/ce461197ed3d17b80eddc01283ea4d6f/external/rules_nixpkgs_core/nixpkgs.bzl", line 447, column 34, in _nixpkgs_build_and_symlink
		exec_result = execute_or_fail(
	File "/private/var/tmp/_bazel_dwagnerhall/ce461197ed3d17b80eddc01283ea4d6f/external/rules_nixpkgs_core/util.bzl", line 97, column 13, in execute_or_fail
		fail("""
Error in fail: 
  Cannot build Nix derivation for package '@nix_rust'.
    Command: "/nix/var/nix/profiles/default/bin/nix" "build" "path:/Volumes/Source/github.com/bazelbuild/rules_rust/examples/nix_cross_compiling/nix#bazel.rust" "--print-out-paths" "--out-link" "bazel-support/nix-out-link"
    Return code: 1
    Error output: 
      > error: flake 'path:/Volumes/Source/github.com/bazelbuild/rules_rust/examples/nix_cross_compiling/nix' does not provide attribute 'packages.aarch64-darwin.bazel.rust', 'legacyPackages.aarch64-darwin.bazel.rust' or 'bazel.rust'

ERROR: Error computing the main repository mapping: Encountered error while reading extension file 'defs.bzl': no such package '@@crate_index//': no such package '@@cargo_bazel_bootstrap//': no such package '@@nix_rust//': 
  Cannot build Nix derivation for package '@nix_rust'.
    Command: "/nix/var/nix/profiles/default/bin/nix" "build" "path:/Volumes/Source/github.com/bazelbuild/rules_rust/examples/nix_cross_compiling/nix#bazel.rust" "--print-out-paths" "--out-link" "bazel-support/nix-out-link"
    Return code: 1
    Error output: 
      > error: flake 'path:/Volumes/Source/github.com/bazelbuild/rules_rust/examples/nix_cross_compiling/nix' does not provide attribute 'packages.aarch64-darwin.bazel.rust', 'legacyPackages.aarch64-darwin.bazel.rust' or 'bazel.rust'

@rickvanprim rickvanprim force-pushed the cargo_bazel_bootstrap branch 3 times, most recently from 2f2e560 to 424411d Compare December 12, 2023 00:02
@@ -621,7 +621,7 @@
}
},
"moduleExtensions": {
"@apple_support~1.5.0//crosstool:setup.bzl%apple_cc_configure_extension": {
"@@apple_support~1.5.0//crosstool:setup.bzl%apple_cc_configure_extension": {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Having no experience with bzlmod yet, I don't know if this is expected. Presumably something to do with Bazel 7.0.0 officially getting released 6 hours ago (🥳)?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah from: https://github.com/bazelbuild/bazel/releases/tag/7.0.0

[Incompatible] All labels in Bazel error messages, log output, Build Event Protocol, etc. are now prefixed with double-at (@@) instead of single-at (@) where applicable, to properly denote that they contain canonical repo names.

@rickvanprim rickvanprim force-pushed the cargo_bazel_bootstrap branch 3 times, most recently from c91da3e to bf8893f Compare December 12, 2023 17:19
Copy link
Collaborator

@illicitonion illicitonion left a comment

Choose a reason for hiding this comment

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

LGTM, tahnks!

@illicitonion illicitonion enabled auto-merge (squash) December 12, 2023 17:24
auto-merge was automatically disabled December 12, 2023 17:40

Head branch was pushed to by a user without write access

@rickvanprim rickvanprim force-pushed the cargo_bazel_bootstrap branch from bf8893f to 948b692 Compare December 12, 2023 17:40
@rickvanprim rickvanprim force-pushed the cargo_bazel_bootstrap branch from 948b692 to 0773ade Compare December 12, 2023 17:47
@illicitonion illicitonion merged commit 3ca92dd into bazelbuild:main Dec 12, 2023
3 checks passed
@rickvanprim rickvanprim deleted the cargo_bazel_bootstrap branch December 12, 2023 17:57
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

Successfully merging this pull request may close these issues.

2 participants