From f341d60b83491336a3810bc5ee8a8f8ca9a85bcf Mon Sep 17 00:00:00 2001 From: Matthieu Vachon Date: Mon, 8 May 2023 10:00:11 -0400 Subject: [PATCH] Added full `CGO` support --- CHANGELOG.md | 8 +++++++- cmd/sfreleaser/models.go | 8 ++++++++ cmd/sfreleaser/release.go | 16 ++++++++++++---- cmd/sfreleaser/release_github.go | 13 ++++++------- cmd/sfreleaser/release_rust.go | 8 ++++---- .../templates/application/goreleaser.yaml.gotmpl | 9 +++++++++ 6 files changed, 46 insertions(+), 16 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b5dfd88..18c4b18 100755 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,7 +5,13 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). -## [Unreleased] +## v0.4.0 + +* Added full `CGO` support when building Go application/library, `.goreleaser.yaml` file now has `C_INCLUDE_PATH` and `LIBRARY_PATH` sets correctly so it's possible to build Go that depends on C libraries. + +* Added config/flag value `goreleaser-docker-image` so it's possible to override `goreleaser` Docker image used. + +## v0.3.0 * Added support for releasing Rust library project. diff --git a/cmd/sfreleaser/models.go b/cmd/sfreleaser/models.go index 8d68c18..b1d3610 100644 --- a/cmd/sfreleaser/models.go +++ b/cmd/sfreleaser/models.go @@ -95,3 +95,11 @@ type RustReleaseModel struct { CargoPublishArgs []string Crates []string } + +type GitHubReleaseModel struct { + AllowDirty bool + EnvFilePath string + GoreleaseConfigPath string + GoreleaserImageID string + ReleaseNotesPath string +} diff --git a/cmd/sfreleaser/release.go b/cmd/sfreleaser/release.go index 4f3db80..6b021ca 100644 --- a/cmd/sfreleaser/release.go +++ b/cmd/sfreleaser/release.go @@ -55,6 +55,7 @@ var ReleaseCmd = Command(release, flags.StringArray("pre-build-hooks", nil, "Set of pre build hooks to run before run the actual building steps") flags.String("upload-substreams-spkg", "", "If provided, add this Substreams package file to the release, if manifest is a 'substreams.yaml' file, the package is first built") flags.Bool("publish-now", false, "By default, publish the release to GitHub in draft mode, if the flag is used, the release is published as latest") + flags.String("goreleaser-docker-image", "goreleaser/goreleaser-cross:v1.20.3", "Full Docker image used to run Goreleaser tool (which perform Go builds and GitHub releases (in all languages))") // Rust Flags flags.String("rust-cargo-publish-args", "", "[Rust only] The extra arguments to pass to 'cargo publish' when publishing, the tool might provide some default on its own, Bash rules are used to split the arguments from the string") @@ -93,6 +94,7 @@ func release(cmd *cobra.Command, args []string) error { } allowDirty := sflags.MustGetBool(cmd, "allow-dirty") + goreleaserDockerImage := sflags.MustGetString(cmd, "goreleaser-docker-image") publishNow := sflags.MustGetBool(cmd, "publish-now") preBuildHooks := sflags.MustGetStringArray(cmd, "pre-build-hooks") uploadSubstreamsSPKG := sflags.MustGetString(cmd, "upload-substreams-spkg") @@ -102,6 +104,7 @@ func release(cmd *cobra.Command, args []string) error { zlog.Debug("starting 'sfreleaser release'", zap.Inline(global), zap.Bool("allow_dirty", allowDirty), + zap.String("goreleaser_docker_image", goreleaserDockerImage), zap.Bool("publish_now", publishNow), zap.Strings("pre_build_hooks", preBuildHooks), zap.String("upload_substreams_spkg", uploadSubstreamsSPKG), @@ -165,15 +168,20 @@ func release(cmd *cobra.Command, args []string) error { runSilent("git tag -d", version) }) - envFilePath := "build/.env.release" - releaseNotesPath := "build/.release_notes.md" + gitHubRelease := &GitHubReleaseModel{ + AllowDirty: allowDirty, + EnvFilePath: "build/.env.release", + GoreleaseConfigPath: ".goreleaser.yaml", + GoreleaserImageID: goreleaserDockerImage, + ReleaseNotesPath: "build/.release_notes.md", + } switch global.Language { case LanguageGolang: - releaseGolangGitHub(".goreleaser.yaml", allowDirty, envFilePath, releaseNotesPath) + releaseGolangGitHub(gitHubRelease) case LanguageRust: - releaseRustGitHub(global, allowDirty, envFilePath, releaseNotesPath) + releaseRustGitHub(global, gitHubRelease) default: cli.Quit("unhandled language %q", global.Language) diff --git a/cmd/sfreleaser/release_github.go b/cmd/sfreleaser/release_github.go index 872151d..cbfc98d 100644 --- a/cmd/sfreleaser/release_github.go +++ b/cmd/sfreleaser/release_github.go @@ -6,12 +6,11 @@ import ( "github.com/streamingfast/cli" ) -func releaseGithub(goreleaseConfigPath string, allowDirty bool, envFilePath string, releaseNotesPath string) { +func releaseGithub(model *GitHubReleaseModel) { if devSkipGoreleaser { return } - golangCrossVersion := "v1.20.2" arguments := []string{ "docker", @@ -19,20 +18,20 @@ func releaseGithub(goreleaseConfigPath string, allowDirty bool, envFilePath stri "run", "--rm", "-e CGO_ENABLED=1", - "--env-file", envFilePath, + "--env-file", model.EnvFilePath, "-v /var/run/docker.sock:/var/run/docker.sock", "-v", cli.WorkingDirectory() + ":/go/src/work", "-w /go/src/work", - "goreleaser/goreleaser-cross:" + golangCrossVersion, + model.GoreleaserImageID, // goreleaser arguments - "-f", goreleaseConfigPath, + "-f", model.GoreleaseConfigPath, "--timeout=60m", "--rm-dist", - "--release-notes=" + releaseNotesPath, + "--release-notes=" + model.ReleaseNotesPath, } - if allowDirty { + if model.AllowDirty { arguments = append(arguments, "--skip-validate") } diff --git a/cmd/sfreleaser/release_rust.go b/cmd/sfreleaser/release_rust.go index 62a59e8..190f410 100644 --- a/cmd/sfreleaser/release_rust.go +++ b/cmd/sfreleaser/release_rust.go @@ -9,9 +9,9 @@ import ( "github.com/streamingfast/cli" ) -func releaseRustGitHub(global *GlobalModel, allowDirty bool, envFilePath string, releaseNotesPath string) { +func releaseRustGitHub(global *GlobalModel, gitHubRelease *GitHubReleaseModel) { buildDirectory := "build" - goreleaserPath := filepath.Join(buildDirectory, "goreleaser.yaml") + gitHubRelease.GoreleaseConfigPath = filepath.Join(buildDirectory, "goreleaser.yaml") cli.NoError(os.MkdirAll(buildDirectory, os.ModePerm), `Unable to create %q directory`, buildDirectory) @@ -20,9 +20,9 @@ func releaseRustGitHub(global *GlobalModel, allowDirty bool, envFilePath string, goreleaserTemplate = goreleaserLibTmpl } - renderTemplate(goreleaserPath, true, goreleaserTemplate, getInstallTemplateModel(global)) + renderTemplate(gitHubRelease.GoreleaseConfigPath, true, goreleaserTemplate, getInstallTemplateModel(global)) - releaseGithub(goreleaserPath, allowDirty, envFilePath, releaseNotesPath) + releaseGithub(gitHubRelease) } func printRustCratesNotPublishedMessage(rust *RustReleaseModel) { diff --git a/cmd/sfreleaser/templates/application/goreleaser.yaml.gotmpl b/cmd/sfreleaser/templates/application/goreleaser.yaml.gotmpl index 757b85a..57137c5 100644 --- a/cmd/sfreleaser/templates/application/goreleaser.yaml.gotmpl +++ b/cmd/sfreleaser/templates/application/goreleaser.yaml.gotmpl @@ -10,8 +10,11 @@ builds: goarch: - amd64 env: + - CGO_ENABLED=1 - CC=o64-clang - CXX=o64-clang++ + - C_INCLUDE_PATH=/usr/local/osxcross/include/amd64 + - LIBRARY_PATH=/usr/local/osxcross/lib/amd64 flags: - -trimpath - -mod=readonly @@ -26,8 +29,11 @@ builds: goarch: - arm64 env: + - CGO_ENABLED=1 - CC=oa64-clang - CXX=oa64-clang++ + - C_INCLUDE_PATH=/usr/local/osxcross/include/arm64 + - LIBRARY_PATH=/usr/local/osxcross/lib/arm64 flags: - -trimpath - -mod=readonly @@ -42,8 +48,11 @@ builds: goarch: - amd64 env: + - CGO_ENABLED=1 - CC=x86_64-linux-gnu-gcc - CXX=x86_64-linux-gnu-g++ + - C_INCLUDE_PATH=/usr/x86_64-linux-gnu/include + - LIBRARY_PATH=/usr/x86_64-linux-gnu/lib flags: - -trimpath - -mod=readonly