Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
81 changes: 42 additions & 39 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,86 +2,89 @@ version: 2.1
executors:
base:
docker:
- image: circleci/golang:1.12
- image: circleci/golang:1.12-node
working_directory: /go/src/github.com/spatialcurrent/gotmpl
jobs:
pre_deps_golang:
executor: base
steps:
- checkout
- run: go get -d ./...
- run: go get github.com/inconshreveable/mousetrap # for windows CLI builds
- run: make deps_go
- run: sudo chown -R circleci /go/src
- save_cache:
key: v1-go-src-{{ .Branch }}-{{ .Revision }}
paths:
- /go/src
test:
test_go:
executor: base
steps:
- run: sudo chown -R circleci /go/src
- restore_cache:
keys:
- v1-go-src-{{ .Branch }}-{{ .Revision }}
- run:
name: Get shadow
command: go get golang.org/x/tools/go/analysis/passes/shadow/cmd/shadow
- run:
name: Install shadow
command: go install golang.org/x/tools/go/analysis/passes/shadow/cmd/shadow
- run:
name: Download and install errcheck
command: go get -u github.com/kisielk/errcheck
- run:
name: Download and install misspell
command: go get -u github.com/client9/misspell/cmd/misspell
- run:
name: Download and install ineffassign
command: go get -u github.com/gordonklaus/ineffassign
- run:
name: Download and install staticheck
command: go get -u honnef.co/go/tools/cmd/staticcheck
- run: make test
validate:
- run: make deps_go_test
- run: make test_go
- run: make imports
- run: git diff --exit-code
test_javascript:
executor: base
steps:
- run: sudo chown -R circleci /go/src
- restore_cache:
keys:
- v1-go-src-{{ .Branch }}-{{ .Revision }}
- run:
name: Install Dig
command: sudo apt update && sudo apt install dnsutils
- run:
name: "Update ~/.ssh/known_hosts"
command: |
mkdir ~/.ssh/
touch ~/.ssh/known_hosts
for ip in $(dig @8.8.8.8 github.com +short); do ssh-keyscan github.com,$ip; ssh-keyscan $ip; done 2>/dev/null >> ~/.ssh/known_hosts
- run: go get github.com/spatialcurrent/go-header/...
- run: go install github.com/spatialcurrent/go-header/cmd/goheader
- run: goheader fix --fix-year 2019 --exit-code-on-changes 1 --verbose
- run: make deps_gopherjs
- run: make deps_javascript
- run: npm run test:clean
build_cli:
executor: base
steps:
- run: sudo chown -R circleci /go/src
- restore_cache:
keys:
- v1-go-src-{{ .Branch }}-{{ .Revision }}
- run: make build
- run: go get github.com/inconshreveable/mousetrap # for windows CLI builds
- run: make build_cli
- store_artifacts:
path: bin
destination: /
build_javascript:
executor: base
steps:
- run: sudo chown -R circleci /go/src
- restore_cache:
keys:
- v1-go-src-{{ .Branch }}-{{ .Revision }}
- run: make deps_gopherjs
- run: make build_javascript
- store_artifacts:
path: dist
destination: /
build_so:
executor: base
steps:
- run: sudo chown -R circleci /go/src
- restore_cache:
keys:
- v1-go-src-{{ .Branch }}-{{ .Revision }}
- run: sudo make deps_arm
- run: make build_so
- store_artifacts:
path: bin
destination: /
workflows:
main:
jobs:
- pre_deps_golang
- test:
- test_go:
requires:
- pre_deps_golang
- validate:
- test_javascript:
requires:
- pre_deps_golang
- build_cli:
requires:
- pre_deps_golang
- build_javascript:
requires:
- pre_deps_golang
10 changes: 10 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
__mocks__/
dist/
bin/
node_modules/
webpack/
.DS_Store
.npm
node_modules
npm-debug.*
package-lock.json
8 changes: 8 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"parserOptions": {
"ecmaVersion": 2017
},
"env": {
"es6": true
}
}
11 changes: 9 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
secret/
bin/
bin
dist
vendor
Gopkg.lock
*.so
*.h
.DS_Store
.npm
node_modules
npm-debug.*
package-lock.json
174 changes: 159 additions & 15 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,32 +5,176 @@
#
# =================================================================

ifdef GOPATH
GCFLAGS=-trimpath=$(shell printenv GOPATH)/src
else
GCFLAGS=-trimpath=$(shell go env GOPATH)/src
endif

LDFLAGS=-X main.gitBranch=$(shell git branch | grep \* | cut -d ' ' -f2) -X main.gitCommit=$(shell git rev-list -1 HEAD)

ifndef DEST
DEST=bin
endif

.PHONY: help
help: ## Print the help documentation
@grep -E '^[a-zA-Z_-\]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'

