Skip to content

Commit c9b650f

Browse files
authored
Merge pull request #9 from spatialcurrent/packages
Refactor into multiple packages
2 parents bef87fc + e57c5cb commit c9b650f

212 files changed

Lines changed: 10471 additions & 2293 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.circleci/config.yml

Lines changed: 33 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -2,64 +2,54 @@ version: 2.1
22
executors:
33
base:
44
docker:
5-
- image: circleci/golang:1.12
5+
- image: circleci/golang:1.12-node
66
working_directory: /go/src/github.com/spatialcurrent/go-simple-serializer
77
jobs:
88
pre_deps_golang:
99
executor: base
1010
steps:
1111
- checkout
12-
- run: make deps
12+
- run: make deps_go
1313
- run: sudo chown -R circleci /go/src
1414
- save_cache:
1515
key: v1-go-src-{{ .Branch }}-{{ .Revision }}
1616
paths:
1717
- /go/src
18-
test:
18+
test_go:
1919
executor: base
2020
steps:
2121
- run: sudo chown -R circleci /go/src
2222
- restore_cache:
2323
keys:
2424
- v1-go-src-{{ .Branch }}-{{ .Revision }}
25-
- run:
26-
name: Get shadow
27-
command: go get golang.org/x/tools/go/analysis/passes/shadow/cmd/shadow
28-
- run:
29-
name: Install shadow
30-
command: go install golang.org/x/tools/go/analysis/passes/shadow/cmd/shadow
31-
- run:
32-
name: Download and install errcheck
33-
command: go get -u github.com/kisielk/errcheck
34-
- run:
35-
name: Download and install misspell
36-
command: go get -u github.com/client9/misspell/cmd/misspell
37-
- run:
38-
name: Download and install ineffassign
39-
command: go get -u github.com/gordonklaus/ineffassign
40-
- run:
41-
name: Download and install staticheck
42-
command: go get -u honnef.co/go/tools/cmd/staticcheck
43-
- run: make test
44-
validate:
25+
- run: make deps_go_test
26+
- run: make test_go
27+
- run: make imports
28+
- run: git diff --exit-code
29+
test_javascript:
4530
executor: base
4631
steps:
4732
- run: sudo chown -R circleci /go/src
4833
- restore_cache:
4934
keys:
5035
- v1-go-src-{{ .Branch }}-{{ .Revision }}
51-
- run:
52-
name: Install Dig
53-
command: sudo apt update && sudo apt install dnsutils
54-
- run:
55-
name: "Update ~/.ssh/known_hosts"
56-
command: |
57-
mkdir ~/.ssh/
58-
touch ~/.ssh/known_hosts
59-
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
60-
- run: go get github.com/spatialcurrent/go-header/...
61-
- run: go install github.com/spatialcurrent/go-header/cmd/goheader
62-
- run: goheader fix --fix-year 2019 --exit-code-on-changes 1 --verbose
36+
- run: make deps_gopherjs
37+
- run: make deps_javascript
38+
- run: npm run test:clean
39+
examples:
40+
executor: base
41+
steps:
42+
- run: sudo chown -R circleci /go/src
43+
- restore_cache:
44+
keys:
45+
- v1-go-src-{{ .Branch }}-{{ .Revision }}
46+
- run: make deps_gopherjs
47+
- run: make deps_javascript
48+
- run: npm run test:clean
49+
- run: make run_example_c
50+
- run: make run_example_cpp
51+
- run: make run_example_javascript
52+
- run: make run_example_python
6353
build_cli:
6454
executor: base
6555
steps:
@@ -79,12 +69,10 @@ jobs:
7969
- restore_cache:
8070
keys:
8171
- v1-go-src-{{ .Branch }}-{{ .Revision }}
82-
- run:
83-
name: Install GopherJS
84-
command: go get -u github.com/gopherjs/gopherjs
72+
- run: make deps_gopherjs
8573
- run: make build_javascript
8674
- store_artifacts:
87-
path: bin
75+
path: dist
8876
destination: /
8977
build_so:
9078
executor: base
@@ -93,6 +81,7 @@ jobs:
9381
- restore_cache:
9482
keys:
9583
- v1-go-src-{{ .Branch }}-{{ .Revision }}
84+
- run: sudo make deps_arm
9685
- run: make build_so
9786
- store_artifacts:
9887
path: bin
@@ -101,10 +90,13 @@ workflows:
10190
main:
10291
jobs:
10392
- pre_deps_golang
104-
- test:
93+
- test_go:
94+
requires:
95+
- pre_deps_golang
96+
- test_javascript:
10597
requires:
10698
- pre_deps_golang
107-
- validate:
99+
- examples:
108100
requires:
109101
- pre_deps_golang
110102
- build_cli:

