Skip to content

Commit

Permalink
Added full CGO support
Browse files Browse the repository at this point in the history
  • Loading branch information
maoueh committed May 8, 2023
1 parent 7daf256 commit f341d60
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 16 deletions.
8 changes: 7 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
8 changes: 8 additions & 0 deletions cmd/sfreleaser/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,3 +95,11 @@ type RustReleaseModel struct {
CargoPublishArgs []string
Crates []string
}

type GitHubReleaseModel struct {
AllowDirty bool
EnvFilePath string
GoreleaseConfigPath string
GoreleaserImageID string
ReleaseNotesPath string
}
16 changes: 12 additions & 4 deletions cmd/sfreleaser/release.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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")
Expand All @@ -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),
Expand Down Expand Up @@ -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)
Expand Down
13 changes: 6 additions & 7 deletions cmd/sfreleaser/release_github.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,33 +6,32 @@ 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",

// docker arguments
"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")
}

Expand Down
8 changes: 4 additions & 4 deletions cmd/sfreleaser/release_rust.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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) {
Expand Down
9 changes: 9 additions & 0 deletions cmd/sfreleaser/templates/application/goreleaser.yaml.gotmpl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down

0 comments on commit f341d60

Please sign in to comment.