all: use make to build
This overhauls the build system.
We used to use a just-in-time clever build system
so that 'go run' and 'go install' Just Worked.
This was really nice, except that it make it
all but impossible to ship a single binary.
It also required our uses to install npm,
which some folks have an understandably negative reaction to.
This migrates to a makefile for building.
The core typescript building logic is mostly still in Go,
and untouched (boy did I learn that lesson the hard way).
The output is a single file that includes the webui, innie, and outie.
(There are still very mild shenanigans in which we write outie
out to a temp file and then 'docker cp' it into the docker container.
But this is pretty manageable.)
There are some significant follow-ups left after this commit:
- convert the nightly release builds to use the makefile
- lots of dead code removal
- maybe add -race support using a dockerfile for the cgo compilation
- maybe use 'docker cp' stdin reading with tar to avoid the temp outtie file
- all the rest of the "better release" todos (brew install, etc.)
diff --git a/Makefile b/Makefile
new file mode 100644
index 0000000..2b31b66
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,32 @@
+# Makefile for building sketch with embedded assets
+#
+# Two-layer architecture:
+# 1. Linux binary ("innie") - runs in container, embeds webui assets
+# 2. Native binary ("outie") - runs on user's machine, embeds innie
+
+BUILD_TIME := $(shell date -u +"%Y-%m-%dT%H:%M:%SZ")
+COMMIT := $(shell git rev-parse HEAD 2>/dev/null || echo "unknown")
+VERSION := $(shell git describe --tags --dirty --always 2>/dev/null || echo "dev")
+LDFLAGS := -X main.version=$(VERSION) -X main.commit=$(COMMIT) -X main.date=$(BUILD_TIME) -X main.makefile=true
+
+.PHONY: all clean help
+.PHONY: outie innie
+.PHONY: webui-assets
+
+all: outie
+
+outie: innie
+ go build -ldflags="$(LDFLAGS)" -tags=outie -o sketch ./cmd/sketch
+
+innie: webui-assets
+ CGO_ENABLED=0 GOOS=linux go build -ldflags="$(LDFLAGS)" -tags=innie -o embedded/sketch-linux/sketch-linux ./cmd/sketch
+
+webui-assets:
+ rm -rf embedded/webui-dist
+ go run ./cmd/genwebui -- embedded/webui-dist
+
+clean:
+ @echo "Cleaning build artifacts..."
+ rm -f sketch
+ rm -rf embedded/sketch-linux embedded/webui-dist
+ cd webui && rm -rf node_modules dist