.eslintignore

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
__mocks__/
2+
dist/
3+
bin/
4+
node_modules/
5+
webpack/
6+
.DS_Store
7+
.npm
8+
node_modules
9+
npm-debug.*
10+
package-lock.json

.eslintrc

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
{
2+
"parser": "babel-eslint",
3+
"extends": "eslint-config-airbnb",
4+
"rules": {
5+
"arrow-parens": ["error", "as-needed"],
6+
"class-methods-use-this": "off",
7+
"comma-dangle": ["error", { "objects": "always-multiline" }],
8+
"import/no-named-as-default": "off",
9+
"import/no-unresolved": "off",
10+
"no-use-before-define": "off",
11+
"object-curly-newline": "off",
12+
"prefer-destructuring": "off",
13+
"react/destructuring-assignment": "off",
14+
"react/forbid-prop-types": "off",
15+
"react/jsx-filename-extension": "off",
16+
"react/jsx-no-bind": "off",
17+
"react/no-access-state-in-setstate": "off",
18+
"react/prefer-stateless-function": "off",
19+
"react/require-default-props": "off",
20+
"react/sort-comp": ["error", { // Team Preference
21+
"order": [
22+
"static-methods",
23+
"/constructor/",
24+
"/state/",
25+
"instance-variables",
26+
"lifecycle",
27+
"getters",
28+
"everything-else",
29+
"render"
30+
]
31+
}],
32+
"sort-keys": "error",
33+
"space-before-function-paren": ["error", "always"]
34+
}
35+
}

.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
bin
2+
dist
23
vendor
34
Gopkg.lock
45
*.so
56
*.h
7+
.DS_Store
8+
.npm
9+
node_modules
10+
npm-debug.*
11+
package-lock.json

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2018 Spatial Current, Inc.
3+
Copyright (c) 2019 Spatial Current, Inc.
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

Makefile

Lines changed: 138 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -17,58 +17,168 @@ ifndef DEST
1717
DEST=bin
1818
endif
1919

20-
deps:
20+
.PHONY: help
21+
22+
help: ## Print the help documentation
23+
@grep -E '^[a-zA-Z_-\]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
24+
25+
#
26+
# Dependencies
27+
#
28+
29+
deps_go: ## Install Go dependencies
2130
go get -d -t ./...
2231

23-
fmt:
32+
.PHONY: deps_go_test
33+
deps_go_test: ## Download Go dependencies for tests
34+
go get golang.org/x/tools/go/analysis/passes/shadow/cmd/shadow # download shadow
35+
go install golang.org/x/tools/go/analysis/passes/shadow/cmd/shadow # install shadow
36+
go get -u github.com/kisielk/errcheck # download and install errcheck
37+
go get -u github.com/client9/misspell/cmd/misspell # download and install misspell
38+
go get -u github.com/gordonklaus/ineffassign # download and install ineffassign
39+
go get -u honnef.co/go/tools/cmd/staticcheck # download and instal staticcheck
40+
go get -u golang.org/x/tools/cmd/goimports # download and install goimports
41+
42+
deps_arm: ## Install dependencies to cross-compile to ARM
43+
# ARMv7
44+
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
45+
# ARMv8
46+
apt-get install gcc-aarch64-linux-gnu g++-aarch64-linux-gnu
47+
48+
deps_gopherjs: ## Install GopherJS
49+
go get -u github.com/gopherjs/gopherjs
50+
51+
deps_javascript: ## Install dependencies for JavaScript tests
52+
npm install .
53+
54+
#
55+
# Go building, formatting, testing, and installing
56+
#
57+
58+
fmt: ## Format Go source code
2459
go fmt $$(go list ./... )
2560

26-
vet:
61+
imports: ## Update imports in Go source code
62+
# If missing, install goimports with: go get golang.org/x/tools/cmd/goimports
63+
goimports -w $$(find . -iname '*.go')
64+
65+
vet: ## Vet Go source code
2766
go vet $$(go list ./...)
2867

29-
test:
68+
test_go: ## Run Go tests
3069
bash scripts/test.sh
3170

32-
bin/gss_darwin_amd64:
71+
build: build_cli build_javascript build_so build_android ## Build CLI, Shared Objects (.so), JavaScript, and Android
72+
73+
install: ## Install GSS CLI on current platform
74+
go install -gcflags="$(GCFLAGS)" -ldflags="$(LDFLAGS)" github.com/spatialcurrent/go-simple-serializer/cmd/gss
75+
76+
#
77+
# Command line Programs
78+
#
79+
80+
bin/gss_darwin_amd64: ## Build GSS CLI for Darwin / amd64
3381
GOOS=darwin GOARCH=amd64 go build -o $(DEST)/gss_darwin_amd64 -gcflags="$(GCFLAGS)" -ldflags="$(LDFLAGS)" github.com/spatialcurrent/go-simple-serializer/cmd/gss
3482

