Skip to content

Commit c7a05b9

Browse files
dilyevskyclaude
andcommitted
feat: add sccache and mold for faster edge-runtime builds
- Add sccache 0.11.0 with depot.dev cache integration - Add mold linker for faster linking - Wire up SCCACHE_WEBDAV_TOKEN in CI workflows Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 3365d5c commit c7a05b9

File tree

4 files changed

+61
-14
lines changed

4 files changed

+61
-14
lines changed

.github/workflows/dev.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ jobs:
2121
dagger call -v build-cli --src=.
2222
# Make sure we can build for Darwin as well.
2323
dagger call -v build-cli --src=. --platform=darwin/arm64
24-
dagger call -v build-apiserver --src=.
25-
dagger call -v build-backplane --src=.
24+
dagger call -v build-apiserver --src=. --sccache-token=env:SCCACHE_WEBDAV_TOKEN
25+
dagger call -v build-backplane --src=. --sccache-token=env:SCCACHE_WEBDAV_TOKEN
2626
dagger call -v build-kube-controller --src=.
2727
dagger call -v build-tunnelproxy --src=.

.github/workflows/main.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,4 @@ jobs:
1818
SHUTUP: 1
1919
timeout-minutes: 30
2020
run: |
21-
dagger call -v publish-images --src=. --tag=latest --sha=${GITHUB_SHA::7} --registry-password=env:APOXY_DOCKERHUB_PASSWORD
21+
dagger call -v publish-images --src=. --tag=latest --sha=${GITHUB_SHA::7} --registry-password=env:APOXY_DOCKERHUB_PASSWORD --sccache-token=env:SCCACHE_WEBDAV_TOKEN

.github/workflows/release.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,6 @@ jobs:
2424
SHUTUP: 1
2525
timeout-minutes: 15
2626
run: |
27-
dagger call -v publish-images --src=. --tag=$GITHUB_REF_NAME --sha=${GITHUB_SHA::7} --registry-password=env:APOXY_DOCKERHUB_PASSWORD
27+
dagger call -v publish-images --src=. --tag=$GITHUB_REF_NAME --sha=${GITHUB_SHA::7} --registry-password=env:APOXY_DOCKERHUB_PASSWORD --sccache-token=env:SCCACHE_WEBDAV_TOKEN
2828
dagger call -v publish-github-release --src=. --tag=$GITHUB_REF_NAME --github-token=env:GITHUB_TOKEN --sha=${GITHUB_SHA::7}
2929
dagger call -v publish-helm-release --src=./deploy/helm --tag=$GITHUB_REF_NAME --registry-password=env:APOXY_DOCKERHUB_PASSWORD

ci/main.go

