nonus25
nonus25

Reputation: 423

golang indirect require causes issues in Cloud function build for package golang.org/x/sys/unix

I am having a problem with deploying cloud function since one of my packages uses indirectly golang.org/x/sys

when using this version CF builds are passing any above seems to be failing

# golang.org/x/sys v0.0.0-20210119212857-b64e53b001e4

but after each run of go get -u ./... we are getting newer version and the CF build is failing with error

2022-10-02 09:03:07.208 CESTStep #1 - "build": # cloudfunctionissue/vendor/golang.org/x/sys/unix
2022-10-02 09:03:07.208 CESTStep #1 - "build": src/cloudfunctionissue/vendor/golang.org/x/sys/unix/syscall.go:83:16: undefined: unsafe.Slice
2022-10-02 09:03:07.208 CESTStep #1 - "build": src/cloudfunctionissue/vendor/golang.org/x/sys/unix/syscall_linux.go:2255:9: undefined: unsafe.Slice
2022-10-02 09:03:07.208 CESTStep #1 - "build": src/cloudfunctionissue/vendor/golang.org/x/sys/unix/syscall_unix.go:118:7: undefined: unsafe.Slice
2022-10-02 09:03:07.208 CESTStep #1 - "build": src/cloudfunctionissue/vendor/golang.org/x/sys/unix/sysvshm_unix.go:33:7: undefined: unsafe.Slice

seems this doc does not explain the problem enough for me https://cloud.google.com/functions/docs/writing/specifying-dependencies-go#using_a_vendor_directory

Upvotes: 0

Views: 371

Answers (2)

nonus25
nonus25

Reputation: 423

Thank you for your answer, and yes I agree with you that my issue come with newer version of go. However we found the work around to this problem by updating only packages which are imported directly, and skip the indirect updates.

#!/bin/sh  
module=$(go list -f '{{.Module.Path}}' .)

go mod tidy
go get -d -t $(go mod graph | grep "^$module" | cut -d ' ' -f 2 | sed 's/@.*/@upgrade/g')
go mod tidy
go mod download

after applying this script to dockerfile we are building our CF without of issues.

Upvotes: 1

Roopa M
Roopa M

Reputation: 3009

You are getting this error because of runtime. unsafe.Slice was introduced in go v1.17 but currently cloud functions support v1.16. Somehow your code invoked syscall.go:83.16 and other packages. Hence you are getting above error. Either try to revert back or determine what is invoking these packages.

Upvotes: 1

Related Questions