Skip to content

Commit 9bc97a5

Browse files
karalabefjl
authored andcommitted
build: NSIS based Windows installer (ethereum#3240)
This commit adds support for creating Windows installers to ci.go
1 parent 6707f70 commit 9bc97a5

9 files changed

+632
-9
lines changed

appveyor.yml

+9-8
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,40 @@
11
os: Visual Studio 2015
22

33
# Clone directly into GOPATH.
4-
clone_folder: c:\gopath\src\github.com\ethereum\go-ethereum
4+
clone_folder: C:\gopath\src\github.com\ethereum\go-ethereum
55
clone_depth: 5
66
version: "{branch}.{build}"
77
environment:
88
global:
9-
GOPATH: c:\gopath
9+
GOPATH: C:\gopath
1010
CC: gcc.exe
1111
matrix:
1212
- GETH_ARCH: amd64
1313
MSYS2_ARCH: x86_64
1414
MSYS2_BITS: 64
1515
MSYSTEM: MINGW64
16-
PATH: C:\msys64\mingw64\bin\;%PATH%
16+
PATH: C:\msys64\mingw64\bin\;C:\Program Files (x86)\NSIS\;%PATH%
1717
- GETH_ARCH: 386
1818
MSYS2_ARCH: i686
1919
MSYS2_BITS: 32
2020
MSYSTEM: MINGW32
21-
PATH: C:\msys64\mingw32\bin\;%PATH%
21+
PATH: C:\msys64\mingw32\bin\;C:\Program Files (x86)\NSIS\;%PATH%
2222

2323
install:
24-
- rmdir c:\go /s /q
24+
- rmdir C:\go /s /q
2525
- appveyor DownloadFile https://storage.googleapis.com/golang/go1.7.3.windows-amd64.zip
2626
- 7z x go1.7.3.windows-amd64.zip -y -oC:\ > NUL
2727
- go version
2828
- gcc --version
2929

3030
build_script:
31-
- go run build\\ci.go install -arch %GETH_ARCH%
31+
- go run build\ci.go install -arch %GETH_ARCH%
3232

3333
after_build:
34-
- go run build\\ci.go archive -arch %GETH_ARCH% -type zip -signer WINDOWS_SIGNING_KEY -upload gethstore/builds
34+
- go run build\ci.go archive -arch %GETH_ARCH% -type zip -signer WINDOWS_SIGNING_KEY -upload gethstore/builds
35+
- go run build\ci.go nsis -arch %GETH_ARCH% -signer WINDOWS_SIGNING_KEY -upload gethstore/builds
3536

3637
test_script:
3738
- set GOARCH=%GETH_ARCH%
3839
- set CGO_ENABLED=1
39-
- go run build\\ci.go test -vet -coverage
40+
- go run build\ci.go test -vet -coverage

build/ci.go

+74-1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ Available commands are:
2828
archive [-arch architecture] [ -type zip|tar ] [ -signer key-envvar ] [ -upload dest ] -- archives build artefacts
2929
importkeys -- imports signing keys from env
3030
debsrc [ -signer key-id ] [ -upload dest ] -- creates a debian source package
31+
nsis -- creates a Windows NSIS installer
3132
xgo [ options ] -- cross builds according to options
3233
3334
For all commands, -n prevents execution of external programs (dry run mode).
@@ -122,6 +123,8 @@ func main() {
122123
doArchive(os.Args[2:])
123124
case "debsrc":
124125
doDebianSource(os.Args[2:])
126+
case "nsis":
127+
doWindowsInstaller(os.Args[2:])
125128
case "xgo":
126129
doXgo(os.Args[2:])
127130
default:
@@ -429,7 +432,7 @@ func makeWorkdir(wdflag string) string {
429432
if wdflag != "" {
430433
err = os.MkdirAll(wdflag, 0744)
431434
} else {
432-
wdflag, err = ioutil.TempDir("", "eth-deb-build-")
435+
wdflag, err = ioutil.TempDir("", "geth-build-")
433436
}
434437
if err != nil {
435438
log.Fatal(err)
@@ -559,6 +562,76 @@ func stageDebianSource(tmpdir string, meta debMetadata) (pkgdir string) {
559562
return pkgdir
560563
}
561564

565+
// Windows installer
566+
567+
func doWindowsInstaller(cmdline []string) {
568+
// Parse the flags and make skip installer generation on PRs
569+
var (
570+
arch = flag.String("arch", runtime.GOARCH, "Architecture for cross build packaging")
571+
signer = flag.String("signer", "", `Environment variable holding the signing key (e.g. WINDOWS_SIGNING_KEY)`)
572+
upload = flag.String("upload", "", `Destination to upload the archives (usually "gethstore/builds")`)
573+
workdir = flag.String("workdir", "", `Output directory for packages (uses temp dir if unset)`)
574+
)
575+
flag.CommandLine.Parse(cmdline)
576+
*workdir = makeWorkdir(*workdir)
577+
env := build.Env()
578+
maybeSkipArchive(env)
579+
580+
// Aggregate binaries that are included in the installer
581+
var (
582+
devTools []string
583+
allTools []string
584+
gethTool string
585+
)
586+
for _, file := range allToolsArchiveFiles {
587+
if file == "COPYING" { // license, copied later
588+
continue
589+
}
590+
allTools = append(allTools, filepath.Base(file))
591+
if filepath.Base(file) == "geth.exe" {
592+
gethTool = file
593+
} else {
594+
devTools = append(devTools, file)
595+
}
596+
}
597+
598+
// Render NSIS scripts: Installer NSIS contains two installer sections,
599+
// first section contains the geth binary, second section holds the dev tools.
600+
templateData := map[string]interface{}{
601+
"License": "COPYING",
602+
"Geth": gethTool,
603+
"DevTools": devTools,
604+
}
605+
build.Render("build/nsis.geth.nsi", filepath.Join(*workdir, "geth.nsi"), 0644, nil)
606+
build.Render("build/nsis.install.nsh", filepath.Join(*workdir, "install.nsh"), 0644, templateData)
607+
build.Render("build/nsis.uninstall.nsh", filepath.Join(*workdir, "uninstall.nsh"), 0644, allTools)
608+
build.Render("build/nsis.envvarupdate.nsh", filepath.Join(*workdir, "EnvVarUpdate.nsh"), 0644, nil)
609+
build.CopyFile(filepath.Join(*workdir, "SimpleFC.dll"), "build/nsis.simplefc.dll", 0755)
610+
build.CopyFile(filepath.Join(*workdir, "COPYING"), "COPYING", 0755)
611+
612+
// Build the installer. This assumes that all the needed files have been previously
613+
// built (don't mix building and packaging to keep cross compilation complexity to a
614+
// minimum).
615+
version := strings.Split(build.VERSION(), ".")
616+
if env.Commit != "" {
617+
version[2] += "-" + env.Commit[:8]
618+
}
619+
installer, _ := filepath.Abs("geth-" + archiveBasename(*arch, env) + ".exe")
620+
build.MustRunCommand("makensis.exe",
621+
"/DOUTPUTFILE="+installer,
622+
"/DMAJORVERSION="+version[0],
623+
"/DMINORVERSION="+version[1],
624+
"/DBUILDVERSION="+version[2],
625+
"/DARCH="+*arch,
626+
filepath.Join(*workdir, "geth.nsi"),
627+
)
628+
629+
// Sign and publish installer.
630+
if err := archiveUpload(installer, *upload, *signer); err != nil {
631+
log.Fatal(err)
632+
}
633+
}
634+
562635
// Cross compilation
563636

564637
func doXgo(cmdline []string) {

0 commit comments

Comments
 (0)