在 Azure DevOps 的 Windows pipeline 中生成 Go 的 syso 文件的步骤
来源:stackoverflow
时间:2024-03-03 17:48:23 282浏览 收藏
偷偷努力,悄无声息地变强,然后惊艳所有人!哈哈,小伙伴们又来学习啦~今天我将给大家介绍《在 Azure DevOps 的 Windows pipeline 中生成 Go 的 syso 文件的步骤》,这篇文章主要会讲到等等知识点,不知道大家对其都有多少了解,下面我们就一起来看一吧!当然,非常希望大家能多多评论,给出合理的建议,我们一起学习,一起进步!
我想使用 go build
的 syso 文件为我的可执行文件设置图标。
在我的 win10 笔记本上一切正常,但是当我在 ubuntu-latest 或 windows-latest 中使用相同的 syso 文件(使用 git lfs 签入)时,我收到以下消息:
c:\users\vssadm~1\appdata\local\temp\go-build430615882\b001\_pkg_.a(rsrc.syso): not an object file ##[error]the go task failed with an error: error: the process 'c:\hostedtoolcache\windows\go\1.14.2\x64\bin\go.exe' failed with exit code 2
对于我的问题,如何在 azure devops 上的 windows pipline 中生成 go 的 syso 文件并将其与 go build
一起使用?
pool: vmImage: 'windows-2019' variables: GOBIN: '$(GOPATH)/bin' GOPATH: '$(system.DefaultWorkingDirectory)/gopath' ExecutableName: tool GoFilePath: '$(System.DefaultWorkingDirectory)/cmd/Tool/' steps: - task: GoTool@0 inputs: version: '1.14.2' - task: Go@0 inputs: command: 'get' arguments: '-d ./...' workingDirectory: '$(System.DefaultWorkingDirectory)' - task: PowerShell@2 displayName: Set last tag to variable inputs: targetType: 'inline' script: | $VERSION_TAG = git describe --tags (git rev-list --tags --max-count=1) Write-Host("##vso[task.setvariable variable=VERSION_TAG]$VERSION_TAG") Write-Host("##vso[build.addbuildtag]$VERSION_TAG") Write-Host($VERSION_TAG) - task: PowerShell@2 displayName: Set date to variable inputs: targetType: 'inline' script: | $DATE = Get-Date -Format "yyyy-MM-dd" Write-Host("##vso[task.setvariable variable=DATE]$DATE") - task: Go@0 displayName: 'Create release for windows x64' enabled: true env: GOOS: windows GOARCH: amd64 inputs: command: 'build' arguments: '-ldflags "-s -w -X main.Version=$(VERSION_TAG) -X main.BuildTime=$(DATE)" -trimpath -o release_build/$(ExecutableName).exe $(GoFilePath)' workingDirectory: '$(System.DefaultWorkingDirectory)' - task: Go@0 displayName: 'Create release for windows x86' enabled: true env: GOOS: windows GOARCH: 386 inputs: command: 'build' arguments: '-ldflags "-s -w -X main.Version=$(VERSION_TAG) -X main.BuildTime=$(DATE)" -trimpath -o release_build/$(ExecutableName)_x86.exe $(GoFilePath)' workingDirectory: '$(System.DefaultWorkingDirectory)' - task: Go@0 displayName: 'Create release for linux x64' enabled: true env: GOOS: linux GOARCH: amd64 inputs: command: 'build' arguments: '-ldflags "-s -w -X main.Version=$(VERSION_TAG) -X main.BuildTime=$(DATE)" -trimpath -o release_build/$(ExecutableName).bin $(GoFilePath)' workingDirectory: '$(System.DefaultWorkingDirectory)' - task: Go@0 displayName: 'Create release for linux x86' enabled: true env: GOOS: linux GOARCH: 386 inputs: command: 'build' arguments: '-ldflags "-s -w -X main.Version=$(VERSION_TAG) -X main.BuildTime=$(DATE)" -trimpath -o release_build/$(ExecutableName)_386.bin $(GoFilePath)' workingDirectory: '$(System.DefaultWorkingDirectory)' - task: Go@0 displayName: 'Create release for macOS x64' enabled: true env: GOOS: darwin GOARCH: amd64 inputs: command: 'build' arguments: '-ldflags "-s -w -X main.Version=$(VERSION_TAG) -X main.BuildTime=$(DATE)" -trimpath -o release_build/$(ExecutableName).app $(GoFilePath)' workingDirectory: '$(System.DefaultWorkingDirectory)' - task: CopyFiles@2 inputs: SourceFolder: '$(System.DefaultWorkingDirectory)/release_build' TargetFolder: '$(Build.ArtifactStagingDirectory)' - task: CopyFiles@2 inputs: SourceFolder: '$(System.DefaultWorkingDirectory)/docs' TargetFolder: '$(Build.ArtifactStagingDirectory)' - task: PublishBuildArtifacts@1 inputs: PathtoPublish: '$(Build.ArtifactStagingDirectory)' ArtifactName: 'Tool Executables'
解决方案
当我写这个问题时,我发现,我对这些文件使用 git lfs
。
添加此步骤后,我可以使用资源文件编译可执行文件。
steps: - checkout: self lfs: true
但是在针对 goos windows 进行构建之后,我必须删除这些文件,否则我会收到错误:
/opt/hostedtoolcache/go/1.14.2/x64/pkg/tool/linux_amd64/link: running gcc failed: exit status 1 /usr/bin/ld: i386 architecture of input file `/tmp/go-link-782633042/000000.o' is incompatible with i386:x86-64 output collect2: error: ld returned 1 exit status
删除这些文件的步骤:
- task: powershell@2 displayname: remove syso files inputs: targettype: 'inline' script: | remove-item $(system.defaultworkingdirectory)/cmd/analysetool/*.syso
说明
这是 v1 文本指针的示例:
version https://git-lfs.github.com/spec/v1 oid sha256:4d7a214614ab2935c943f9e0ff69d22eadbb8f32b1258daaa5e2ca24d17e2393 size 12345 (ending \n)
来源:https://github.com/git-lfs/git-lfs/blob/master/docs/spec.md
下载源代码时不支持 lfs,将放置此文本文件而不是真实文件。
很明显,该文件无法执行(错误的幻数)或者引用的 bin 文件格式错误(不是目标文件)。
今天关于《在 Azure DevOps 的 Windows pipeline 中生成 Go 的 syso 文件的步骤》的内容介绍就到此结束,如果有什么疑问或者建议,可以在golang学习网公众号下多多回复交流;文中若有不正之处,也希望回复留言以告知!
-
502 收藏
-
502 收藏
-
501 收藏
-
501 收藏
-
501 收藏
-
139 收藏
-
204 收藏
-
325 收藏
-
477 收藏
-
486 收藏
-
439 收藏
-
357 收藏
-
352 收藏
-
101 收藏
-
440 收藏
-
212 收藏
-
143 收藏
-
- 前端进阶之JavaScript设计模式
- 设计模式是开发人员在软件开发过程中面临一般问题时的解决方案,代表了最佳的实践。本课程的主打内容包括JS常见设计模式以及具体应用场景,打造一站式知识长龙服务,适合有JS基础的同学学习。
- 立即学习 542次学习
-
- GO语言核心编程课程
- 本课程采用真实案例,全面具体可落地,从理论到实践,一步一步将GO核心编程技术、编程思想、底层实现融会贯通,使学习者贴近时代脉搏,做IT互联网时代的弄潮儿。
- 立即学习 508次学习
-
- 简单聊聊mysql8与网络通信
- 如有问题加微信:Le-studyg;在课程中,我们将首先介绍MySQL8的新特性,包括性能优化、安全增强、新数据类型等,帮助学生快速熟悉MySQL8的最新功能。接着,我们将深入解析MySQL的网络通信机制,包括协议、连接管理、数据传输等,让
- 立即学习 497次学习
-
- JavaScript正则表达式基础与实战
- 在任何一门编程语言中,正则表达式,都是一项重要的知识,它提供了高效的字符串匹配与捕获机制,可以极大的简化程序设计。
- 立即学习 487次学习
-
- 从零制作响应式网站—Grid布局
- 本系列教程将展示从零制作一个假想的网络科技公司官网,分为导航,轮播,关于我们,成功案例,服务流程,团队介绍,数据部分,公司动态,底部信息等内容区块。网站整体采用CSSGrid布局,支持响应式,有流畅过渡和展现动画。
- 立即学习 484次学习