Skip to content

Commit

Permalink
desktop/windows: add single-line build script
Browse files Browse the repository at this point in the history
This gives us a single-line command that can be run from a Windows build
machine to create a signed installer binary:

    $CHAIN/desktop/windows/build /path/to/signing.key signingKeyPassword

Closes #1343
  • Loading branch information
jeffomatic authored and iampogo committed Jun 15, 2017
1 parent 6d39296 commit 147f205
Show file tree
Hide file tree
Showing 9 changed files with 142 additions and 50 deletions.
1 change: 1 addition & 0 deletions bin/build-cored-release
Expand Up @@ -37,6 +37,7 @@ mkdir -p $newChain
git clone $CHAIN $newChain
cd $newChain
git checkout $releaseRef
cd - # on some platforms (e.g. Windows), the cleanup trap cannot proceed unless we navigate away from the tempdir

# Cross-compilation args for cored and corectl
export CGO_ENABLED=0 # There are issues with cgo (e.g. https://github.com/lib/pq/issues/395), so disable it entirely.
Expand Down
1 change: 1 addition & 0 deletions desktop/windows/.gitignore
Expand Up @@ -8,3 +8,4 @@ ChainBundle/bin/
ChainBundle/obj/
ChainPackage/bin/
ChainBundle/obj/
build/
105 changes: 82 additions & 23 deletions desktop/windows/README.md
Expand Up @@ -5,9 +5,88 @@
To install Chain Core Developer Edition for Windows, please visit [our downloads page](https://chain.com/docs/core/get-started/install).

## Building the Windows installer
The following instructions describe how to build the Windows installer from source:

### Dependencies
There are two workflows for building the Windows installer:

- [Automated workflow](#automated-workflow): 99% of the time, this is what you want.
- [Manual workflow](#manual-workflow): when you want to understand what's going on.

### Automated workflow

### Setup

#### System commands

You should prepare your build machine with the following system tools. Most or all are available via [scoop](http://scoop.sh/):

- Go 1.8: `scoop install go`
- Git: `scoop install git`
- msys: `scoop install msys`
- curl: `scoop install curl`

#### Installers

Download and run the following installers:

- [Wix Toolset](https://s3.amazonaws.com/chain-engineering-internal/windows-build-deps/tools/wix311.exe)
- [Windows 10 SDK](https://developer.microsoft.com/windows/downloads/windows-10-sdk) (this provides `signtool`)

#### Programming environment

Set the following environment variables:

- `GOPATH`
- `CHAIN` (should be `$GOPATH/src/chain`)

Clone the source repository to `$CHAIN`:

```
git clone https://github.com/chain/chain.git %CHAIN%
```

#### Code-signing key

Ensure that your build machine has access to `csev.pfx`, the code-signing key. We recommend having this file available via USB.

### Build process

First, open a bash prompt via MSYS:

```
c:\MinGW\msys\msys.bat
```

It's useful to have a shortcut to this file on the desktop.

Navigate to `$CHAIN`:

```
cd $CHAIN
```

Check out the gitref you'd like to build:

```
git checkout chain-core-windows-1.2.1
```

Run the build script:

```
./desktop/windows/bin/build /path/to/csev.pfx signingKeyPassword
```

This will generate a new installer binary at `$CHAIN/desktop/windows/build/ChainBundle/Chain_Core_Latest.exe`.

You can change the filename from `Chain_Core_Latest.exe` to `Chain_Core_<version>.exe` by adding a third parameter:

```
./desktop/windows/bin/build /path/to/csev.pfx signingKeyPassword 1.2.1
```

### Manual workflow

#### Dependencies

These instructions assume that your PATH includes the wix tools binary. My wix tools binary is located at `C:\Program Files (x86)\WiX Toolset v3.10\bin`.

Expand Down Expand Up @@ -47,27 +126,7 @@ The VC++ Redistributable can be downloaded from https://www.microsoft.com/en-us/

Make sure you have the 64-bit versions. Chain Core Windows does not support 32-bit. Do not actually run these installers, just provide them.

### Using the build script

Run `buildChainExe.bat` to compile a signed Chain Core Windows installer. The
batch file takes three required positional arguments, and an optional
third argument:

1. The path to your `.pfx` certificate.
2. The password for the above certificate.
3. The version label of the Chain Core executable (optional, defaults to "Latest").

`buildChainExe.bat` must be run from inside the `desktop/windows` directory.

Example usage:

```
buildChainExe.bat Z:\path\to\cert my-strong-password 1.1.0
```

The resulting binary will be available at `ChainBundle/Chain_Core_[your-version].exe`.

### Manual
#### Build process

🚧 Hang on. Only go down here if you know what you're doing. The above script
runs exactly these instructions. 🚧
Expand Down
54 changes: 54 additions & 0 deletions desktop/windows/bin/build
@@ -0,0 +1,54 @@
#!/usr/bin/env bash
set -e

buildDir=$CHAIN/desktop/windows/build
rm -rf $buildDir
mkdir -p $buildDir

$CHAIN/bin/build-cored-release chain-core-server-1.2.0 $buildDir
mv $buildDir/cored $buildDir/cored.exe
rm $buildDir/corectl

echo "Building ChaingMgr..."
mkdir $buildDir/ChainMgr
go build -o $buildDir/ChainMgr/ChainMgr.exe chain/desktop/windows/ChainMgr

cp -R $CHAIN/desktop/windows/ChainBundle $buildDir/ChainBundle
cp -R $CHAIN/desktop/windows/ChainPackage $buildDir/ChainPackage

echo "Downloading install-time dependencies..."
mkdir $buildDir/Postgres
curl https://s3.amazonaws.com/chain-engineering-internal/windows-build-deps/build-deps/postgresql-9.5.5-1-windows-x64.exe \
-s -o $buildDir/Postgres/postgresql-9.5.5-1-windows-x64.exe
curl https://s3.amazonaws.com/chain-engineering-internal/windows-build-deps/build-deps/vcredist_x64.exe \
-s -o $buildDir/Postgres/vcredist_x64.exe

certPath=$1
certPass=$2
version=${3:-"Latest"}

cd $buildDir

echo "Signing executables..."
signtool sign -v -f $certPath -p $certPass cored.exe
signtool sign -v -f $certPath -p $certPass ChainMgr/ChainMgr.exe

cd ChainPackage

echo "Building and signing ChainPackage..."
candle -ext WixHttpExtension -ext WixUtilExtension ChainCoreInstaller.wxs
light -ext WixHttpExtension -ext WixUtilExtension ChainCoreInstaller.wixobj
signtool sign -v -f $certPath -p $certPass cab1.cab

cd ../ChainBundle

echo "Building and signing installer executable..."
candle Bundle.wxs -arch x64 -ext WixBalExtension \
-dChainPackage.TargetPath="$buildDir\ChainPackage\ChainCoreInstaller.msi" \
-dPostgresPackage.TargetPath="$buildDir\Postgres\postgresql-9.5.5-1-windows-x64.exe" \
-dVCRPackage.TargetPath="$buildDir\Postgres\vcredist_x64.exe"
light Bundle.wixobj -ext WixBalExtension
insignia -ib Bundle.exe -o engine.exe
signtool sign -v -f $certPath -p $certPass engine.exe
insignia -ab engine.exe Bundle.exe -o Chain_Core_$version.exe -v
signtool sign -v -f $certPath -p $certPass Chain_Core_$version.exe
23 changes: 0 additions & 23 deletions desktop/windows/buildChainExe.bat

This file was deleted.

2 changes: 1 addition & 1 deletion generated/rev/RevId.java
@@ -1,4 +1,4 @@

public final class RevId {
public final String Id = "main/rev3246";
public final String Id = "main/rev3247";
}
2 changes: 1 addition & 1 deletion generated/rev/revid.go
@@ -1,3 +1,3 @@
package rev

const ID string = "main/rev3246"
const ID string = "main/rev3247"
2 changes: 1 addition & 1 deletion generated/rev/revid.js
@@ -1,2 +1,2 @@

export const rev_id = "main/rev3246"
export const rev_id = "main/rev3247"
2 changes: 1 addition & 1 deletion generated/rev/revid.rb
@@ -1,4 +1,4 @@

module Chain::Rev
ID = "main/rev3246".freeze
ID = "main/rev3247".freeze
end

0 comments on commit 147f205

Please sign in to comment.