#
# Dependencies
#

deps_go: ## Install Go dependencies
go get -d -t ./...

.PHONY: deps_go_test
deps_go_test: ## Download Go dependencies for tests
go get golang.org/x/tools/go/analysis/passes/shadow/cmd/shadow # download shadow
go install golang.org/x/tools/go/analysis/passes/shadow/cmd/shadow # install shadow
go get -u github.com/kisielk/errcheck # download and install errcheck
go get -u github.com/client9/misspell/cmd/misspell # download and install misspell
go get -u github.com/gordonklaus/ineffassign # download and install ineffassign
go get -u honnef.co/go/tools/cmd/staticcheck # download and instal staticcheck
go get -u golang.org/x/tools/cmd/goimports # download and install goimports

deps_arm: ## Install dependencies to cross-compile to ARM
# ARMv7
apt-get install -y libc6-armel-cross libc6-dev-armel-cross binutils-arm-linux-gnueabi libncurses5-dev gcc-arm-linux-gnueabi g++-arm-linux-gnueabi
# ARMv8
apt-get install gcc-aarch64-linux-gnu g++-aarch64-linux-gnu

deps_gopherjs: ## Install GopherJS with jsbuiltin
go get -u github.com/gopherjs/gopherjs
go get -u -d -tags=js github.com/gopherjs/jsbuiltin

deps_javascript: ## Install dependencies for JavaScript tests
npm install .

#
# Go building, formatting, testing, and installing
#

.PHONY: fmt
fmt: ## Format Go source code
go fmt $$(go list ./... )

.PHONY: imports
imports: ## Update imports in Go source code
goimports -w $$(find . -iname '*.go')

.PHONY: vet
vet: ## Vet Go source code
go vet $$(go list ./... )

.PHONY: test_go
test_go: ## Run Go tests
bash scripts/test.sh

build: build_cli build_javascript ## Build CLI and JavaScript

install: ## Install gotmpl CLI on current platform
go install -gcflags="$(GCFLAGS)" -ldflags="$(LDFLAGS)" github.com/spatialcurrent/gotmpl/cmd/gotmpl

#
# Command line Programs
#

bin/gotmpl_darwin_amd64:
GOOS=darwin GOARCH=amd64 go build -o bin/gotmpl_darwin_amd64 $$(go list ./...)
GOOS=darwin GOARCH=amd64 go build -o bin/gotmpl_darwin_amd64 -gcflags="$(GCFLAGS)" -ldflags="$(LDFLAGS)" github.com/spatialcurrent/gotmpl/cmd/gotmpl

bin/gotmpl_linux_amd64:
GOOS=linux GOARCH=amd64 go build -o bin/gotmpl_linux_amd64 $$(go list ./...)
GOOS=linux GOARCH=amd64 go build -o bin/gotmpl_linux_amd64 -gcflags="$(GCFLAGS)" -ldflags="$(LDFLAGS)" github.com/spatialcurrent/gotmpl/cmd/gotmpl

bin/gotmpl_windows_amd64.exe:
GOOS=windows GOARCH=amd64 go build -o bin/gotmpl_windows_amd64.exe $$(go list ./...)
GOOS=windows GOARCH=amd64 go build -o bin/gotmpl_windows_amd64.exe -gcflags="$(GCFLAGS)" -ldflags="$(LDFLAGS)" github.com/spatialcurrent/gotmpl/cmd/gotmpl

bin/gotmpl_linux_arm64:
GOOS=linux GOARCH=arm64 go build -o bin/gotmpl_linux_arm64 $$(go list ./...)
GOOS=linux GOARCH=arm64 go build -o bin/gotmpl_linux_arm64 -gcflags="$(GCFLAGS)" -ldflags="$(LDFLAGS)" github.com/spatialcurrent/gotmpl/cmd/gotmpl

build: \
bin/gotmpl_darwin_amd64 \
bin/gotmpl_linux_amd64 \
bin/gotmpl_windows_amd64.exe \
bin/gotmpl_linux_arm64
build_cli: bin/gotmpl_darwin_amd64 bin/gotmpl_linux_amd64 bin/gotmpl_windows_amd64.exe bin/gotmpl_linux_arm64 ## Build command line programs

fmt:
go fmt $$(go list ./... )
#
# Shared Objects
#

install:
go install $$(go list ./...)
bin/gotmpl.so: ## Compile Shared Object for current platform
# https://golang.org/cmd/link/
# CGO Enabled : https://github.com/golang/go/issues/24068
CGO_ENABLED=1 go build -o $(DEST)/gotmpl.so -buildmode=c-shared -ldflags "$(LDFLAGS)" -gcflags="$(GCFLAGS)" github.com/spatialcurrent/gotmpl/plugins/gotmpl

