diff options
Diffstat (limited to 'third_party/overlays/patches')
4 files changed, 152 insertions, 209 deletions
diff --git a/third_party/overlays/patches/cbtemulator-uds.patch b/third_party/overlays/patches/cbtemulator-uds.patch deleted file mode 100644 index a19255306f88..000000000000 --- a/third_party/overlays/patches/cbtemulator-uds.patch +++ /dev/null @@ -1,140 +0,0 @@ -commit 1397e10225d8c6fd079a86fccd58fb5d0f4200bc -Author: Florian Klink <flokli@flokli.de> -Date: Fri Mar 29 10:06:34 2024 +0100 - - feat(bigtable/emulator): allow listening on Unix Domain Sockets - - cbtemulator listening on unix domain sockets is much easier than trying - to allocate free TCP ports, especially if many cbtemulators are run at - the same time in integration tests. - - This adds an additional flag, address, which has priority if it's set, - rather than host:port. - - `NewServer` already takes a `laddr string`, so we simply check for it to - contain slashes, and if so, listen on unix, rather than TCP. - -diff --git a/bigtable/bttest/inmem.go b/bigtable/bttest/inmem.go -index 556abc2a85..33e4bf2667 100644 ---- a/bttest/inmem.go -+++ b/bttest/inmem.go -@@ -40,6 +40,7 @@ import ( - "math" - "math/rand" - "net" -+ "os" - "regexp" - "sort" - "strings" -@@ -106,7 +107,15 @@ type server struct { - // The Server will be listening for gRPC connections, without TLS, - // on the provided address. The resolved address is named by the Addr field. - func NewServer(laddr string, opt ...grpc.ServerOption) (*Server, error) { -- l, err := net.Listen("tcp", laddr) -+ var l net.Listener -+ var err error -+ -+ // If the address contains slashes, listen on a unix domain socket instead. -+ if strings.Contains(laddr, "/") { -+ l, err = net.Listen("unix", laddr) -+ } else { -+ l, err = net.Listen("tcp", laddr) -+ } - if err != nil { - return nil, err - } -diff --git a/bigtable/cmd/emulator/cbtemulator.go b/bigtable/cmd/emulator/cbtemulator.go -index 144c09ffb1..deaf69b717 100644 ---- a/cmd/emulator/cbtemulator.go -+++ b/cmd/emulator/cbtemulator.go -@@ -27,8 +27,9 @@ import ( - ) - - var ( -- host = flag.String("host", "localhost", "the address to bind to on the local machine") -- port = flag.Int("port", 9000, "the port number to bind to on the local machine") -+ host = flag.String("host", "localhost", "the address to bind to on the local machine") -+ port = flag.Int("port", 9000, "the port number to bind to on the local machine") -+ address = flag.String("address", "", "address:port number or unix socket path to listen on. Has priority over host/port") - ) - - const ( -@@ -42,7 +43,15 @@ func main() { - grpc.MaxRecvMsgSize(maxMsgSize), - grpc.MaxSendMsgSize(maxMsgSize), - } -- srv, err := bttest.NewServer(fmt.Sprintf("%s:%d", *host, *port), opts...) -+ -+ var laddr string -+ if *address != "" { -+ laddr = *address -+ } else { -+ laddr = fmt.Sprintf("%s:%d", *host, *port) -+ } -+ -+ srv, err := bttest.NewServer(laddr, opts...) - if err != nil { - log.Fatalf("failed to start emulator: %v", err) - } -commit ce16f843d6c93159d86b3807c6d9ff66e43aac67 -Author: Florian Klink <flokli@flokli.de> -Date: Fri Mar 29 11:53:15 2024 +0100 - - feat(bigtable): clean up unix socket on close - - Call srv.Close when receiving an interrupt, and delete the unix domain - socket in that function. - -diff --git a/bigtable/bttest/inmem.go b/bigtable/bttest/inmem.go -index 33e4bf2667..0dc96024b1 100644 ---- a/bttest/inmem.go -+++ b/bttest/inmem.go -@@ -148,6 +148,11 @@ func (s *Server) Close() { - - s.srv.Stop() - s.l.Close() -+ -+ // clean up unix socket -+ if strings.Contains(s.Addr, "/") { -+ _ = os.Remove(s.Addr) -+ } - } - - func (s *server) CreateTable(ctx context.Context, req *btapb.CreateTableRequest) (*btapb.Table, error) { -diff --git a/bigtable/cmd/emulator/cbtemulator.go b/bigtable/cmd/emulator/cbtemulator.go -index deaf69b717..5a9e8f7a8c 100644 ---- a/cmd/emulator/cbtemulator.go -+++ b/cmd/emulator/cbtemulator.go -@@ -18,9 +18,12 @@ cbtemulator launches the in-memory Cloud Bigtable server on the given address. - package main - - import ( -+ "context" - "flag" - "fmt" - "log" -+ "os" -+ "os/signal" - - "cloud.google.com/go/bigtable/bttest" - "google.golang.org/grpc" -@@ -51,11 +54,18 @@ func main() { - laddr = fmt.Sprintf("%s:%d", *host, *port) - } - -+ ctx, stop := signal.NotifyContext(context.Background(), os.Interrupt) -+ defer stop() -+ - srv, err := bttest.NewServer(laddr, opts...) - if err != nil { - log.Fatalf("failed to start emulator: %v", err) - } - - fmt.Printf("Cloud Bigtable emulator running on %s\n", srv.Addr) -- select {} -+ select { -+ case <-ctx.Done(): -+ srv.Close() -+ stop() -+ } - } diff --git a/third_party/overlays/patches/crate2nix-0001-Fix-Use-mkDerivation-with-src-instead-of-runCommand.patch b/third_party/overlays/patches/crate2nix-0001-Fix-Use-mkDerivation-with-src-instead-of-runCommand.patch new file mode 100644 index 000000000000..fbc18860ac81 --- /dev/null +++ b/third_party/overlays/patches/crate2nix-0001-Fix-Use-mkDerivation-with-src-instead-of-runCommand.patch @@ -0,0 +1,109 @@ +From 96f66ec32e003c6c215aa2a644281289a71dae7d Mon Sep 17 00:00:00 2001 +From: Ilan Joselevich <personal@ilanjoselevich.com> +Date: Sun, 4 Aug 2024 02:35:27 +0300 +Subject: [PATCH] Fix: Use mkDerivation with src instead of runCommand for test + derivation + +The problem with using runCommand and recreating the src directory with +lndir is that it changes the file types of individual files, they will +now be a symlink instead of a regular file. If you have a crate that tests +that a file is of regular type then it will fail inside the crate2nix derivation. +--- + templates/nix/crate2nix/default.nix | 81 ++++++++----------- + 1 file changed, 35 insertions(+), 46 deletions(-) + +diff --git a/templates/nix/crate2nix/default.nix b/templates/nix/crate2nix/default.nix +index c53925e..90e10c6 100644 +--- a/templates/nix/crate2nix/default.nix ++++ b/templates/nix/crate2nix/default.nix +@@ -120,52 +120,41 @@ rec { + testPostRun + ]); + in +- pkgs.runCommand "run-tests-${testCrate.name}" +- { +- inherit testCrateFlags; +- buildInputs = testInputs; +- } '' +- set -e +- +- export RUST_BACKTRACE=1 +- +- # recreate a file hierarchy as when running tests with cargo +- +- # the source for test data +- # It's necessary to locate the source in $NIX_BUILD_TOP/source/ +- # instead of $NIX_BUILD_TOP/ +- # because we compiled those test binaries in the former and not the latter. +- # So all paths will expect source tree to be there and not in the build top directly. +- # For example: $NIX_BUILD_TOP := /build in general, if you ask yourself. +- # NOTE: There could be edge cases if `crate.sourceRoot` does exist but +- # it's very hard to reason about them. +- # Open a bug if you run into this! +- mkdir -p source/ +- cd source/ +- +- ${pkgs.buildPackages.xorg.lndir}/bin/lndir ${crate.src} +- +- # build outputs +- testRoot=target/debug +- mkdir -p $testRoot +- +- # executables of the crate +- # we copy to prevent std::env::current_exe() to resolve to a store location +- for i in ${crate}/bin/*; do +- cp "$i" "$testRoot" +- done +- chmod +w -R . +- +- # test harness executables are suffixed with a hash, like cargo does +- # this allows to prevent name collision with the main +- # executables of the crate +- hash=$(basename $out) +- for file in ${drv}/tests/*; do +- f=$testRoot/$(basename $file)-$hash +- cp $file $f +- ${testCommand} +- done +- ''; ++ pkgs.stdenvNoCC.mkDerivation { ++ name = "run-tests-${testCrate.name}"; ++ ++ inherit (crate) src; ++ ++ inherit testCrateFlags; ++ ++ buildInputs = testInputs; ++ ++ buildPhase = '' ++ set -e ++ export RUST_BACKTRACE=1 ++ ++ # build outputs ++ testRoot=target/debug ++ mkdir -p $testRoot ++ ++ # executables of the crate ++ # we copy to prevent std::env::current_exe() to resolve to a store location ++ for i in ${crate}/bin/*; do ++ cp "$i" "$testRoot" ++ done ++ chmod +w -R . ++ ++ # test harness executables are suffixed with a hash, like cargo does ++ # this allows to prevent name collision with the main ++ # executables of the crate ++ hash=$(basename $out) ++ for file in ${drv}/tests/*; do ++ f=$testRoot/$(basename $file)-$hash ++ cp $file $f ++ ${testCommand} ++ done ++ ''; ++ }; + in + pkgs.runCommand "${crate.name}-linked" + { +-- +2.44.0 + diff --git a/third_party/overlays/patches/crate2nix-run-tests-in-build-source.patch b/third_party/overlays/patches/crate2nix-run-tests-in-build-source.patch deleted file mode 100644 index 52793270e6e8..000000000000 --- a/third_party/overlays/patches/crate2nix-run-tests-in-build-source.patch +++ /dev/null @@ -1,69 +0,0 @@ -From 7cf084f73f7d15fe0538a625182fa7179c083b3d Mon Sep 17 00:00:00 2001 -From: Raito Bezarius <masterancpp@gmail.com> -Date: Tue, 16 Jan 2024 02:10:48 +0100 -Subject: [PATCH] fix(template): run tests in `/build/source` instead `/build` - -Previously, the source tree was located inline in `/build` during tests, this was a mistake -because the crates more than often are built in `/build/source` as per the `sourceRoot` system. - -This can cause issues with test binaries hardcoding `/build/source/...` as their choice for doing things, -causing them to be confused in the test phase which is relocated without rewriting the paths inside test binaries. - -We fix that by relocating ourselves in the right hierarchy. - -This is a "simple" fix in the sense that more edge cases could exist but they are hard to reason about -because they would be crates using custom `sourceRoot`, i.e. having `crate.sourceRoot` set and then it becomes -a bit hard to reproduce the hierarchy, you need to analyze whether the path is absolute or relative, - -If it's relative, you can just reuse it and reproduce that specific hierarchy. -If it's absolute, you need to cut the "absolute" meaningless part, e.g. `$NIX_BUILD_TOP/` and proceed like -it's a relative path IMHO. ---- - crate2nix/Cargo.nix | 10 ++++++++++ - crate2nix/templates/nix/crate2nix/default.nix | 10 ++++++++++ - -diff --git a/Cargo.nix b/Cargo.nix -index 6ef7a49..172ff34 100644 ---- a/Cargo.nix -+++ b/Cargo.nix -@@ -2889,6 +2889,16 @@ rec { - # recreate a file hierarchy as when running tests with cargo - - # the source for test data -+ # It's necessary to locate the source in $NIX_BUILD_TOP/source/ -+ # instead of $NIX_BUILD_TOP/ -+ # because we compiled those test binaries in the former and not the latter. -+ # So all paths will expect source tree to be there and not in the build top directly. -+ # For example: $NIX_BUILD_TOP := /build in general, if you ask yourself. -+ # TODO(raitobezarius): I believe there could be more edge cases if `crate.sourceRoot` -+ # do exist but it's very hard to reason about them, so let's wait until the first bug report. -+ mkdir -p source/ -+ cd source/ -+ - ${pkgs.buildPackages.xorg.lndir}/bin/lndir ${crate.src} - - # build outputs -diff --git a/crate2nix/templates/nix/crate2nix/default.nix b/crate2nix/templates/nix/crate2nix/default.nix -index e4fc2e9..dfb14c4 100644 ---- a/templates/nix/crate2nix/default.nix -+++ b/templates/nix/crate2nix/default.nix -@@ -135,6 +135,16 @@ rec { - # recreate a file hierarchy as when running tests with cargo - - # the source for test data -+ # It's necessary to locate the source in $NIX_BUILD_TOP/source/ -+ # instead of $NIX_BUILD_TOP/ -+ # because we compiled those test binaries in the former and not the latter. -+ # So all paths will expect source tree to be there and not in the build top directly. -+ # For example: $NIX_BUILD_TOP := /build in general, if you ask yourself. -+ # TODO(raitobezarius): I believe there could be more edge cases if `crate.sourceRoot` -+ # do exist but it's very hard to reason about them, so let's wait until the first bug report. -+ mkdir -p source/ -+ cd source/ -+ - ${pkgs.buildPackages.xorg.lndir}/bin/lndir ${crate.src} - - # build outputs --- -2.43.0 - diff --git a/third_party/overlays/patches/treefmt-fix-no-cache.patch b/third_party/overlays/patches/treefmt-fix-no-cache.patch new file mode 100644 index 000000000000..2ad9d595e106 --- /dev/null +++ b/third_party/overlays/patches/treefmt-fix-no-cache.patch @@ -0,0 +1,43 @@ +From 601af097720079ea40db100b1dd6aefba4685e7c Mon Sep 17 00:00:00 2001 +From: Florian Klink <flokli@flokli.de> +Date: Mon, 1 Jul 2024 17:34:08 +0300 +Subject: [PATCH] fix: only try opening the cache if cache is enabled + +Otherwise `--no-cache` still fails to open the cache. +--- + cli/format.go | 12 ++++++++---- + 1 file changed, 8 insertions(+), 4 deletions(-) + +diff --git a/cli/format.go b/cli/format.go +index 492a4f3..8ccf578 100644 +--- a/cli/format.go ++++ b/cli/format.go +@@ -118,9 +118,11 @@ func (f *Format) Run() (err error) { + f.formatters[name] = formatter + } + +- // open the cache +- if err = cache.Open(f.TreeRoot, f.ClearCache, f.formatters); err != nil { +- return err ++ // open the cache if configured ++ if !f.NoCache { ++ if cache.Open(f.TreeRoot, f.ClearCache, f.formatters); err != nil { ++ return err ++ } + } + + // create an app context and listen for shutdown +@@ -148,7 +150,9 @@ func (f *Format) Run() (err error) { + f.processedCh = make(chan *walk.File, cap(f.filesCh)) + + // start concurrent processing tasks in reverse order +- eg.Go(f.updateCache(ctx)) ++ if !f.NoCache { ++ eg.Go(f.updateCache(ctx)) ++ } + eg.Go(f.applyFormatters(ctx)) + eg.Go(f.walkFilesystem(ctx)) + +-- +2.44.1 + |