summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSean E. Russell <ser@ser1.net>2020-02-20 10:05:58 -0600
committerSean E. Russell <ser@ser1.net>2020-02-20 12:35:18 -0600
commit5f37965467eb89f6d7e2cb83fe20ed1de25ab9a7 (patch)
tree46de122a279e78f4b4559df74bb5a8ddae613942
parentf96a97c3d8f5b8cd87a6e2f1fd1d0a4032c429a7 (diff)
Builds for darwin; requires docker.
osxcross has an old go; make go.mod match. Directory clean-ups
-rw-r--r--README.md17
-rw-r--r--build/nfpm.yml2
-rwxr-xr-xbuild/osx.sh3
-rw-r--r--build/snapcraft.yaml (renamed from snap/snapcraft.yaml)0
-rwxr-xr-xci/script.sh36
-rw-r--r--go.mod2
-rw-r--r--logging/logging_other.go2
-rwxr-xr-xmake.sh150
8 files changed, 132 insertions, 80 deletions
diff --git a/README.md b/README.md
index a3ff80c..ca7be96 100644
--- a/README.md
+++ b/README.md
@@ -32,6 +32,23 @@ Visit [here](https://github.com/xxxserxxx/gotop/releases) with your web browser
Unzip it and then move `gotop` into your `$PATH` somewhere. If you're on a Debian or Redhat derivative, you can download an `.rpm` or `.deb` to install.
+### Building
+
+The easiest way is to
+```
+go get github.com/xxxserxxx/gotop/cmd/gotop
+```
+
+To create the cross-compile builds, there's a `make.sh` script; it has a lot of dependencies and has only been tested on my computer. When it works, it creates archives for numerous OSes & architectures. There's no testing for whether dependencies are available; it assumes they are and will fail in strange ways when they aren't.
+
+- bash
+- Go
+- zip
+- nfpm (for deb & rpm)
+- docker (for darwin)
+
+It is *just* smart enough to not rebuild things when it doesn't have to, and it tries to keep the darwin docker container around so it's not building from scratch every time. There are no guarantees.
+
## Usage
### Keybinds
diff --git a/build/nfpm.yml b/build/nfpm.yml
index 67b575b..69852e0 100644
--- a/build/nfpm.yml
+++ b/build/nfpm.yml
@@ -12,4 +12,4 @@ homepage: "https://github.com/xxxserxxx/gotop"
license: "GNU Affero General Public License v3.0"
bindir: "/usr/local/bin"
files:
- dist/gotop: "/usr/local/bin/gotop"
+ build/gotop: "/usr/local/bin/gotop"
diff --git a/build/osx.sh b/build/osx.sh
new file mode 100755
index 0000000..9d76d59
--- /dev/null
+++ b/build/osx.sh
@@ -0,0 +1,3 @@
+#!/bin/bash
+cd /mnt
+./make.sh darwin
diff --git a/snap/snapcraft.yaml b/build/snapcraft.yaml
index de17ee7..de17ee7 100644
--- a/snap/snapcraft.yaml
+++ b/build/snapcraft.yaml
diff --git a/ci/script.sh b/ci/script.sh
deleted file mode 100755
index 27e6cdf..0000000
--- a/ci/script.sh
+++ /dev/null
@@ -1,36 +0,0 @@
-#!/usr/bin/env bash
-
-function main {
- # Check if any command failed
- ERROR=false
-
- GOARCH=${_GOARCH}
- GOOS=${_GOOS}
-
- if [[ ! ${GOARCH} ]]; then
- exit
- fi
-
- env GOOS=${GOOS} GOARCH=${GOARCH} GOARM=${GOARM} go build -o ${NAME} || ERROR=true
-
- mkdir -p dist
-
- if [[ ${GOARCH} == "arm64" ]]; then
- FILE=${NAME}_${TRAVIS_BRANCH}_${GOOS}_arm8
- else
- FILE=${NAME}_${TRAVIS_BRANCH}_${GOOS}_${GOARCH}${GOARM}
- fi
-
- tar -czf dist/${FILE}.tgz ${NAME} || ERROR=true
-
- if [[ ${GOOS} == "linux" && ${GOARCH} == "amd64" ]]; then
- make all || ERROR=true
- rm dist/gotop
- fi
-
- if [ ${ERROR} == "true" ]; then
- exit 1
- fi
-}
-
-main
diff --git a/go.mod b/go.mod
index 6058002..639a0d1 100644
--- a/go.mod
+++ b/go.mod
@@ -15,4 +15,4 @@ require (
howett.net/plist v0.0.0-20181124034731-591f970eefbb // indirect
)
-go 1.13
+go 1.12
diff --git a/logging/logging_other.go b/logging/logging_other.go
index f5705d6..fd88b83 100644
--- a/logging/logging_other.go
+++ b/logging/logging_other.go
@@ -1,4 +1,4 @@
-// +build linux openbsd freebsd
+// +build linux openbsd freebsd darwin
// +build !arm64
package logging
diff --git a/make.sh b/make.sh
index 132657a..c158883 100755
--- a/make.sh
+++ b/make.sh
@@ -4,7 +4,8 @@ export VERSION=$(go run ./cmd/gotop -V)
rm -f build.log
-function candz() {
+# Set up some common environment variables
+function out() {
export GOOS=$1
export GOARCH=$2
OUT=build/gotop_${VERSION}_${GOOS}_${GOARCH}
@@ -12,64 +13,131 @@ function candz() {
export GOARM=$3
OUT=${OUT}_v${GOARM}
fi
- OUT=${OUT}.zip
- if [[ -e $OUT ]]; then
- echo SKIP $OUT
- return
- fi
D=build/gotop
if [[ $GOOS == "windows" ]]; then
D=${D}.exe
+ AR=${OUT}.zip
+ else
+ AR=${OUT}.tgz
fi
+}
+# Clean up environment variables
+function uset() {
+ unset GOOS GOARCH GOARM CGO_ENABLED OUT D AR
+}
+# Compile something that can be cross-compiled without docker
+function c() {
+ out $1 $2 $3
go build -o $D ./cmd/gotop >> build.log 2>&1
if [[ $? -ne 0 ]]; then
printenv | grep GO >> build.log
- echo "############### FAILED ###############" >> build.log
- echo >> build.log
- echo >> build.log
- echo FAILED $OUT
+ echo "############### FAILED ###############"
+ echo FAILED COMPILE $OUT
+ fi
+}
+# Zip up something that's been compiled
+function z() {
+ out $1 $2 $3
+ if [[ -e $AR ]]; then
+ echo SKIP $AR
return
fi
- unset GOOS GOARCH GOARM CGO_ENABLED
cd build
- zip $(basename $OUT) $(basename $D) >> ../build.log 2>&1
- cd ..
- rm -f $D
+ if [[ $GOOS == "windows" ]]; then
+ zip -q $(basename $AR) $(basename $D)
+ else
+ tar -czf $(basename $AR) $(basename $D)
+ fi
if [[ $? -ne 0 ]]; then
- echo "############### FAILED ###############" >> build.log
- echo >> build.log
- echo >> build.log
- echo FAILED $OUT
+ echo "############### FAILED ###############"
+ echo FAILED ARCHIVE $AR
+ cd ..
return
fi
- echo BUILT $OUT
+ cd ..
+ echo BUILT $AR
}
-
-candz linux arm64
-for x in 5 6 7; do
- candz linux arm $x
-done
-for x in 386 amd64; do
- candz linux $x
-
- sed -i "s/arch: .*/arch: \"${x}\"/" build/nfpm.yml
+# Do c(), then z(), and then clean up.
+function candz() {
+ unset OUT
+ out $1 $2 $3
+ local AR=${OUT}.zip
+ if [[ -e $AR ]]; then
+ echo SKIP $AR
+ return
+ fi
+ c $1 $2 $3
+ z $1 $2 $3
+ rm -f $D
+ uset
+}
+# Build the deb and rpm archives
+function nfpmAR() {
+ out $1 $2 $3
+ sed -i "s/arch: .*/arch: \"${GOARCH}\"/" build/nfpm.yml
for y in rpm deb; do
- OUT=build/gotop_${VERSION}_linux_${x}.${y}
- if [[ -e $OUT ]]; then
- echo SKIP $OUT
+ local AR=build/gotop_${VERSION}_linux_${GOARCH}.${y}
+ if [[ -e $AR ]]; then
+ echo SKIP $AR
else
- echo Building $OUT
- nfpm pkg -t ${OUT} -f build/nfpm.yml
+ echo Building $AR
+ nfpm pkg -t ${AR} -f build/nfpm.yml
fi
done
+}
+# Cross-compile the darwin executable. This requires docker.
+function cdarwinz() {
+ if [[ ! -d darwin ]]; then
+ git clone . darwin
+ cd darwin
+ else
+ cd darwin
+ git pull
+ fi
+ export CGO_ENABLED=1
+ if [[ `docker images -q gotopdarwin` == "" ]]; then
+ docker run -it --name osxcross --mount type=bind,source="$(pwd)",target=/mnt dockercore/golang-cross /bin/bash /mnt/build/osx.sh
+ local ID=`docker commit osxcross dockercore/golang-cross | cut -d : -f 2`
+ docker tag $ID gotopdarwin
+ else
+ docker run -it --name osxcross --mount type=bind,source="$(pwd)",target=/mnt gotopdarwin /bin/bash /mnt/build/osx.sh
+ fi
+ cd ..
+ mv darwin/build/gotop*darwin*.tgz build/
+ docker rm osxcross
+ uset
+}
- candz windows $x
- candz freebsd $x
+##########################################################
+# Iterate through the OS/ARCH permutations and build an
+# archive for each, using the previously defined functions.
+if [[ $1 == "darwin" ]]; then
+ export MACOSX_DEPLOYMENT_TARGET=10.10.0
+ export CC=o64-clang
+ export CXX=o64-clang++
+ export CGO_ENABLED=1
+ c darwin 386
+ z darwin 386
+ c darwin amd64
+ z darwin amd64
+else
+ candz linux arm64
- export CGO_ENABLED=1
- candz darwin $x
- candz openbsd $x
- unset CGO_ENABLED
-done
+ for x in 5 6 7; do
+ candz linux arm $x
+ done
-rm -f build/gotop
+ for x in 386 amd64; do
+ c linux $x
+ z linux $x
+ nfpmAR linux $x
+ rm -f $D
+ uset
+
+ candz windows $x
+ candz freebsd $x
+
+ # candz openbsd $x
+ done
+ cdarwinz
+fi