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: darwin arm64 binary #690

Merged
merged 10 commits into from May 15, 2022
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
24 changes: 13 additions & 11 deletions .github/workflows/release.yml
Expand Up @@ -9,22 +9,24 @@ jobs:
name: Release
runs-on: ubuntu-latest
steps:
- name: Checkout Code
uses: actions/checkout@v3

- name: Set up Go 1.17
uses: actions/setup-go@v3
with:
go-version: 1.17
id: go
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this is used.


- name: Checkout Code
uses: actions/checkout@v3

- name: Fetch tags
run: git fetch --depth=1 origin +refs/tags/*:refs/tags/*

- name: Run GoReleaser
uses: goreleaser/goreleaser-action@v2
env:
GITHUB_TOKEN: ${{ secrets.GORELEASER_GITHUB_TOKEN }}
with:
version: latest
args: release --rm-dist
- name: release dry run
run: make release-dry-run
Comment on lines +23 to +24
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This container image is awfully big. I wouldn't want this running that often as I don't personally understand the implications for GHA for this org.


- name: setup release environment
run: |-
echo 'GITHUB_TOKEN=${{secrets.GORELEASER_GITHUB_TOKEN }}' > .release-env

- name: release publish
run: make release

144 changes: 81 additions & 63 deletions .goreleaser.yml
@@ -1,76 +1,95 @@
# GoReleaser config

---
before:
hooks:
- go mod tidy

builds:
- id: pop_darwin
binary: soda
main: soda/main.go
goos:
- darwin
goarch:
- amd64
env:
- CGO_ENABLED=1
- CC=o64-clang
- CXX=o64-clang++
flags:
- -tags
- sqlite
- id: pop_darwin
binary: soda
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I changed the indentation as my vimconfig make it obnoxious. Maybe I should undo that because this looks more gnarly than it is.

main: soda/main.go
goos:
- darwin
goarch:
- amd64
ldflags:
- -s
env:
- CGO_ENABLED=1
- CC=/osxcross/target/bin/o64-clang
- CXX=/osxcross/target/bin/o64-clang++
flags:
- -tags
- sqlite

- id: pop_linux
binary: soda
main: soda/main.go
env:
- CGO_ENABLED=1
flags:
- -tags
- sqlite
goos:
- linux
goarch:
- amd64
- 386
- id: pop_darwin_arm64
binary: soda
main: soda/main.go
goos:
- darwin
goarch:
- arm64
ldflags:
- -s
env:
- CGO_ENABLED=1
- CC=/osxcross/target/bin/oa64-clang
- CXX=/osxcross/target/bin/oa64-clang++
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I separated out pop_darwin and pop_darwin_arm64 as darwin_arm64 suggests oa64-clang/oa64-clang++ on https://github.com/goreleaser/goreleaser-cross#supported-toolchainsplatforms.

flags:
- -tags
- sqlite

- id: pop_windows_i686
binary: soda
main: soda/main.go
ldflags:
- "-extldflags '-static'"
env:
- CGO_ENABLED=1
- CC=i686-w64-mingw32-gcc
- CXX=i686-w64-mingw32-g++
flags:
- -tags
- sqlite
goos:
- windows
goarch:
- 386
- id: pop_linux
binary: soda
main: soda/main.go
env:
- CGO_ENABLED=0
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I changed CGO_ENABLED=0 on the Linux builds and it built fine in https://github.com/jfreeland/pop/runs/6069504394?check_suite_focus=true#step:5:95. But maybe that is not the correct step here.

flags:
- -tags
- sqlite
goos:
- linux
goarch:
- amd64
- 386

- id: pop_windows_x64
binary: soda
main: soda/main.go
ldflags:
- "-extldflags '-static'"
env:
- CGO_ENABLED=1
- CC=x86_64-w64-mingw32-gcc
- CXX=x86_64-w64-mingw32-g++
flags:
- -tags
- sqlite
goos:
- windows
goarch:
- amd64
- id: pop_windows_i686
binary: soda
main: soda/main.go
ldflags:
- "-extldflags '-static'"
env:
- CGO_ENABLED=1
- CC=i686-w64-mingw32-gcc
- CXX=i686-w64-mingw32-g++
flags:
- -tags
- sqlite
goos:
- windows
goarch:
- 386

- id: pop_windows_x64
binary: soda
main: soda/main.go
ldflags:
- "-extldflags '-static'"
env:
- CGO_ENABLED=1
- CC=x86_64-w64-mingw32-gcc
- CXX=x86_64-w64-mingw32-g++
flags:
- -tags
- sqlite
goos:
- windows
goarch:
- amd64

archives:
-
format_overrides:
- format_overrides:
- goos: windows
format: zip

Expand All @@ -88,8 +107,7 @@ changelog:
- '^test:'

brews:
-
name: 'pop'
- name: 'pop'
tap:
owner: gobuffalo
name: homebrew-tap
Expand Down
41 changes: 40 additions & 1 deletion Makefile
@@ -1,3 +1,6 @@
PACKAGE_NAME := github.com/gobuffalo/pop
GOLANG_CROSS_VERSION ?= v1.17.6

TAGS ?= "sqlite"
GO_BIN ?= go

Expand Down Expand Up @@ -37,5 +40,41 @@ endif
release-test:
./test.sh

.PHONY: sysroot-pack
sysroot-pack:
@tar cf - $(SYSROOT_DIR) -P | pv -s $[$(du -sk $(SYSROOT_DIR) | awk '{print $1}') * 1024] | pbzip2 > $(SYSROOT_ARCHIVE)

.PHONY: sysroot-unpack
sysroot-unpack:
@pv $(SYSROOT_ARCHIVE) | pbzip2 -cd | tar -xf -
Comment on lines +43 to +49
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't see anywhere that these functions are explicitly used, they just came from https://github.com/goreleaser/goreleaser-cross-example/blob/master/Makefile#L7-L13. These could probably be removed.


.PHONY: release-dry-run
release-dry-run:
@docker run \
--rm \
--privileged \
-e CGO_ENABLED=1 \
-v /var/run/docker.sock:/var/run/docker.sock \
-v `pwd`:/go/src/$(PACKAGE_NAME) \
-v `pwd`/sysroot:/sysroot \
-w /go/src/$(PACKAGE_NAME) \
goreleaser/goreleaser-cross:${GOLANG_CROSS_VERSION} \
--rm-dist --skip-validate --skip-publish --snapshot
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When I was running without --snapshot goreleaser was complaining about not having tags available.


.PHONY: release
release:
release -y -f soda/cmd/version.go
@if [ ! -f ".release-env" ]; then \
echo "\033[91m.release-env is required for release\033[0m";\
exit 1;\
fi
docker run \
--rm \
--privileged \
-e CGO_ENABLED=1 \
--env-file .release-env \
-v /var/run/docker.sock:/var/run/docker.sock \
-v `pwd`:/go/src/$(PACKAGE_NAME) \
-v `pwd`/sysroot:/sysroot \
-w /go/src/$(PACKAGE_NAME) \
goreleaser/goreleaser-cross:${GOLANG_CROSS_VERSION} \
release --rm-dist
4 changes: 4 additions & 0 deletions associations/association.go
Expand Up @@ -160,5 +160,9 @@ func fieldIsNil(f reflect.Value) bool {

// IsZeroOfUnderlyingType will check if the value of anything is the equal to the Zero value of that type.
func IsZeroOfUnderlyingType(x interface{}) bool {
if x == nil {
return true
}

return reflect.DeepEqual(x, reflect.Zero(reflect.TypeOf(x)).Interface())
}
37 changes: 37 additions & 0 deletions associations/association_test.go
@@ -0,0 +1,37 @@
package associations

import (
"database/sql"
"fmt"
"github.com/gobuffalo/nulls"
"github.com/gofrs/uuid"
"github.com/stretchr/testify/assert"
"testing"
)

func Test_IsZeroOfUnderlyingType(t *testing.T) {
for k, tc := range []struct {
in interface{}
zero bool
}{
{in: nil, zero: true},
{in: 0, zero: true},
{in: 1, zero: false},
{in: false, zero: true},
{in: "", zero: true},
{in: interface{}(nil), zero: true},
{in: uuid.NullUUID{}, zero: true},
{in: uuid.UUID{}, zero: true},
{in: uuid.NullUUID{Valid: true}, zero: false},
{in: nulls.Int{}, zero: true},
{in: nulls.String{}, zero: true},
{in: nulls.Bool{}, zero: true},
{in: nulls.Float64{}, zero: true},
{in: sql.NullString{}, zero: true},
{in: sql.NullString{Valid: true}, zero: false},
} {
t.Run(fmt.Sprintf("case=%d", k), func(t *testing.T) {
assert.EqualValues(t, tc.zero, IsZeroOfUnderlyingType(tc.in))
})
}
}
13 changes: 11 additions & 2 deletions associations/associations_for_struct.go
@@ -1,7 +1,6 @@
package associations

import (
"errors"
"fmt"
"reflect"
"regexp"
Expand Down Expand Up @@ -30,7 +29,7 @@ var associationBuilders = map[string]associationBuilder{}
func ForStruct(s interface{}, fields ...string) (Associations, error) {
t, v := getModelDefinition(s)
if t.Kind() != reflect.Struct {
return nil, errors.New("could not get struct associations: not a struct")
return nil, fmt.Errorf("could not get struct associations: not a struct but %T", s)
}
fields = trimFields(fields)
associations := Associations{}
Expand Down Expand Up @@ -73,6 +72,16 @@ func ForStruct(s interface{}, fields ...string) (Associations, error) {
for i := 0; i < t.NumField(); i++ {
f := t.Field(i)

// inline embedded field
if f.Anonymous {
innerAssociations, err := ForStruct(v.Field(i).Interface(), fields...)
if err != nil {
return nil, err
}
associations = append(associations, innerAssociations...)
continue
}

// ignores those fields not included in fields list.
if len(fields) > 0 && fieldIgnoredIn(fields, f.Name) {
continue
Expand Down
21 changes: 14 additions & 7 deletions associations/belongs_to_association.go
Expand Up @@ -128,15 +128,22 @@ func (b *belongsToAssociation) BeforeInterface() interface{} {

func (b *belongsToAssociation) BeforeSetup() error {
ownerID := reflect.Indirect(reflect.ValueOf(b.ownerModel.Interface())).FieldByName("ID")
if b.ownerID.CanSet() {
if n := nulls.New(b.ownerID.Interface()); n != nil {
b.ownerID.Set(reflect.ValueOf(n.Parse(ownerID.Interface())))
} else if b.ownerID.Kind() == reflect.Ptr {
b.ownerID.Set(ownerID.Addr())
toSet := b.ownerID
switch b.ownerID.Type().Name() {
case "NullUUID":
b.ownerID.FieldByName("Valid").Set(reflect.ValueOf(true))
toSet = b.ownerID.FieldByName("UUID")
}

if toSet.CanSet() {
if n := nulls.New(toSet.Interface()); n != nil {
toSet.Set(reflect.ValueOf(n.Parse(ownerID.Interface())))
} else if toSet.Kind() == reflect.Ptr {
toSet.Set(ownerID.Addr())
} else {
b.ownerID.Set(ownerID)
toSet.Set(ownerID)
}
return nil
}
return fmt.Errorf("could not set '%s' to '%s'", ownerID, b.ownerID)
return fmt.Errorf("could not set '%s' to '%s'", ownerID, toSet)
}
19 changes: 19 additions & 0 deletions associations/belongs_to_association_test.go
Expand Up @@ -22,6 +22,11 @@ type barBelongsTo struct {
Foo fooBelongsTo `belongs_to:"foo"`
}

type barBelongsToNullable struct {
FooID uuid.NullUUID `db:"foo_id"`
Foo *fooBelongsTo `belongs_to:"foo"`
}

func Test_Belongs_To_Association(t *testing.T) {
a := require.New(t)

Expand Down Expand Up @@ -50,3 +55,17 @@ func Test_Belongs_To_Association(t *testing.T) {
a.Equal(nil, before[index].BeforeInterface())
}
}

func Test_Belongs_To_Nullable_Association(t *testing.T) {
a := require.New(t)
id, _ := uuid.NewV1()

bar := barBelongsToNullable{Foo: &fooBelongsTo{id}}
as, err := associations.ForStruct(&bar, "Foo")
a.NoError(err)

before := as.AssociationsBeforeCreatable()
for index := range before {
a.Equal(nil, before[index].BeforeSetup())
}
}