Lines changed: 57 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -379,20 +379,42 @@ func (m *ApoxyCli) BuildEdgeRuntime(
379379
platform string,
380380
// +optional
381381
src *dagger.Directory,
382+
// +optional
383+
sccacheToken *dagger.Secret,
382384
) *dagger.Container {
383385
if src == nil {
384386
src = dag.Git("https://github.com/apoxy-dev/edge-runtime").
385387
Branch("main").
386388
Tree()
387389
}
388390
p := dagger.Platform(platform)
389-
return dag.Container(dagger.ContainerOpts{Platform: p}).
391+
goarch := archOf(p)
392+
targetArch := canonArchFromGoArch(goarch)
393+
394+
builder := dag.Container(dagger.ContainerOpts{Platform: p}).
390395
From("rust:1.82.0-bookworm").
391396
WithExec([]string{"apt-get", "update"}).
392-
WithExec([]string{"apt-get", "install", "-y", "llvm-dev", "libclang-dev", "gcc", "cmake", "binutils"}).
397+
WithExec([]string{"apt-get", "install", "-y", "llvm-dev", "libclang-dev", "gcc", "cmake", "binutils", "clang", "mold"}).
398+
// Install sccache for compilation caching (0.11.0 is compatible with rustc 1.82.0).
399+
WithExec([]string{"cargo", "install", "sccache", "--version", "0.11.0", "--locked"}).
400+
WithEnvVariable("SCCACHE_WEBDAV_ENDPOINT", "https://cache.depot.dev").
401+
WithEnvVariable("RUSTC_WRAPPER", "/usr/local/cargo/bin/sccache").
402+
// Configure mold as linker for faster linking.
403+
WithEnvVariable("CARGO_TARGET_X86_64_UNKNOWN_LINUX_GNU_LINKER", "clang").
404+
WithEnvVariable("CARGO_TARGET_X86_64_UNKNOWN_LINUX_GNU_RUSTFLAGS", "-C link-arg=-fuse-ld=mold").
405+
WithEnvVariable("CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_LINKER", "clang").
406+
WithEnvVariable("CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_RUSTFLAGS", "-C link-arg=-fuse-ld=mold").
407+
WithMountedCache("/usr/local/cargo/registry", dag.CacheVolume("cargo-registry-"+goarch)).
408+
WithMountedCache("/src/target", dag.CacheVolume("cargo-target-"+goarch)).
409+
WithMountedCache("/root/.cache/sccache", dag.CacheVolume("sccache-"+targetArch)).
393410
WithWorkdir("/src").
394-
WithDirectory("/src", src).
395-
WithExec([]string{"cargo", "build", "--release"})
411+
WithDirectory("/src", src)
412+
413+
if sccacheToken != nil {
414+
builder = builder.WithSecretVariable("SCCACHE_WEBDAV_TOKEN", sccacheToken)
415+
}
416+
417+
return builder.WithExec([]string{"cargo", "build", "--release"})
396418
}
397419

