about summary refs log tree commit diff
diff options
context:
space:
mode:
authorTerin Stock <terinjokes@gmail.com>2017-05-29 21:51:32 -0700
committerTerin Stock <terinjokes@gmail.com>2017-05-29 22:06:40 -0700
commit290e822a687e7d69def79d55dd7801447c804293 (patch)
treef7e0fbef00ff2c5ddf1ff55b3d3519756f596e96
parent560a5800c57ca40038c3f36d433bb6ae2f3acde2 (diff)
feat(main): just enough to bakelite itself v0.0.1
This is just the beginning of the amazing adventures of Terin and
Bakelite. Their journey is destined to be packed with non-stop action,
millions of laughs, heart pounding perils, and endless excitement.
Together, they'll encounter fantastic friends, evil enemies, and meet
creatures beyond your wildest imagination. And as their story unfolds,
we'll unlock the magic and mystery of a most wondrous place, the
incredible world of [fixme].
-rw-r--r--.travis.yml28
-rw-r--r--LICENSE.md19
-rw-r--r--README.md11
-rw-r--r--main.go147
4 files changed, 205 insertions, 0 deletions
diff --git a/.travis.yml b/.travis.yml
new file mode 100644
index 0000000..1de576e
--- /dev/null
+++ b/.travis.yml
@@ -0,0 +1,28 @@
+language: go
+go:
+  - 1.8.x
+install:
+  - go get github.com/Masterminds/glide
+script:
+  - go test -v $(glide nv)
+
+jobs:
+  include:
+  - stage: Build and Deploy
+    go: 1.8.x
+    script:
+      - go build github.com/terinjokes/bakelite
+      - "./bakelite github.com/terinjokes/bakelite"
+      - for i in bakelite-*; do tar -czf $i.tar.gz $i; done
+      - shasum -a 512 bakelite-*.tar.gz | tee sha512sum.txt
+    deploy:
+      provider: releases
+      api_key:
+        secure: V5ZA8knEw5y9tYrUCJSffVTtyY+qKENNgpE0fXP3EKjI7H3NqGspLrm+oxCs1ym35YVFFYglCB2plD2JdnRaOe3VDi3/QJqpLQpI44OkNm8S73HgjNjXYIQypjP19uHfxBUPLX8BVwqrKKUrNQ7vCMc1JCJFf6qxB0Evd0355j5/VdtmQNM1MyVWwt+3XFo3VUfBP7RLuhdOmDQc1uSeQTqlG+xim5N8VIuINsfECXCoKnEhS2zCbHz+8dJgBtmqOeUHYIKI1WXpLqj/wLTjGvViaNwzUCYndS7PwX3dQcZVm1kikgdj1L6w6Pow0SfE8krhdKSIGzWJoiNMyYC0aiwomKpSitK9DK/cQLJbhCVpx19iONUGcfJ8Hr1I40MAF2jt9cThEQgnlHdkfkjRFGNWU7RHDkrW8L1nQ3kUA0t/QOXYl7SLRcTgWvwc5LuBx5vYDV1M4kb3RowNiMKKrII82Tcjswqe63fxXe0B+73Ksza/3Vi9VDki/UyDOVNEvMinF5xVlYOQgcFfj0r8ZAXjWeylYdLTTnn8X+6rt4waaYdualyb4Bf8S4LmRVHCD7Jl1+Xtv1dRM7Oyq7d0weLtyzvV9J1CjJsPKJxujuBFWjQv4fn/HPJEljXhNnFDoNgmgN0yXx4LNM+uB8IVzRjpNXbDnq2mGeYD4XXlCLE=
+      skip_cleanup: true
+      file_glob: true
+      file:
+        - bakelite-*.tar.gz
+        - sha512sum.txt
+      on:
+        tags: true
diff --git a/LICENSE.md b/LICENSE.md
new file mode 100644
index 0000000..47f9740
--- /dev/null
+++ b/LICENSE.md
@@ -0,0 +1,19 @@
+Copyright (c) 2017 Terin Stock <terinjokes@gmail.com>
+
+Permission is hereby granted, free of charge, to any person obtaining a copy of
+this software and associated documentation files (the "Software"), to deal in
+the Software without restriction, including without limitation the rights to
+use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
+of the Software, and to permit persons to whom the Software is furnished to do
+so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+SOFTWARE.
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..fddba98
--- /dev/null
+++ b/README.md
@@ -0,0 +1,11 @@
+# Bakelite [![Travis branch][travis-shield]][travis-url] ![Stability: Experimental][stability-shield]
+
+[travis-shield]: https://img.shields.io/travis/terinjokes/bakelite/master.svg?style=flat-square
+[travis-url]: https://travis-ci.org/terinjokes/bakelite
+[stability-shield]: https://img.shields.io/badge/stability-experimental-orange.svg?style=flat-square
+
+A tool to quickly mass-produce Go binaries for multiple Operating
+Systems and architectures.
+
+Highly experimental codebase: not yet intended for serious use. Just
+enough implemented to bakelite itself.
diff --git a/main.go b/main.go
new file mode 100644
index 0000000..d2ecf84
--- /dev/null
+++ b/main.go
@@ -0,0 +1,147 @@
+package main
+
+import (
+	"bytes"
+	"context"
+	"flag"
+	"fmt"
+	"log"
+	"os"
+	"os/exec"
+	"path/filepath"
+)
+
+type Arch string
+
+const (
+	ARCH_AMD64    Arch = "amd64"
+	ARCH_386      Arch = "386"
+	ARCH_ARM      Arch = "arm"
+	ARCH_ARM64    Arch = "arm64"
+	ARCH_PPC64    Arch = "ppc64"
+	ARCH_PPC64LE  Arch = "ppc64le"
+	ARCH_MIPS     Arch = "mips"
+	ARCH_MIPSLE   Arch = "mipsle"
+	ARCH_MIPS64   Arch = "mips64"
+	ARCH_MIPS64LE Arch = "mips64le"
+)
+
+type OS string
+
+const (
+	OS_ANDROID   OS = "android"
+	OS_DARWIN    OS = "darwin"
+	OS_DRAGONFLY OS = "dragonfly"
+	OS_FREEBSD   OS = "freebsd"
+	OS_LINUX     OS = "linux"
+	OS_NETBSD    OS = "netbsd"
+	OS_OPENBSD   OS = "openbsd"
+	OS_PLAN9     OS = "plan9"
+	OS_SOLARIS   OS = "solaris"
+	OS_WINDOWS   OS = "windows"
+)
+
+type Platform struct {
+	OS   OS
+	Arch Arch
+}
+
+type kvs map[string]string
+
+func (o kvs) Strings() []string {
+	str := []string{}
+	for k, v := range o {
+		str = append(str, k+"="+v)
+	}
+
+	return str
+}
+
+var cgo bool
+
+func main() {
+	// TODO: enable ARM after supporting GOARM
+	// TODO: probably should make this configurableā€¦
+	platforms := []Platform{
+		//{OS_ANDROID, ARCH_ARM},
+		{OS_DARWIN, ARCH_386},
+		{OS_DARWIN, ARCH_AMD64},
+		//{OS_DARWIN, ARCH_ARM},
+		//{OS_DARWIN, ARCH_ARM64},
+		{OS_DRAGONFLY, ARCH_AMD64},
+		{OS_FREEBSD, ARCH_386},
+		{OS_FREEBSD, ARCH_AMD64},
+		//{OS_FREEBSD, ARCH_ARM},
+		{OS_LINUX, ARCH_386},
+		{OS_LINUX, ARCH_AMD64},
+		//{OS_LINUX, ARCH_ARM},
+		//{OS_LINUX, ARCH_ARM64},
+		{OS_LINUX, ARCH_PPC64},
+		{OS_LINUX, ARCH_PPC64LE},
+		{OS_LINUX, ARCH_MIPS},
+		{OS_LINUX, ARCH_MIPSLE},
+		{OS_LINUX, ARCH_MIPS64},
+		{OS_LINUX, ARCH_MIPS64LE},
+		{OS_NETBSD, ARCH_386},
+		{OS_NETBSD, ARCH_AMD64},
+		//{OS_NETBSD, ARCH_ARM},
+		{OS_OPENBSD, ARCH_386},
+		{OS_OPENBSD, ARCH_AMD64},
+		//{OS_OPENBSD, ARCH_ARM},
+		{OS_PLAN9, ARCH_386},
+		{OS_PLAN9, ARCH_AMD64},
+		{OS_SOLARIS, ARCH_AMD64},
+		{OS_WINDOWS, ARCH_386},
+		{OS_WINDOWS, ARCH_AMD64},
+	}
+
+	flags := flag.NewFlagSet("bakelite", flag.ExitOnError)
+	flags.BoolVar(&cgo, "cgo", false, "Enables cgo (BYOTC)")
+	flags.Usage = func() {
+		fmt.Println("bakelite - dev")
+	}
+	if err := flags.Parse(os.Args[1:]); err != nil {
+		flags.Usage()
+		os.Exit(-1)
+	}
+
+	packages := flags.Args()
+	if len(packages) == 0 {
+		fmt.Println("fatal: Expected at least one package.")
+		os.Exit(-1)
+	}
+
+	for _, platform := range platforms {
+		for _, pkg := range packages {
+			name := fmt.Sprintf("%s-%s-%s", filepath.Base(pkg), platform.OS, platform.Arch)
+			env := kvs{
+				"GOOS":   string(platform.OS),
+				"GOARCH": string(platform.Arch),
+				"GOROOT": os.Getenv("GOROOT"),
+				"GOPATH": os.Getenv("GOPATH"),
+			}
+
+			if cgo {
+				env["CGO_ENABLED"] = "1"
+			} else {
+				env["CGO_ENABLED"] = "0"
+			}
+
+			var stdout bytes.Buffer
+			var stderr bytes.Buffer
+
+			cmd := exec.CommandContext(context.Background(), "go", "build", "-o", name, pkg)
+			cmd.Env = env.Strings()
+			cmd.Stdout = &stdout
+			cmd.Stderr = &stderr
+
+			fmt.Printf("info: Running build for %s @ %s/%sā€¦\n", pkg, platform.OS, platform.Arch)
+			err := cmd.Run()
+
+			if err != nil {
+				log.Printf("fatal: There was an error! err='%s' stdout='%s' stderr='%s'", err, stdout.String(), stderr.String())
+				os.Exit(-1)
+			}
+		}
+	}
+}