test:
bash scripts/test.sh
bin/gotmpl_linux_amd64.so: ## Compile Shared Object for Linux / amd64
# https://golang.org/cmd/link/
# CGO Enabled : https://github.com/golang/go/issues/24068
GOOS=linux GOARCH=amd64 CGO_ENABLED=1 go build -o $(DEST)/gotmpl_linux_amd64.so -buildmode=c-shared -ldflags "$(LDFLAGS)" -gcflags="$(GCFLAGS)" github.com/spatialcurrent/gotmpl/plugins/gotmpl

bin/gotmpl_linux_armv7.so: ## Compile Shared Object for Linux / ARMv7
# LDFLAGS - https://golang.org/cmd/link/
# CGO Enabled - https://github.com/golang/go/issues/24068
# GOARM/GOARCH Compatability Table - https://github.com/golang/go/wiki/GoArm
# ARM Cross Compiler Required - https://www.acmesystems.it/arm9_toolchain
GOOS=linux GOARCH=arm GOARM=7 CGO_ENABLED=1 CC=arm-linux-gnueabi-gcc go build -ldflags "-linkmode external -extldflags -static" -o $(DEST)/gotmpl_linux_armv7.so -buildmode=c-shared -ldflags "$(LDFLAGS)" -gcflags="$(GCFLAGS)" github.com/spatialcurrent/gotmpl/plugins/gotmpl

bin/gotmpl_linux_armv8.so: ## Compile Shared Object for Linux / ARMv8
# LDFLAGS - https://golang.org/cmd/link/
# CGO Enabled - https://github.com/golang/go/issues/24068
# GOARM/GOARCH Compatability Table - https://github.com/golang/go/wiki/GoArm
# ARM Cross Compiler Required - https://www.acmesystems.it/arm9_toolchain
# Dependencies - https://www.96boards.org/blog/cross-compile-files-x86-linux-to-96boards/
GOOS=linux GOARCH=arm64 CGO_ENABLED=1 CC=aarch64-linux-gnu-gcc go build -ldflags "-linkmode external -extldflags -static" -o $(DEST)/gotmpl_linux_armv8.so -buildmode=c-shared -ldflags "$(LDFLAGS)" -gcflags="$(GCFLAGS)" github.com/spatialcurrent/gotmpl/plugins/gotmpl

build_so: bin/gotmpl_linux_amd64.so bin/gotmpl_linux_armv7.so bin/gotmpl_linux_armv8.so ## Build Shared Objects (.so)

#
# JavaScript
#

dist/gotmpl.mod.js: ## Build JavaScript module
gopherjs build -o dist/gotmpl.mod.js github.com/spatialcurrent/gotmpl/cmd/gotmpl.mod.js

dist/gotmpl.mod.min.js: ## Build minified JavaScript module
gopherjs build -m -o dist/gotmpl.mod.min.js github.com/spatialcurrent/gotmpl/cmd/gotmpl.mod.js

dist/gotmpl.global.js: ## Build JavaScript library that attaches to global or window.
gopherjs build -o dist/gotmpl.global.js github.com/spatialcurrent/gotmpl/cmd/gotmpl.global.js

dist/gotmpl.global.min.js: ## Build minified JavaScript library that attaches to global or window.
gopherjs build -m -o dist/gotmpl.global.min.js github.com/spatialcurrent/gotmpl/cmd/gotmpl.global.js

build_javascript: dist/gotmpl.mod.js dist/gotmpl.mod.min.js dist/gotmpl.global.js dist/gotmpl.global.min.js ## Build artifacts for JavaScript

test_javascript: ## Run JavaScript tests
npm run test

lint: ## Lint JavaScript source code
npm run lint

#
# Examples
#

bin/gotmpl_example_c: bin/gotmpl.so ## Build C example
mkdir -p bin && cd bin && gcc -o gotmpl_example_c -I. ./../examples/c/main.c -L. -l:gotmpl.so

bin/gotmpl_example_cpp: bin/gotmpl.so ## Build C++ example
mkdir -p bin && cd bin && g++ -o gotmpl_example_cpp -I . ./../examples/cpp/main.cpp -L. -l:gotmpl.so

run_example_c: bin/gotmpl.so bin/gotmpl_example_c ## Run C example
cd bin && LD_LIBRARY_PATH=. ./gotmpl_example_c

run_example_cpp: bin/gotmpl.so bin/gotmpl_example_cpp ## Run C++ example
cd bin && LD_LIBRARY_PATH=. ./gotmpl_example_cpp

run_example_python: bin/gotmpl.so ## Run Python example
LD_LIBRARY_PATH=bin python examples/python/test.py

run_example_javascript: dist/gotmpl.mod.js ## Run JavaScript module example
node examples/js/index.mod.js

#
# Clean
#

clean:
rm -fr bin
rm -fr dist
Loading