lol

envoy: fix up Rust

Envoy 1.32 has added some more dependencies on rules_rust bits, so we
need to support that now.

In particular, for some reason, we always fail with a message about
needing repinning, so we repin during the IFD phase, but we need to
point rules_rust at the nixpkgs Rust toolchain, make it build the
cargo-bazel tool (because the one in nixpkgs is the wrong version), and
then clean up afterwards.

+120 -4
+54
pkgs/by-name/en/envoy/bazel_nix.BUILD.bazel
··· 1 + load("@bazel_tools//tools/sh:sh_toolchain.bzl", "sh_toolchain") 2 + load("@rules_rust//rust:toolchain.bzl", "rust_toolchain") 3 + 4 + toolchains = { 5 + "x86_64": "x86_64-unknown-linux-gnu", 6 + "aarch64": "aarch64-unknown-linux-gnu", 7 + } 8 + 9 + exports_files(["cargo", "rustdoc", "ruststd", "rustc"]) 10 + 11 + [ 12 + rust_toolchain( 13 + name = "rust_nix_" + k + "_impl", 14 + binary_ext = "", 15 + dylib_ext = ".so", 16 + exec_triple = v, 17 + cargo = ":cargo", 18 + rust_doc = ":rustdoc", 19 + rust_std = ":ruststd", 20 + rustc = ":rustc", 21 + stdlib_linkflags = ["-ldl", "-lpthread"], 22 + staticlib_ext = ".a", 23 + target_triple = v, 24 + ) 25 + for k, v in toolchains.items() 26 + ] 27 + 28 + [ 29 + toolchain( 30 + name = "rust_nix_" + k, 31 + exec_compatible_with = [ 32 + "@platforms//cpu:" + k, 33 + "@platforms//os:linux", 34 + ], 35 + target_compatible_with = [ 36 + "@platforms//cpu:" + k, 37 + "@platforms//os:linux", 38 + ], 39 + toolchain = ":rust_nix_" + k + "_impl", 40 + toolchain_type = "@rules_rust//rust:toolchain_type", 41 + ) 42 + for k in toolchains.keys() 43 + ] 44 + 45 + sh_toolchain( 46 + name = "local_sh_impl", 47 + path = "@bash@", 48 + ) 49 + 50 + toolchain( 51 + name = "local_sh", 52 + toolchain = ":local_sh_impl", 53 + toolchain_type = "@bazel_tools//tools/sh:toolchain_type", 54 + )
+48 -4
pkgs/by-name/en/envoy/package.nix
··· 5 5 buildBazelPackage, 6 6 fetchFromGitHub, 7 7 stdenv, 8 + cacert, 9 + cargo, 10 + rustc, 11 + rustPlatform, 8 12 cmake, 9 13 gn, 10 14 go, ··· 33 37 # these need to be updated for any changes to fetchAttrs 34 38 depsHash = 35 39 { 36 - x86_64-linux = ""; 37 - aarch64-linux = ""; 40 + x86_64-linux = "sha256-LkDNPFT7UUCsGPG1dMnwzdIw0lzc5+3JYDoblF5oZVk="; 41 + aarch64-linux = "sha256-DkibjmY1YND9Q2aQ41bhNdch0SKM5ghY2mjYSQfV30M="; 38 42 } 39 43 .${stdenv.system} or (throw "unsupported system ${stdenv.system}"); 40 44 in 41 - buildBazelPackage { 45 + buildBazelPackage rec { 42 46 pname = "envoy"; 43 47 inherit (srcVer) version; 44 48 bazel = bazel_6; ··· 58 62 sed -i 's,#!/usr/bin/env python3,#!${python3}/bin/python,' bazel/foreign_cc/luajit.patch 59 63 sed -i '/javabase=/d' .bazelrc 60 64 sed -i '/"-Werror"/d' bazel/envoy_internal.bzl 65 + 66 + mkdir -p bazel/nix/ 67 + substitute ${./bazel_nix.BUILD.bazel} bazel/nix/BUILD.bazel \ 68 + --subst-var-by bash "$(type -p bash)" 69 + ln -sf "${cargo}/bin/cargo" bazel/nix/cargo 70 + ln -sf "${rustc}/bin/rustc" bazel/nix/rustc 71 + ln -sf "${rustc}/bin/rustdoc" bazel/nix/rustdoc 72 + ln -sf "${rustPlatform.rustLibSrc}" bazel/nix/ruststd 73 + substituteInPlace bazel/dependency_imports.bzl \ 74 + --replace-fail 'crate_universe_dependencies()' 'crate_universe_dependencies(rust_toolchain_cargo_template="@@//bazel/nix:cargo", rust_toolchain_rustc_template="@@//bazel/nix:rustc")' \ 75 + --replace-fail 'crates_repository(' 'crates_repository(rust_toolchain_cargo_template="@@//bazel/nix:cargo", rust_toolchain_rustc_template="@@//bazel/nix:rustc",' 76 + 77 + substitute ${./rules_rust_extra.patch} bazel/nix/rules_rust_extra.patch \ 78 + --subst-var-by bash "$(type -p bash)" 79 + cat bazel/nix/rules_rust_extra.patch bazel/rules_rust.patch > bazel/nix/rules_rust.patch 80 + mv bazel/nix/rules_rust.patch bazel/rules_rust.patch 61 81 ''; 62 82 63 83 patches = [ ··· 79 99 jdk 80 100 ninja 81 101 patchelf 102 + cacert 82 103 ]; 83 104 84 105 buildInputs = [ linuxHeaders ]; 85 106 86 107 fetchAttrs = { 87 108 sha256 = depsHash; 109 + env.CARGO_BAZEL_REPIN = true; 88 110 dontUseCmakeConfigure = true; 89 111 dontUseGnConfigure = true; 112 + postPatch = '' 113 + ${postPatch} 114 + 115 + substituteInPlace bazel/dependency_imports.bzl \ 116 + --replace-fail 'crate_universe_dependencies(' 'crate_universe_dependencies(bootstrap=True, ' \ 117 + --replace-fail 'crates_repository(' 'crates_repository(generator="@@cargo_bazel_bootstrap//:cargo-bazel", ' 118 + ''; 90 119 preInstall = '' 91 120 # Strip out the path to the build location (by deleting the comment line). 92 121 find $bazelOut/external -name requirements.bzl | while read requirements; do ··· 113 142 114 143 # fix tcmalloc failure https://github.com/envoyproxy/envoy/issues/30838 115 144 sed -i '/TCMALLOC_GCC_FLAGS = \[/a"-Wno-changes-meaning",' $bazelOut/external/com_github_google_tcmalloc/tcmalloc/copts.bzl 145 + 146 + # Install repinned rules_rust lockfile 147 + cp source/extensions/dynamic_modules/sdk/rust/Cargo.Bazel.lock $bazelOut/external/Cargo.Bazel.lock 148 + 149 + # Don't save cargo_bazel_bootstrap or the crate index cache 150 + rm -rf $bazelOut/external/cargo_bazel_bootstrap $bazelOut/external/dynamic_modules_rust_sdk_crate_index/.cargo_home $bazelOut/external/dynamic_modules_rust_sdk_crate_index/splicing-output 116 151 ''; 117 152 }; 118 153 buildAttrs = { ··· 125 160 file "$execbin" | grep -q ': ELF .*, dynamically linked,' || continue 126 161 patchelf \ 127 162 --set-interpreter $(cat ${stdenv.cc}/nix-support/dynamic-linker) \ 128 - "$execbin" 163 + "$execbin" || echo "$execbin" 129 164 done 130 165 131 166 ln -s ${bazel-gazelle}/bin $bazelOut/external/bazel_gazelle_go_repository_tools/bin ··· 139 174 $bazelOut/external/com_github_luajit_luajit/build.py \ 140 175 $bazelOut/external/local_config_sh/BUILD \ 141 176 $bazelOut/external/*_pip3/BUILD.bazel 177 + 178 + # Install repinned rules_rust lockfile 179 + cp $bazelOut/external/Cargo.Bazel.lock source/extensions/dynamic_modules/sdk/rust/Cargo.Bazel.lock 142 180 ''; 143 181 installPhase = '' 144 182 install -Dm0755 bazel-bin/source/exe/envoy-static $out/bin/envoy ··· 162 200 "--java_runtime_version=local_jdk" 163 201 "--tool_java_runtime_version=local_jdk" 164 202 203 + # Force use of system Rust. 204 + "--extra_toolchains=//bazel/nix:rust_nix_aarch64,//bazel/nix:rust_nix_x86_64" 205 + 165 206 # undefined reference to 'grpc_core::*Metadata*::*Memento* 166 207 # 167 208 # During linking of the final binary, we see undefined references to grpc_core related symbols. ··· 181 222 182 223 bazelFetchFlags = [ 183 224 "--define=wasm=${wasmRuntime}" 225 + 226 + # Force use of system Rust. 227 + "--extra_toolchains=//bazel/nix:rust_nix_aarch64,//bazel/nix:rust_nix_x86_64" 184 228 185 229 # https://github.com/bazelbuild/rules_go/issues/3844 186 230 "--repo_env=GOPROXY=https://proxy.golang.org,direct"
+18
pkgs/by-name/en/envoy/rules_rust_extra.patch
··· 1 + --- crate_universe/src/metadata/cargo_tree_rustc_wrapper.sh 2 + +++ crate_universe/src/metadata/cargo_tree_rustc_wrapper.sh 3 + @@ -1,4 +1,4 @@ 4 + -#!/usr/bin/env bash 5 + +#!@bash@ 6 + # 7 + # For details, see: 8 + # `@rules_rust//crate_universe/src/metadata/cargo_tree_resolver.rs - TreeResolver::create_rustc_wrapper` 9 + 10 + --- util/process_wrapper/private/process_wrapper.sh 11 + +++ util/process_wrapper/private/process_wrapper.sh 12 + @@ -1,4 +1,4 @@ 13 + -#!/usr/bin/env bash 14 + +#!@bash@ 15 + 16 + set -euo pipefail 17 + 18 +