Skip to content

Commit

Permalink
fix: include {arch} in default -o filename
Browse files Browse the repository at this point in the history
This was a recommended way to use rsrc for long time, but never made default
nor explained anywhere (other than in github issues). Given that I'm fixing
some bugs anyway in rsrc now, let's use this time to also make this more user
friendly.
  • Loading branch information
akavel committed Dec 10, 2020
1 parent c549a91 commit 4ff63ad
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 7 deletions.
4 changes: 2 additions & 2 deletions README.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ INSTALL: go get github.com/akavel/rsrc

USAGE:

rsrc.exe [-manifest FILE.exe.manifest] [-ico FILE.ico[,FILE2.ico...]] -o FILE.syso
rsrc.exe [-manifest FILE.exe.manifest] [-ico FILE.ico[,FILE2.ico...]] [OPTIONS...]
Generates a .syso file with specified resources embedded in .rsrc section,
aimed for consumption by Go linker when building Win32 excecutables.

Expand All @@ -20,7 +20,7 @@ OPTIONS:
-manifest string
path to a Windows manifest file to embed
-o string
name of output COFF (.res or .syso) file (default "rsrc.syso")
name of output COFF (.res or .syso) file; if set to empty, will default to 'rsrc_windows_{arch}.syso'

Based on ideas presented by Minux.

Expand Down
9 changes: 6 additions & 3 deletions rsrc.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (

var usage = `USAGE:
%s [-manifest FILE.exe.manifest] [-ico FILE.ico[,FILE2.ico...]] -o FILE.syso
%s [-manifest FILE.exe.manifest] [-ico FILE.ico[,FILE2.ico...]] [OPTIONS...]
Generates a .syso file with specified resources embedded in .rsrc section,
aimed for consumption by Go linker when building Win32 excecutables.
Expand All @@ -28,17 +28,20 @@ func main() {
flags := flag.NewFlagSet("", flag.ExitOnError)
flags.StringVar(&fnamein, "manifest", "", "path to a Windows manifest file to embed")
flags.StringVar(&fnameico, "ico", "", "comma-separated list of paths to .ico files to embed")
flags.StringVar(&fnameout, "o", "rsrc.syso", "name of output COFF (.res or .syso) file")
flags.StringVar(&fnameout, "o", "", "name of output COFF (.res or .syso) file; if set to empty, will default to 'rsrc_windows_{arch}.syso'")
flags.StringVar(&arch, "arch", "386", "architecture of output file - one of: 386, amd64, [EXPERIMENTAL: arm, arm64]")
flags.Usage = func() {
fmt.Fprintf(os.Stderr, usage, os.Args[0])
flags.PrintDefaults()
}
_ = flags.Parse(os.Args[1:])
if fnameout == "" || (fnamein == "" && fnameico == "") {
if fnamein == "" && fnameico == "" {
flags.Usage()
os.Exit(1)
}
if fnameout == "" {
fnameout = "rsrc_windows_" + arch + ".syso"
}

err := rsrc.Embed(fnameout, arch, fnamein, fnameico)
if err != nil {
Expand Down
10 changes: 8 additions & 2 deletions rsrc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"testing"
)

const name = "rsrc.syso"
const name = "rsrc_windows_amd64.syso"

func TestBuildSucceeds(t *testing.T) {
tests := []struct {
Expand All @@ -35,7 +35,7 @@ func TestBuildSucceeds(t *testing.T) {
// Compile icon/manifest in testdata/ dir
os.Stdout.Write([]byte("-- compiling resource(s)...\n"))
defer os.Remove(filepath.Join(dir, name))
cmd := exec.Command("go", "run", "../rsrc.go", "-arch", "amd64", "-o", name)
cmd := exec.Command("go", "run", "../rsrc.go", "-arch", "amd64")
cmd.Args = append(cmd.Args, tt.args...)
cmd.Dir = dir
cmd.Stdout = os.Stdout
Expand All @@ -45,6 +45,12 @@ func TestBuildSucceeds(t *testing.T) {
t.Fatal(err)
}

// Verify if a .syso file with default name was created
_, err = os.Stat(filepath.Join(dir, name))
if err != nil {
t.Fatal(err)
}

defer os.Setenv("GOOS", os.Getenv("GOOS"))
defer os.Setenv("GOARCH", os.Getenv("GOARCH"))
os.Setenv("GOOS", "windows")
Expand Down

0 comments on commit 4ff63ad

Please sign in to comment.