Skip to content
This repository was archived by the owner on Mar 14, 2026. It is now read-only.

Commit 8872e19

Browse files
committed
Add GOCACHEPROG binary and pre-build stdlib cache for Go 1.25.5
- Build a new cacheprog binary to enable read-only cache access. - Pre-build the standard library cache in a dedicated GOCACHE directory. - Update compile script to use GOCACHEPROG for improved caching during builds.
1 parent b087c41 commit 8872e19

4 files changed

Lines changed: 116 additions & 2 deletions

File tree

packages/.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,5 @@
55
!*/*/environment
66
!*/*/run
77
!*/*/compile
8-
!*/*/test.*
8+
!*/*/test.*
9+
!*/*/cacheprog.go

packages/go/1.25.5/build.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,11 @@
22
curl -LO https://go.dev/dl/go1.25.5.linux-amd64.tar.gz
33
tar -xzf go1.25.5.linux-amd64.tar.gz
44
rm go1.25.5.linux-amd64.tar.gz
5+
6+
# Build GOCACHEPROG binary for read-only cache access
7+
CGO_ENABLED=0 ./go/bin/go build -o cacheprog cacheprog.go
8+
9+
# Pre-build standard library cache
10+
export GOCACHE=$PWD/cache
11+
mkdir -p $GOCACHE
12+
CGO_ENABLED=0 ./go/bin/go build std

packages/go/1.25.5/cacheprog.go

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
package main
2+
3+
import (
4+
"bufio"
5+
"encoding/hex"
6+
"encoding/json"
7+
"os"
8+
"path/filepath"
9+
"strconv"
10+
"strings"
11+
)
12+
13+
type Request struct {
14+
ID int64 `json:"ID"`
15+
Command string `json:"Command"`
16+
ActionID []byte `json:"ActionID,omitempty"`
17+
}
18+
19+
type Response struct {
20+
ID int64 `json:"ID"`
21+
KnownCommands []string `json:"KnownCommands,omitempty"`
22+
Miss bool `json:"Miss,omitempty"`
23+
OutputID []byte `json:"OutputID,omitempty"`
24+
Size int64 `json:"Size,omitempty"`
25+
DiskPath string `json:"DiskPath,omitempty"`
26+
}
27+
28+
func main() {
29+
if len(os.Args) < 2 {
30+
os.Exit(1)
31+
}
32+
cacheDir := os.Args[1]
33+
34+
enc := json.NewEncoder(os.Stdout)
35+
enc.Encode(Response{ID: 0, KnownCommands: []string{"get", "close"}})
36+
37+
scanner := bufio.NewScanner(os.Stdin)
38+
for scanner.Scan() {
39+
var req Request
40+
if err := json.Unmarshal(scanner.Bytes(), &req); err != nil {
41+
continue
42+
}
43+
44+
switch req.Command {
45+
case "get":
46+
enc.Encode(handleGet(cacheDir, req))
47+
case "close":
48+
enc.Encode(Response{ID: req.ID})
49+
return
50+
}
51+
}
52+
}
53+
54+
func handleGet(cacheDir string, req Request) Response {
55+
actionHex := hex.EncodeToString(req.ActionID)
56+
if len(actionHex) < 2 {
57+
return Response{ID: req.ID, Miss: true}
58+
}
59+
60+
actionPath := filepath.Join(cacheDir, actionHex[:2], actionHex+"-a")
61+
data, err := os.ReadFile(actionPath)
62+
if err != nil {
63+
return Response{ID: req.ID, Miss: true}
64+
}
65+
66+
outputID, size, err := parseActionEntry(data)
67+
if err != nil {
68+
return Response{ID: req.ID, Miss: true}
69+
}
70+
71+
outputHex := hex.EncodeToString(outputID)
72+
dataPath := filepath.Join(cacheDir, outputHex[:2], outputHex+"-d")
73+
if _, err := os.Stat(dataPath); err != nil {
74+
return Response{ID: req.ID, Miss: true}
75+
}
76+
77+
return Response{
78+
ID: req.ID,
79+
OutputID: outputID,
80+
Size: size,
81+
DiskPath: dataPath,
82+
}
83+
}
84+
85+
// parseActionEntry parses: "v1 <actionHex> <outputHex> <size> <time>\n"
86+
func parseActionEntry(data []byte) ([]byte, int64, error) {
87+
line := strings.TrimSpace(string(data))
88+
fields := strings.Fields(line)
89+
if len(fields) < 4 || fields[0] != "v1" {
90+
return nil, 0, os.ErrInvalid
91+
}
92+
93+
outputID, err := hex.DecodeString(fields[2])
94+
if err != nil {
95+
return nil, 0, err
96+
}
97+
98+
size, err := strconv.ParseInt(fields[3], 10, 64)
99+
if err != nil {
100+
return nil, 0, err
101+
}
102+
103+
return outputID, size, nil
104+
}

packages/go/1.25.5/compile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#!/usr/bin/env bash
22

33
mv $1 $1.go
4-
GOCACHE=$PWD go build -o binary *.go
4+
export GOCACHEPROG="/piston/packages/go/1.25.5/cacheprog /piston/packages/go/1.25.5/cache"
5+
CGO_ENABLED=0 go build -o binary *.go
56
chmod +x binary

0 commit comments

Comments
 (0)