35-
bin/gss_linux_amd64:
83+
bin/gss_linux_amd64: ## Build GSS CLI for Linux / amd64
3684
GOOS=linux GOARCH=amd64 go build -o $(DEST)/gss_linux_amd64 -gcflags="$(GCFLAGS)" -ldflags="$(LDFLAGS)" github.com/spatialcurrent/go-simple-serializer/cmd/gss
3785

38-
bin/gss_windows_amd64.exe:
86+
bin/gss_windows_amd64.exe: ## Build GSS CLI for Windows / amd64
3987
GOOS=windows GOARCH=amd64 go build -o $(DEST)/gss_windows_amd64.exe -gcflags="$(GCFLAGS)" -ldflags="$(LDFLAGS)" github.com/spatialcurrent/go-simple-serializer/cmd/gss
4088

41-
bin/gss_linux_arm64:
89+
bin/gss_linux_arm64: ## Build GSS CLI for Linux / arm64
4290
GOOS=linux GOARCH=arm64 go build -o $(DEST)/gss_linux_arm64 -gcflags="$(GCFLAGS)" -ldflags="$(LDFLAGS)" github.com/spatialcurrent/go-simple-serializer/cmd/gss
4391

44-
# Build Shared Object
45-
bin/gss.so:
46-
go build -o $(DEST)/gss.so -buildmode=c-shared -ldflags "$(LDFLAGS)" -gcflags="$(GCFLAGS)" github.com/spatialcurrent/go-simple-serializer/plugins/gss
92+
build_cli: bin/gss_darwin_amd64 bin/gss_linux_amd64 bin/gss_windows_amd64.exe bin/gss_linux_arm64 ## Build command line programs
93+
94+
#
95+
# Shared Objects
96+
#
97+
98+
bin/gss.so: ## Compile Shared Object for current platform
99+
# https://golang.org/cmd/link/
100+
# CGO Enabled : https://github.com/golang/go/issues/24068
101+
CGO_ENABLED=1 go build -o $(DEST)/gss.so -buildmode=c-shared -ldflags "$(LDFLAGS)" -gcflags="$(GCFLAGS)" github.com/spatialcurrent/go-simple-serializer/plugins/gss
102+
103+
bin/gss_linux_amd64.so: ## Compile Shared Object for Linux / amd64
104+
# https://golang.org/cmd/link/
105+
# CGO Enabled : https://github.com/golang/go/issues/24068
106+
GOOS=linux GOARCH=amd64 CGO_ENABLED=1 go build -o $(DEST)/gss_linux_amd64.so -buildmode=c-shared -ldflags "$(LDFLAGS)" -gcflags="$(GCFLAGS)" github.com/spatialcurrent/go-simple-serializer/plugins/gss
107+
108+
bin/gss_linux_armv7.so: ## Compile Shared Object for Linux / ARMv7
109+
# LDFLAGS - https://golang.org/cmd/link/
110+
# CGO Enabled - https://github.com/golang/go/issues/24068
111+
# GOARM/GOARCH Compatability Table - https://github.com/golang/go/wiki/GoArm
112+
# ARM Cross Compiler Required - https://www.acmesystems.it/arm9_toolchain
113+
GOOS=linux GOARCH=arm GOARM=7 CGO_ENABLED=1 CC=arm-linux-gnueabi-gcc go build -ldflags "-linkmode external -extldflags -static" -o $(DEST)/gss_linux_armv7.so -buildmode=c-shared -ldflags "$(LDFLAGS)" -gcflags="$(GCFLAGS)" github.com/spatialcurrent/go-simple-serializer/plugins/gss
114+
115+
bin/gss_linux_armv8.so: ## Compile Shared Object for Linux / ARMv8
116+
# LDFLAGS - https://golang.org/cmd/link/
117+
# CGO Enabled - https://github.com/golang/go/issues/24068
118+
# GOARM/GOARCH Compatability Table - https://github.com/golang/go/wiki/GoArm
119+
# ARM Cross Compiler Required - https://www.acmesystems.it/arm9_toolchain
120+
# Dependencies - https://www.96boards.org/blog/cross-compile-files-x86-linux-to-96boards/
121+
GOOS=linux GOARCH=arm64 CGO_ENABLED=1 CC=aarch64-linux-gnu-gcc go build -ldflags "-linkmode external -extldflags -static" -o $(DEST)/gss_linux_armv8.so -buildmode=c-shared -ldflags "$(LDFLAGS)" -gcflags="$(GCFLAGS)" github.com/spatialcurrent/go-simple-serializer/plugins/gss
122+
123+
build_so: bin/gss_linux_amd64.so bin/gss_linux_armv7.so bin/gss_linux_armv8.so ## Build Shared Objects (.so)
124+
125+
#
126+
# Android
127+
#
47128

