英文:
golang indirect require causes issues in Cloud function build for package golang.org/x/sys/unix
问题
我在部署云函数时遇到了问题,因为我的一个包间接使用了golang.org/x/sys
。
当使用以下版本时,云函数构建通过,但似乎以上版本都会失败:
# golang.org/x/sys v0.0.0-20210119212857-b64e53b001e4
但是,在每次运行go get -u ./...
之后,我们都会得到更新的版本,并且云函数构建会失败并显示错误:
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
似乎这篇文档没有足够解释问题的内容:https://cloud.google.com/functions/docs/writing/specifying-dependencies-go#using_a_vendor_directory
英文:
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
答案1
得分: 1
您之所以遇到这个错误是因为运行时问题。unsafe.Slice 是在 go v1.17
中引入的,但当前 云函数支持 v1.16
。不知何故,您的代码调用了 syscall.go:83.16 和其他包。因此,您会遇到上述错误。要么尝试回退版本,要么确定是什么在调用这些包。
英文:
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.
答案2
得分: 1
感谢您的回答,是的,我同意您的观点,我的问题确实与较新版本的Go有关。然而,我们找到了解决这个问题的方法,只更新直接导入的包,跳过间接的更新。
#!/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
将此脚本应用于Dockerfile后,我们构建的CF没有任何问题。
英文:
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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论