Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(build): initial support for zig #5312

Merged
merged 16 commits into from
Nov 28, 2024
Merged
4 changes: 4 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,7 @@ charset = utf-8
[*.{md,yml,yaml,rb}]
indent_size = 2
indent_style = space

[*.py]
indent_size = 4
indent_style = space
6 changes: 6 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@ www/docs/static/schema.json linguist-generated=true
www/docs/static/schema-pro.json linguist-generated=true
www/docs/static/releases.json linguist-generated=true
www/docs/static/releases-pro.json linguist-generated=true

internal/builders/zig/testdata/proj/**/* linguist-generated=true
internal/builders/zig/all_targets.txt linguist-generated=true
internal/builders/zig/error_targets.txt linguist-generated=true
internal/builders/zig/testdata/version.txt linguist-generated=true

*.nix.golden linguist-language=Nix
*.rb.golden linguist-language=Ruby
*.json.golden linguist-language=JSON
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ jobs:
- uses: actions/setup-go@41dfa10bad2bb2ae585af6ee5bb4d7d973ad74ed # v4
with:
go-version: stable
- uses: mlugg/setup-zig@v1
- uses: sigstore/cosign-installer@v3.7.0
- uses: anchore/sbom-action/download-syft@v0.17.8
- name: setup-validate-krew-manifest
Expand Down
2 changes: 1 addition & 1 deletion dagger/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func (g *Goreleaser) Base() *dagger.Container {
// Base image with Go
return dag.Container().
From(wolfiBase).
WithExec([]string{"apk", "add", "go"}).
WithExec([]string{"apk", "add", "go", "zig"}).
// Mount the Go cache
WithMountedCache(
"/go",
Expand Down
15 changes: 13 additions & 2 deletions internal/artifact/artifact.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ const (
ExtraSize = "Size"
ExtraChecksum = "Checksum"
ExtraChecksumOf = "ChecksumOf"
ExtraBuilder = "Builder"
)

// Extras represents the extra fields in an artifact.
Expand Down Expand Up @@ -467,14 +468,24 @@ func ByGoarch(s string) Filter {
// ByGoarm is a predefined filter that filters by the given goarm.
func ByGoarm(s string) Filter {
return func(a *Artifact) bool {
return a.Goarm == s
switch ExtraOr(*a, ExtraBuilder, "") {
case "zig":
return true
default:
return a.Goarm == s
}
}
}

// ByGoamd64 is a predefined filter that filters by the given goamd64.
func ByGoamd64(s string) Filter {
return func(a *Artifact) bool {
return a.Goamd64 == s
switch ExtraOr(*a, ExtraBuilder, "") {
case "zig":
return true
default:
return a.Goamd64 == s
}
}
}

Expand Down
7 changes: 4 additions & 3 deletions internal/builders/golang/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -244,9 +244,10 @@ func (*Builder) Build(ctx *context.Context, build config.Build, options api.Opti
Goriscv64: t.Goriscv64,
Target: t.Target,
Extra: map[string]interface{}{
artifact.ExtraBinary: strings.TrimSuffix(filepath.Base(options.Path), options.Ext),
artifact.ExtraExt: options.Ext,
artifact.ExtraID: build.ID,
artifact.ExtraBinary: strings.TrimSuffix(filepath.Base(options.Path), options.Ext),
artifact.ExtraExt: options.Ext,
artifact.ExtraID: build.ID,
artifact.ExtraBuilder: "go",
},
}

Expand Down
63 changes: 35 additions & 28 deletions internal/builders/golang/build_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -529,10 +529,11 @@ func TestBuild(t *testing.T) {
Target: "linux_amd64_v1",
Type: artifact.Binary,
Extra: map[string]interface{}{
artifact.ExtraExt: "",
artifact.ExtraBinary: "foo-v5.6.7",
artifact.ExtraID: "foo",
"testEnvs": []string{"TEST_T=l"},
artifact.ExtraExt: "",
artifact.ExtraBinary: "foo-v5.6.7",
artifact.ExtraID: "foo",
artifact.ExtraBuilder: "go",
"testEnvs": []string{"TEST_T=l"},
},
},
{
Expand All @@ -544,10 +545,11 @@ func TestBuild(t *testing.T) {
Target: "linux_mips_softfloat",
Type: artifact.Binary,
Extra: map[string]interface{}{
artifact.ExtraExt: "",
artifact.ExtraBinary: "foo-v5.6.7",
artifact.ExtraID: "foo",
"testEnvs": []string{"TEST_T=l"},
artifact.ExtraExt: "",
artifact.ExtraBinary: "foo-v5.6.7",
artifact.ExtraID: "foo",
artifact.ExtraBuilder: "go",
"testEnvs": []string{"TEST_T=l"},
},
},
{
Expand All @@ -559,10 +561,11 @@ func TestBuild(t *testing.T) {
Target: "linux_mips64le_softfloat",
Type: artifact.Binary,
Extra: map[string]interface{}{
artifact.ExtraExt: "",
artifact.ExtraBinary: "foo-v5.6.7",
artifact.ExtraID: "foo",
"testEnvs": []string{"TEST_T=l"},
artifact.ExtraExt: "",
artifact.ExtraBinary: "foo-v5.6.7",
artifact.ExtraID: "foo",
artifact.ExtraBuilder: "go",
"testEnvs": []string{"TEST_T=l"},
},
},
{
Expand All @@ -574,10 +577,11 @@ func TestBuild(t *testing.T) {
Target: "darwin_amd64_v1",
Type: artifact.Binary,
Extra: map[string]interface{}{
artifact.ExtraExt: "",
artifact.ExtraBinary: "foo-v5.6.7",
artifact.ExtraID: "foo",
"testEnvs": []string{"TEST_T=d"},
artifact.ExtraExt: "",
artifact.ExtraBinary: "foo-v5.6.7",
artifact.ExtraID: "foo",
artifact.ExtraBuilder: "go",
"testEnvs": []string{"TEST_T=d"},
},
},
{
Expand All @@ -589,10 +593,11 @@ func TestBuild(t *testing.T) {
Target: "linux_arm_6",
Type: artifact.Binary,
Extra: map[string]interface{}{
artifact.ExtraExt: "",
artifact.ExtraBinary: "foo-v5.6.7",
artifact.ExtraID: "foo",
"testEnvs": []string{"TEST_T=l"},
artifact.ExtraExt: "",
artifact.ExtraBinary: "foo-v5.6.7",
artifact.ExtraID: "foo",
artifact.ExtraBuilder: "go",
"testEnvs": []string{"TEST_T=l"},
},
},
{
Expand All @@ -604,10 +609,11 @@ func TestBuild(t *testing.T) {
Target: "windows_amd64_v1",
Type: artifact.Binary,
Extra: map[string]interface{}{
artifact.ExtraExt: ".exe",
artifact.ExtraBinary: "foo-v5.6.7",
artifact.ExtraID: "foo",
"testEnvs": []string{"TEST_T=w"},
artifact.ExtraExt: ".exe",
artifact.ExtraBinary: "foo-v5.6.7",
artifact.ExtraID: "foo",
artifact.ExtraBuilder: "go",
"testEnvs": []string{"TEST_T=w"},
},
},
{
Expand All @@ -618,10 +624,11 @@ func TestBuild(t *testing.T) {
Target: "js_wasm",
Type: artifact.Binary,
Extra: map[string]interface{}{
artifact.ExtraExt: ".wasm",
artifact.ExtraBinary: "foo-v5.6.7",
artifact.ExtraID: "foo",
"testEnvs": []string{"TEST_T="},
artifact.ExtraExt: ".wasm",
artifact.ExtraBinary: "foo-v5.6.7",
artifact.ExtraID: "foo",
artifact.ExtraBuilder: "go",
"testEnvs": []string{"TEST_T="},
},
},
}
Expand Down
94 changes: 94 additions & 0 deletions internal/builders/zig/all_targets.txt

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading