Skip to content

Commit

Permalink
Merge pull request #9 from getlantern/2105
Browse files Browse the repository at this point in the history
getlantern/lantern#2105 crosscompile now uses tag for latest commit id i...
  • Loading branch information
aranhoide committed Dec 21, 2014
2 parents d57ae91 + 04d7cfe commit ffa3a61
Show file tree
Hide file tree
Showing 6 changed files with 102 additions and 81 deletions.
79 changes: 79 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,82 @@ flashlight-build [![Travis CI Status](https://travis-ci.org/getlantern/flashligh
flashlight-build is a [gost](https://github.com/getlantern/gost) project that
provides repeatable builds and consolidated pull requests for flashlight.

### Building Flashlight

Flashlight requires [Go 1.3.x](http://golang.org/dl/).

It is convenient to build flashlight for multiple platforms using
[gox](https://github.com/mitchellh/gox).

The typical cross-compilation setup doesn't work for anything that uses C code,
which includes the DNS resolution code and some other things. See
[this blog](https://inconshreveable.com/04-30-2014/cross-compiling-golang-programs-with-native-libraries/)
for more discussion.

To deal with that, you need to use a Go installed using
[gonative](https://github.com/getlantern/gonative). Ultimately, you can put this
go wherever you like. Ox keeps his at ~/go_native.

```bash
go get github.com/mitchellh/gox
go get github.com/getlantern/gonative
cd ~
gonative -version="1.3.3" -platforms="darwin_amd64 linux_386 linux_amd64 windows_386"
mv go go_native
```

Finally update your GOROOT and PATH to point at `~/go_native` instead of your
previous go installation. They should look something like this:

```bash
➜ flashlight git:(1606) ✗ echo $GOROOT
/Users/ox.to.a.cart//go_native
➜ flashlight git:(1606) ✗ which go
/Users/ox.to.a.cart//go_native/bin/go
```

Now that you have go and gox set up, the binaries used for Lantern can be built
with the `./crosscompile.bash` script. This script also sets the version of
flashlight to the most recent commit id in git, or if the most recent commit is
tagged, the tag of that commit id.

An annotated tag can be added like this:

```bash
git tag -a v1.0.0 -m"Tagged 1.0.0"
git push --tags
```

The script `tagandbuild.bash` tags and runs crosscompile.bash.

`./tagandbuild.bash <tag>`

Note - ./crosscompile.bash omits debug symbols to keep the build smaller.

Note also that these binaries should be signed for use in production, at least
on OSX and Windows. On OSX the command to do this should resemble the following
(assuming you have an associated code signing certificate):

```
codesign -s "Developer ID Application: Brave New Software Project, Inc" -f install/osx/pt/flashlight/flashlight
```

The script `copyexecutables.bash` takes care of signing the OS X executable and
copying everything in the Lantern file tree.

`copyexecutables.bash` will also optionally sign the Windows executable if the
environment variables BNS_CERT and BNS_CERT_PASS are set to point to
[bns-cert.p12](https://github.com/getlantern/too-many-secrets/blob/master/bns_cert.p12)
and its [password](https://github.com/getlantern/too-many-secrets/blob/master/build-installers/env-vars.txt#L3).

The code signing [certificate](https://github.com/getlantern/too-many-secrets/blob/master/osx-code-signing-certificate.p12)
and [password](https://github.com/getlantern/too-many-secrets/blob/master/osx-code-signing-certificate.p12.txt)
can be obtained from [too-many-secrets](https://github.com/getlantern/too-many-secrets).

note - Signing windows code requires that the
[osslsigncode](http://sourceforge.net/projects/osslsigncode/) utility be
installed. On OS X with homebrew, you can do this with
`brew install osslsigncode`.



File renamed without changes.
8 changes: 8 additions & 0 deletions crosscompile.bash
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/bash

# The VERSION is set to the tag for the current commit (if it exists) otherwise
# just the commit id.
VERSION="`git describe --abbrev=0 --tags --exact-match || git rev-parse --short HEAD`"
BUILD_DATE="`date -u +%Y%m%d%.%H%M%S`"
echo "Building flashlight version $VERSION ($BUILD_DATE)"
gox -ldflags="-w -X main.version $VERSION -X main.buildDate $BUILD_DATE" -osarch="linux/386 linux/amd64 windows/386 darwin/amd64" github.com/getlantern/flashlight
76 changes: 0 additions & 76 deletions src/github.com/getlantern/flashlight/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,82 +72,6 @@ On the client, you should see something like this for every request:
Handling request for: http://www.google.com/humans.txt
```

### Building

Flashlight requires [Go 1.3.x](http://golang.org/dl/).

It is convenient to build flashlight for multiple platforms using
[gox](https://github.com/mitchellh/gox).

The typical cross-compilation setup doesn't work for anything that uses C code,
which includes the DNS resolution code and some other things. See
[this blog](https://inconshreveable.com/04-30-2014/cross-compiling-golang-programs-with-native-libraries/)
for more discussion.

To deal with that, you need to use a Go installed using
[gonative](https://github.com/getlantern/gonative). Ultimately, you can put this
go wherever you like. Ox keeps his at ~/go_native.

```bash
go get github.com/mitchellh/gox
go get github.com/getlantern/gonative
cd ~
gonative -version="1.3.3" -platforms="darwin_amd64 linux_386 linux_amd64 windows_386"
mv go go_native
```

Finally update your GOROOT and PATH to point at `~/go_native` instead of your
previous go installation. They should look something like this:

```bash
➜ flashlight git:(1606) ✗ echo $GOROOT
/Users/ox.to.a.cart//go_native
➜ flashlight git:(1606) ✗ which go
/Users/ox.to.a.cart//go_native/bin/go
```

Now that you have go and gox set up, the binaries used for Lantern can be built
with the `./crosscompile.bash` script. This script also sets the version of
flashlight to the most recent annotated tag in git. An annotated tag can be
added like this:

```bash
git tag -a v1.0.0 -m"Tagged 1.0.0"
git push --tags
```

The script `tagandbuild.bash` tags and runs crosscompile.bash.

`./tagandbuild.bash <tag<`

Note - ./crosscompile.bash omits debug symbols to keep the build smaller.

Note also that these binaries should also be signed for use in production, at
least on OSX and Windows. On OSX the command to do this should resemble the
following (assuming you have an associated code signing certificate):

```
codesign -s "Developer ID Application: Brave New Software Project, Inc" -f install/osx/pt/flashlight/flashlight
```

The script `copyexecutables.bash` takes care of signing the OS X executable and
copying everything in the Lantern file tree.

`copyexecutables.bash` will also optionally sign the Windows executable if the
environment variables BNS_CERT and BNS_CERT_PASS are set to point to
[bns-cert.p12](https://github.com/getlantern/too-many-secrets/blob/master/bns_cert.p12)
and its [password](https://github.com/getlantern/too-many-secrets/blob/master/build-installers/env-vars.txt#L3).

The code signing [certificate](https://github.com/getlantern/too-many-secrets/blob/master/osx-code-signing-certificate.p12)
and [password](https://github.com/getlantern/too-many-secrets/blob/master/osx-code-signing-certificate.p12.txt)
can be obtained from [too-many-secrets](https://github.com/getlantern/too-many-secrets).

note - Signing windows code requires that the
[osslsigncode](http://sourceforge.net/projects/osslsigncode/) utility be
installed. On OS X with homebrew, you can do this with
`brew install osslsigncode`.


### Masquerade Host Management

Masquerade host configuration is managed using utilities in the [`genconfig/`](genconfig/) subfolder.
Expand Down
5 changes: 0 additions & 5 deletions src/github.com/getlantern/flashlight/crosscompile.bash

This file was deleted.

15 changes: 15 additions & 0 deletions tagandbuild.bash
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/bin/bash

function die() {
echo $*
exit 1
}

if [ $# -lt "1" ]
then
die "$0: Tag required"
fi

git tag -a "$1" -f --annotate -m"Tagged $1"
git push --tags -f
./crosscompile.bash

0 comments on commit ffa3a61

Please sign in to comment.