398420
// PullEdgeRuntime builds the Apoxy edge-runtime fork from source.
@@ -403,8 +425,11 @@ func (m *ApoxyCli) PullEdgeRuntime(
403425
platform dagger.Platform,
404426
// +optional
405427
apoxyCliSrc *dagger.Directory,
428+
// +optional
429+
sccacheToken *dagger.Secret,
406430
) *dagger.Container {
407431
goarch := archOf(platform)
432+
targetArch := canonArchFromGoArch(goarch)
408433

409434
// Build edge-runtime from source.
410435
edgeRuntimeSrc := dag.Git("https://github.com/apoxy-dev/edge-runtime").
@@ -414,11 +439,27 @@ func (m *ApoxyCli) PullEdgeRuntime(
414439
builder := dag.Container(dagger.ContainerOpts{Platform: platform}).
415440
From("rust:1.82.0-bookworm").
416441
WithExec([]string{"apt-get", "update"}).
417-
WithExec([]string{"apt-get", "install", "-y", "llvm-dev", "libclang-dev", "gcc", "cmake", "binutils"}).
442+
WithExec([]string{"apt-get", "install", "-y", "llvm-dev", "libclang-dev", "gcc", "cmake", "binutils", "clang", "mold"}).
443+
// Install sccache for compilation caching (0.11.0 is compatible with rustc 1.82.0).
444+
WithExec([]string{"cargo", "install", "sccache", "--version", "0.11.0", "--locked"}).
445+
WithEnvVariable("SCCACHE_WEBDAV_ENDPOINT", "https://cache.depot.dev").
446+
WithEnvVariable("RUSTC_WRAPPER", "/usr/local/cargo/bin/sccache").
447+
// Configure mold as linker for faster linking.
448+
WithEnvVariable("CARGO_TARGET_X86_64_UNKNOWN_LINUX_GNU_LINKER", "clang").
449+
WithEnvVariable("CARGO_TARGET_X86_64_UNKNOWN_LINUX_GNU_RUSTFLAGS", "-C link-arg=-fuse-ld=mold").
450+
WithEnvVariable("CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_LINKER", "clang").
451+
WithEnvVariable("CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_RUSTFLAGS", "-C link-arg=-fuse-ld=mold").
418452
WithMountedCache("/usr/local/cargo/registry", dag.CacheVolume("cargo-registry-"+goarch)).
419453
WithMountedCache("/src/target", dag.CacheVolume("cargo-target-"+goarch)).
454+
WithMountedCache("/root/.cache/sccache", dag.CacheVolume("sccache-"+targetArch)).
420455
WithWorkdir("/src").
421-
WithDirectory("/src", edgeRuntimeSrc).
456+
WithDirectory("/src", edgeRuntimeSrc)
457+
458+
if sccacheToken != nil {
459+
builder = builder.WithSecretVariable("SCCACHE_WEBDAV_TOKEN", sccacheToken)
460+
}
461+
462+
builder = builder.
422463
WithExec([]string{"cargo", "build", "--release"}).
423464
WithExec([]string{"cp", "/src/target/release/edge-runtime", "/edge-runtime"})
424465

@@ -445,6 +486,8 @@ func (m *ApoxyCli) BuildAPIServer(
445486
src *dagger.Directory,
446487
// +optional
447488
platform string,
489+
// +optional
490+
sccacheToken *dagger.Secret,
448491
) *dagger.Container {
449492
if platform == "" {
450493
platform = runtime.GOOS + "/" + runtime.GOARCH
@@ -459,7 +502,7 @@ func (m *ApoxyCli) BuildAPIServer(
459502
WithEnvVariable("CC", fmt.Sprintf("zig-wrapper cc --target=%s-linux-musl", canonArchFromGoArch(goarch))).
460503
WithExec([]string{"go", "build", "-o", "apiserver", "./cmd/apiserver"})
461504

462-
runtimeCtr := m.PullEdgeRuntime(ctx, p, src)
505+
runtimeCtr := m.PullEdgeRuntime(ctx, p, src, sccacheToken)
463506

464507
return dag.Container(dagger.ContainerOpts{Platform: p}).
465508
From("cgr.dev/chainguard/wolfi-base:latest").
@@ -483,6 +526,8 @@ func (m *ApoxyCli) BuildBackplane(
483526
src *dagger.Directory,
484527
// +optional
485528
platform string,
529+
// +optional
530+
sccacheToken *dagger.Secret,
486531
) *dagger.Container {
487532
if platform == "" {
488533
platform = runtime.GOOS + "/" + runtime.GOARCH
@@ -514,7 +559,7 @@ func (m *ApoxyCli) BuildBackplane(
514559
WithExec([]string{"go", "build", "-o", "/src/" + otelOut}).
515560
WithWorkdir("/src")
516561

517-
runtimeCtr := m.PullEdgeRuntime(ctx, p, src)
562+
runtimeCtr := m.PullEdgeRuntime(ctx, p, src, sccacheToken)
518563

519564
return dag.Container(dagger.ContainerOpts{Platform: p}).
520565
From("cgr.dev/chainguard/wolfi-base:latest").
@@ -610,10 +655,12 @@ func (m *ApoxyCli) PublishImages(
610655
registryPassword *dagger.Secret,
611656
tag string,
612657
sha string,
658+
// +optional
659+
sccacheToken *dagger.Secret,
613660
) error {
614661
var apiCtrs []*dagger.Container
615662
for _, platform := range []string{"linux/amd64", "linux/arm64"} {
616-
apiCtrs = append(apiCtrs, m.BuildAPIServer(ctx, src, platform))
663+
apiCtrs = append(apiCtrs, m.BuildAPIServer(ctx, src, platform, sccacheToken))
617664
}
618665

619666
addr, err := dag.Container().
@@ -633,7 +680,7 @@ func (m *ApoxyCli) PublishImages(
633680

634681
var bCtrs []*dagger.Container
635682
for _, platform := range []string{"linux/amd64", "linux/arm64"} {
636-
bCtrs = append(bCtrs, m.BuildBackplane(ctx, src, platform))
683+
bCtrs = append(bCtrs, m.BuildBackplane(ctx, src, platform, sccacheToken))
637684
}
638685

639686
addr, err = dag.Container().

0 commit comments

Comments
 (0)