Skip to content

Commit 377f994

Browse files
committed
build: Added build handy tools
Added bin folder to gitignore, added Makefile for building.
1 parent 723f0fd commit 377f994

3 files changed

Lines changed: 98 additions & 0 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1+
bin/
12
.idea/

Makefile

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
# MAINTAINER: David López <d.lopez@saltosystems.com>
2+
3+
APP = sqlfmt
4+
OS = amd64-linux-gnu amd64-linux-musl amd64-darwin amd64-windows
5+
SHELL := /bin/bash
6+
7+
# Overridable by CI
8+
COMMIT_SHORT ?= $(shell git rev-parse --verify --short HEAD)
9+
VERSION ?= $(COMMIT_SHORT)
10+
VERSION_NOPREFIX ?= $(shell echo $(VERSION) | sed -e 's/^[[v]]*//')
11+
12+
# Build vars
13+
CGO_ENABLED = 1
14+
GOOS :=
15+
GOARCH :=
16+
CC :=
17+
CXX :=
18+
LDFLAGS :=
19+
EXTRA_CMAKE_FLAGS :=
20+
SUFFIX :=
21+
EXT :=
22+
23+
#
24+
# Common methodology based targets
25+
#
26+
.PHONY: build
27+
build:
28+
@for app in $(APP) ; do \
29+
for os in $(OS) ; do \
30+
if [ "$$os" == "amd64-linux-gnu" ]; then \
31+
GOOS=linux; \
32+
GOARCH=amd64; \
33+
CC=x86_64-unknown-linux-gnu-cc; \
34+
CXX=x86_64-unknown-linux-gnu-c++; \
35+
LDFLAGS="-static-libgcc -static-libstdc++"; \
36+
SUFFIX=-linux-2.6.32-gnu-amd64; \
37+
fi; \
38+
if [ "$$os" == "amd64-linux-musl" ]; then \
39+
GOOS=linux; \
40+
GOARCH=amd64; \
41+
CC=x86_64-unknown-linux-musl-cc; \
42+
CXX=x86_64-unknown-linux-musl-c++; \
43+
LDFLAGS=-static; \
44+
SUFFIX=-linux-2.6.32-musl-amd64; \
45+
fi; \
46+
if [ "$$os" == "amd64-darwin" ]; then \
47+
echo "entra"; \
48+
GOOS=darwin; \
49+
GOARCH=amd64; \
50+
CC=x86_64-apple-darwin13-cc; \
51+
CXX=x86_64-apple-darwin13-c++; \
52+
EXTRA_CMAKE_FLAGS=-DCMAKE_INSTALL_NAME_TOOL=x86_64-apple-darwin13-install_name_tool; \
53+
SUFFIX=-darwin-10.9-amd64; \
54+
fi; \
55+
if [ "$$os" == "amd64-windows" ]; then \
56+
EXT=".exe"; \
57+
GOOS=windows; \
58+
GOARCH=amd64; \
59+
CC=x86_64-w64-mingw32-cc; \
60+
CXX=x86_64-w64-mingw32-c++; \
61+
LDFLAGS=-static; \
62+
SUFFIX=-windows-6.2-amd64; \
63+
fi; \
64+
CGO_ENABLED=$(CGO_ENABLED) GOOS=$$GOOS GOARCH=$$GOARCH \
65+
CC=$$CC CXX=$$CXX EXTRA_CMAKE_FLAGS=$$EXTRA_CMAKE_FLAGS SUFFIX=$$SUFFIX \
66+
go build \
67+
-a -x -v -ldflags "$(LDFLAGS) \
68+
-X main.Version=$(VERSION_NOPREFIX) \
69+
-X main.GitRev=$(COMMIT_SHORT) \
70+
" \
71+
-o ./bin/$$app-$(VERSION_NOPREFIX)-$$os$$EXT \
72+
./cmd/$$app; \
73+
done; \
74+
done;

README.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,4 +73,27 @@ Flags:
7373
7474
```
7575
Error: syntax error at or near "fron"
76+
```
77+
78+
## Build cross-platform binaries from source
79+
80+
Each release comes with pre-compiled binaries for several platforms:
81+
82+
https://github.com/lopezator/sqlfmt/releases
83+
84+
Anyway, if you want to cross-compile from source, you can do it using docker in a handy way:
85+
86+
1. Build container:
87+
```
88+
$> docker run --rm -t -d --name="sqlfmt-builder" -v="$PWD:/go/src/github.com/lopezator/sqlfmt" --workdir="/go/src/github.com/lopezator/sqlfmt" --entrypoint="cat" cockroachdb/builder:20180813-101406
89+
```
90+
91+
2. Build binaries inside the container:
92+
```
93+
$> docker exec -it sqlfmt-builder make build
94+
```
95+
96+
3. Stop container:
97+
```
98+
$> docker container stop sqlfmt-builder
7699
```

0 commit comments

Comments
 (0)