https://github.com/numtide/build-go-cache
buildGoCache speeds up nix's buildGoModule by pre-compiling imported go modules
https://github.com/numtide/build-go-cache
buildbot-numtide
Last synced: 3 months ago
JSON representation
buildGoCache speeds up nix's buildGoModule by pre-compiling imported go modules
- Host: GitHub
- URL: https://github.com/numtide/build-go-cache
- Owner: numtide
- License: other
- Created: 2023-10-26T13:19:50.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2024-10-02T14:57:38.000Z (9 months ago)
- Last Synced: 2025-04-02T23:55:51.092Z (3 months ago)
- Topics: buildbot-numtide
- Language: Nix
- Homepage:
- Size: 23.4 KB
- Stars: 16
- Watchers: 3
- Forks: 4
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
# buildGoCache
buildGoCache speeds up nix's buildGoModule by pre-compiling imported go modules
## Potential speed-up
For telegraf we measured the following build times with and without the buildGoCache.
Build machine: AMD Ryzen 9 7950X3D 16-Core Processor, 128G DDR4 RAM, zfs raid0
without cache:
```
time nix build .#example-no-cache -L
0.28s user 0.20s system 0% cpu 59.539 total
time nix build .#example-proxy-vendor-no-cachA
0.30s user 0.20s system 0% cpu 1:14.01 total
```with cache:
```
time nix build .#example -L
0.23s user 0.18s system 1% cpu 25.872 total
time nix build .#example-proxy-vendor -L
0.03s user 0.04s system 0% cpu 30.501 total
```Speedup: 2.3x..~2.4x
## Usage
First we generate a list of all imported packages:
```
nix run .#get-external-imports -- ./. imported-packages
```Than we modify our `buildGoModule` to use your go build cache:
```nix
let
vendorHash = "sha256-aMO7nH68E1S5G1iWj29McK0VY0frfjNnJ6D6rJ29cqQ=";
proxyVendor = true; # must be in sync for buildGoCache and buildGoModule
src = ./.; # replace this with the source directorygoCache = buildGoCache {
importPackagesFile = ./imported-packages;
inherit src vendorHash proxyVendor;
};
in
buildGoModule {
name = "myproject";buildInputs = [ goCache ];
inherit src;
inherit vendorHash proxyVendor;
}
```See [./examples]() for real-world examples based on telegraf and gomod2nix
Other [real-world example](https://github.com/replit/upm/pull/155)