48-
# Build JavaScript Library
49-
bin/gss.js:
50-
gopherjs build -o $(DEST)/gss.js github.com/spatialcurrent/go-simple-serializer/cmd/gss.js
129+
bin/gss.aar: ## Build Android Archive Library
130+
gomobile bind -target android -javapkg=com.spatialcurrent -o $(DEST)/gss.aar -gcflags="$(GCFLAGS)" github.com/spatialcurrent/go-simple-serializer/pkg/gss
51131

52-
# Build Minified JavaScript Library
53-
bin/gss.min.js:
54-
gopherjs build -m -o $(DEST)/gss.min.js github.com/spatialcurrent/go-simple-serializer/cmd/gss.js
132+
build_android: bin/gss.arr ## Build artifacts for Android
55133

56-
# Build Android Archive Library
57-
bin/gss.aar:
58-
gomobile bind -target android -javapkg=com.spatialcurrent -o $(DEST)/gss.aar -gcflags="$(GCFLAGS)" github.com/spatialcurrent/go-simple-serializer/gss
134+
#
135+
# JavaScript
136+
#
59137

60-
build_cli: bin/gss_darwin_amd64 bin/gss_linux_amd64 bin/gss_windows_amd64.exe bin/gss_linux_arm64
138+
dist/gss.mod.js: ## Build JavaScript module
139+
gopherjs build -o dist/gss.mod.js github.com/spatialcurrent/go-simple-serializer/cmd/gss.mod.js
61140

62-
build_javascript: bin/gss.js bin/gss.min.js
141+
dist/gss.mod.min.js: ## Build minified JavaScript module
142+
gopherjs build -m -o dist/gss.mod.min.js github.com/spatialcurrent/go-simple-serializer/cmd/gss.mod.js
63143

64-
build_android: bin/gss.arr
144+
dist/gss.global.js: ## Build JavaScript library that attaches to global or window.
145+
GSS_JS_EXPORT_GLOBAL=1 gopherjs build -o dist/gss.global.js github.com/spatialcurrent/go-simple-serializer/cmd/gss.global.js
65146

66-
build_so: bin/gss.so
147+
dist/gss.global.min.js: ## Build minified JavaScript library that attaches to global or window.
148+
GSS_JS_EXPORT_GLOBAL=1 gopherjs build -m -o dist/gss.global.min.js github.com/spatialcurrent/go-simple-serializer/cmd/gss.global.js
67149

68-
build: build_cli build_javascript build_so build_android
150+
build_javascript: dist/gss.mod.js dist/gss.mod.min.js dist/gss.global.js dist/gss.global.min.js ## Build artifacts for JavaScript
69151

70-
install:
71-
go install -gcflags="$(GCFLAGS)" -ldflags="$(LDFLAGS)" github.com/spatialcurrent/go-simple-serializer/cmd/gss
152+
test_javascript: ## Run JavaScript tests
153+
npm run test
154+
155+
lint: ## Lint JavaScript source code
156+
npm run lint
157+
158+
#
159+
# Examples
160+
#
161+
162+
bin/gss_example_c: bin/gss.so ## Build C example
163+
mkdir -p bin && cd bin && gcc -o gss_example_c -I. ./../examples/c/main.c -L. -l:gss.so
164+
165+
bin/gss_example_cpp: bin/gss.so ## Build C++ example
166+
mkdir -p bin && cd bin && g++ -o gss_example_cpp -I . ./../examples/cpp/main.cpp -L. -l:gss.so
167+
168+
run_example_c: bin/gss.so bin/gss_example_c ## Run C example
169+
cd bin && LD_LIBRARY_PATH=. ./gss_example_c
170+
171+
run_example_cpp: bin/gss.so bin/gss_example_cpp ## Run C++ example
172+
cd bin && LD_LIBRARY_PATH=. ./gss_example_cpp
173+
174+
run_example_python: bin/gss.so ## Run Python example
175+
LD_LIBRARY_PATH=bin python examples/python/test.py
176+
177+
run_example_javascript: dist/gss.mod.js ## Run JavaScript module example
178+
node examples/js/index.mod.js
179+
180+
## Clean
72181

73-
clean:
182+
clean: ## Clean artifacts
74183
rm -fr bin
184+
rm -fr dist

0 commit comments

Comments
 (0)