- Notifications
You must be signed in to change notification settings - Fork928
feat: include winres metadata in Windows binaries#16706
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Merged
Uh oh!
There was an error while loading.Please reload this page.
Merged
Changes from1 commit
Commits
Show all changes
6 commits Select commitHold shift + click to select a range
85e2a6a
feat: include winres metadata in Windows binaries
deansheatherd2c54b3
test CI
deansheathercf9fc04
fix: add permission for gcloud auth
deansheather970bf8a
test CI 2
deansheather35dc760
Revert "test CI 2"
deansheather5d9c439
Revert "test CI"
deansheatherFile filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
48 changes: 46 additions & 2 deletions.github/workflows/ci.yaml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
28 changes: 16 additions & 12 deletions.github/workflows/release.yaml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletionsbuildinfo/resources/.gitignore
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
*.syso |
8 changes: 8 additions & 0 deletionsbuildinfo/resources/resources.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
// This package is used for embedding .syso resource files into the binary | ||
// during build and does not contain any code. During build, .syso files will be | ||
// dropped in this directory and then removed after the build completes. | ||
// | ||
// This package must be imported by all binaries for this to work. | ||
// | ||
// See build_go.sh for more details. | ||
package resources |
1 change: 1 addition & 0 deletionscmd/coder/main.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletionsenterprise/cmd/coder/main.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
114 changes: 108 additions & 6 deletionsscripts/build_go.sh
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -36,17 +36,19 @@ source "$(dirname "${BASH_SOURCE[0]}")/lib.sh" | ||
version="" | ||
os="${GOOS:-linux}" | ||
arch="${GOARCH:-amd64}" | ||
output_path="" | ||
slim="${CODER_SLIM_BUILD:-0}" | ||
agpl="${CODER_BUILD_AGPL:-0}" | ||
sign_darwin="${CODER_SIGN_DARWIN:-0}" | ||
sign_windows="${CODER_SIGN_WINDOWS:-0}" | ||
boringcrypto=${CODER_BUILD_BORINGCRYPTO:-0} | ||
dylib=0 | ||
windows_resources="${CODER_WINDOWS_RESOURCES:-0}" | ||
debug=0 | ||
bin_ident="com.coder.cli" | ||
args="$(getopt -o "" -l version:,os:,arch:,output:,slim,agpl,sign-darwin,sign-windows,boringcrypto,dylib,windows-resources,debug -- "$@")" | ||
eval set -- "$args" | ||
while true; do | ||
case "$1" in | ||
@@ -79,6 +81,10 @@ while true; do | ||
sign_darwin=1 | ||
shift | ||
;; | ||
--sign-windows) | ||
sign_windows=1 | ||
shift | ||
;; | ||
ethanndickson marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
--boringcrypto) | ||
boringcrypto=1 | ||
shift | ||
@@ -87,6 +93,10 @@ while true; do | ||
dylib=1 | ||
shift | ||
;; | ||
--windows-resources) | ||
windows_resources=1 | ||
shift | ||
;; | ||
--debug) | ||
debug=1 | ||
shift | ||
@@ -115,11 +125,13 @@ if [[ "$sign_darwin" == 1 ]]; then | ||
dependencies rcodesign | ||
requiredenvs AC_CERTIFICATE_FILE AC_CERTIFICATE_PASSWORD_FILE | ||
fi | ||
if [[ "$sign_windows" == 1 ]]; then | ||
dependencies java | ||
requiredenvs JSIGN_PATH EV_KEYSTORE EV_KEY EV_CERTIFICATE_PATH EV_TSA_URL GCLOUD_ACCESS_TOKEN | ||
fi | ||
if [[ "$windows_resources" == 1 ]]; then | ||
dependencies go-winres | ||
fi | ||
ldflags=( | ||
-X "'github.com/coder/coder/v2/buildinfo.tag=$version'" | ||
@@ -204,10 +216,100 @@ if [[ "$boringcrypto" == 1 ]]; then | ||
goexp="boringcrypto" | ||
fi | ||
# On Windows, we use go-winres to embed the resources into the binary. | ||
if [[ "$windows_resources" == 1 ]] && [[ "$os" == "windows" ]]; then | ||
# Convert the version to a format that Windows understands. | ||
# Remove any trailing data after a "+" or "-". | ||
version_windows=$version | ||
version_windows="${version_windows%+*}" | ||
version_windows="${version_windows%-*}" | ||
# If there wasn't any extra data, add a .0 to the version. Otherwise, add | ||
# a .1 to the version to signify that this is not a release build so it can | ||
# be distinguished from a release build. | ||
non_release_build=0 | ||
if [[ "$version_windows" == "$version" ]]; then | ||
version_windows+=".0" | ||
else | ||
version_windows+=".1" | ||
non_release_build=1 | ||
fi | ||
if [[ ! "$version_windows" =~ ^[0-9]+\.[0-9]+\.[0-9]+\.[0-1]$ ]]; then | ||
error "Computed invalid windows version format: $version_windows" | ||
fi | ||
# File description changes based on slimness, AGPL status, and architecture. | ||
file_description="Coder" | ||
if [[ "$agpl" == 1 ]]; then | ||
file_description+=" AGPL" | ||
fi | ||
if [[ "$slim" == 1 ]]; then | ||
file_description+=" CLI" | ||
fi | ||
if [[ "$non_release_build" == 1 ]]; then | ||
file_description+=" (development build)" | ||
fi | ||
# Because this writes to a file with the OS and arch in the filename, we | ||
# don't support concurrent builds for the same OS and arch (irregardless of | ||
# slimness or AGPL status). | ||
# | ||
# This is fine since we only embed resources during dogfood and release | ||
# builds, which use make (which will build all slim targets in parallel, | ||
# then all non-slim targets in parallel). | ||
expected_rsrc_file="./buildinfo/resources/resources_windows_${arch}.syso" | ||
if [[ -f "$expected_rsrc_file" ]]; then | ||
rm "$expected_rsrc_file" | ||
fi | ||
touch "$expected_rsrc_file" | ||
pushd ./buildinfo/resources | ||
GOARCH="$arch" go-winres simply \ | ||
--arch "$arch" \ | ||
--out "resources" \ | ||
--product-version "$version_windows" \ | ||
--file-version "$version_windows" \ | ||
--manifest "cli" \ | ||
--file-description "$file_description" \ | ||
--product-name "Coder" \ | ||
--copyright "Copyright $(date +%Y) Coder Technologies Inc." \ | ||
--original-filename "coder.exe" \ | ||
--icon ../../scripts/win-installer/coder.ico | ||
popd | ||
if [[ ! -f "$expected_rsrc_file" ]]; then | ||
error "Failed to generate $expected_rsrc_file" | ||
fi | ||
fi | ||
set +e | ||
GOEXPERIMENT="$goexp" CGO_ENABLED="$cgo" GOOS="$os" GOARCH="$arch" GOARM="$arm_version" \ | ||
go build \ | ||
"${build_args[@]}" \ | ||
"$cmd_path" 1>&2 | ||
exit_code=$? | ||
set -e | ||
# Clean up the resources file if it was generated. | ||
if [[ "$windows_resources" == 1 ]] && [[ "$os" == "windows" ]]; then | ||
rm "$expected_rsrc_file" | ||
ethanndickson marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
fi | ||
if [[ "$exit_code" != 0 ]]; then | ||
exit "$exit_code" | ||
fi | ||
# If we did embed resources, verify that they were included. | ||
if [[ "$windows_resources" == 1 ]] && [[ "$os" == "windows" ]]; then | ||
winres_dir=$(mktemp -d) | ||
if ! go-winres extract --dir "$winres_dir" "$output_path" 1>&2; then | ||
rm -rf "$winres_dir" | ||
error "Compiled binary does not contain embedded resources" | ||
fi | ||
# If go-winres didn't return an error, it means it did find embedded | ||
# resources. | ||
rm -rf "$winres_dir" | ||
fi | ||
if [[ "$sign_darwin" == 1 ]] && [[ "$os" == "darwin" ]]; then | ||
execrelative ./sign_darwin.sh "$output_path" "$bin_ident" 1>&2 | ||
Oops, something went wrong.
Uh oh!
There was an error while loading.Please reload this page.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.