-
Notifications
You must be signed in to change notification settings - Fork 11
/
Makefile
165 lines (122 loc) · 4.5 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
COMMIT=$(shell git rev-parse HEAD)
VERSION=$(shell git describe --tags --exact-match --always)
VERSION=$(shell cat VERSION)
DATE=$(shell date +'%FT%TZ%z')
VENDOR_SQLITE=$(shell pwd)/sqlite
GO_BUILD_LDFLAGS=-ldflags '-X main.Version=v$(VERSION) -X main.Commit=$(COMMIT) -X main.Date=$(DATE)'
GO_BUILD_CGO_CFLAGS=CGO_ENABLED=1 CGO_CFLAGS="-DUSE_LIBSQLITE3" CPATH="$(VENDOR_SQLITE)"
ifeq ($(shell uname -s),Darwin)
CONFIG_DARWIN=y
else ifeq ($(OS),Windows_NT)
CONFIG_WINDOWS=y
else
CONFIG_LINUX=y
endif
# framework stuff is needed bc https://github.com/golang/go/issues/42459#issuecomment-896089738
ifdef CONFIG_DARWIN
LOADABLE_EXTENSION=dylib
SQLITE3_CFLAGS=-framework CoreFoundation -framework Security
endif
ifdef CONFIG_LINUX
LOADABLE_EXTENSION=so
endif
ifdef CONFIG_WINDOWS
LOADABLE_EXTENSION=dll
endif
ifdef python
PYTHON=$(python)
else
PYTHON=python3
endif
ifdef IS_MACOS_ARM
RENAME_WHEELS_ARGS=--is-macos-arm
else
RENAME_WHEELS_ARGS=
endif
prefix=dist
TARGET_LOADABLE=$(prefix)/http0.$(LOADABLE_EXTENSION)
TARGET_WHEELS=$(prefix)/wheels
TARGET_OBJ=$(prefix)/http0.o
TARGET_SQLITE3=$(prefix)/sqlite3
INTERMEDIATE_PYPACKAGE_EXTENSION=python/sqlite_http/sqlite_http/http0.$(LOADABLE_EXTENSION)
loadable: $(TARGET_LOADABLE)
all: loadable
GO_FILES= ./cookies.go ./settings.go ./do.go ./shared.go ./meta.go ./headers.go
$(prefix):
mkdir -p $(prefix)
$(TARGET_WHEELS): $(prefix)
mkdir -p $(TARGET_WHEELS)
$(TARGET_LOADABLE): $(GO_FILES)
$(GO_BUILD_CGO_CFLAGS) go build \
-buildmode=c-shared -o $@ -tags="shared" \
$(GO_BUILD_LDFLAGS) \
.
python: $(TARGET_WHEELS) $(TARGET_LOADABLE) $(TARGET_WHEELS) scripts/rename-wheels.py $(shell find python/sqlite_http -type f -name '*.py')
cp $(TARGET_LOADABLE) $(INTERMEDIATE_PYPACKAGE_EXTENSION)
rm $(TARGET_WHEELS)/sqlite_http* || true
pip3 wheel python/sqlite_http/ -w $(TARGET_WHEELS)
python3 scripts/rename-wheels.py $(TARGET_WHEELS) $(RENAME_WHEELS_ARGS)
echo "✅ generated python wheel"
python-versions: python/version.py.tmpl
VERSION=$(VERSION) envsubst < python/version.py.tmpl > python/sqlite_http/sqlite_http/version.py
echo "✅ generated python/sqlite_http/sqlite_http/version.py"
VERSION=$(VERSION) envsubst < python/version.py.tmpl > python/datasette_sqlite_http/datasette_sqlite_http/version.py
echo "✅ generated python/datasette_sqlite_http/datasette_sqlite_http/version.py"
datasette: $(TARGET_WHEELS) $(shell find python/datasette_sqlite_http -type f -name '*.py')
rm $(TARGET_WHEELS)/datasette* || true
pip3 wheel python/datasette_sqlite_http/ --no-deps -w $(TARGET_WHEELS)
bindings/sqlite-utils/pyproject.toml: bindings/sqlite-utils/pyproject.toml.tmpl VERSION
VERSION=$(VERSION) envsubst < $< > $@
echo "✅ generated $@"
bindings/sqlite-utils/sqlite_utils_sqlite_http/version.py: bindings/sqlite-utils/sqlite_utils_sqlite_http/version.py.tmpl VERSION
VERSION=$(VERSION) envsubst < $< > $@
echo "✅ generated $@"
sqlite-utils: $(TARGET_WHEELS) bindings/sqlite-utils/pyproject.toml bindings/sqlite-utils/sqlite_utils_sqlite_http/version.py
python3 -m build bindings/sqlite-utils -w -o $(TARGET_WHEELS)
npm: VERSION npm/platform-package.README.md.tmpl npm/platform-package.package.json.tmpl npm/sqlite-http/package.json.tmpl scripts/npm_generate_platform_packages.sh
scripts/npm_generate_platform_packages.sh
deno: VERSION deno/deno.json.tmpl
scripts/deno_generate_package.sh
bindings/ruby/lib/version.rb: bindings/ruby/lib/version.rb.tmpl VERSION
VERSION=$(VERSION) envsubst < $< > $@
ruby: bindings/ruby/lib/version.rb
version:
make python
make python-versions
make bindings/sqlite-utils/pyproject.toml bindings/sqlite-utils/sqlite_utils_sqlite_http/version.py
make npm
make deno
make ruby
$(TARGET_OBJ): $(GO_FILES)
$(GO_BUILD_CGO_CFLAGS) CGO_ENABLED=1 go build -buildmode=c-archive \
$(GO_BUILD_LDFLAGS) \
-o $@ .
dist/sqlite3-extra.c: sqlite/sqlite3.c sqlite/core_init.c
cat sqlite/sqlite3.c sqlite/core_init.c > $@
format:
gofmt -s -w .
httpbin:
docker run -p 8080:80 kennethreitz/httpbin
clean:
rm dist/*
test-loadable:
$(PYTHON) tests/test-loadable.py
test-python:
$(PYTHON) tests/test-python.py
test-npm:
node npm/sqlite-http/test.js
test-deno:
deno task --config deno/deno.json test
test-watch:
watchexec --clear -w tests/test-loadable.py make test-loadable
test:
make test-loadable
make test-python
make test-npm
make test-deno
publish-release:
./scripts/publish_release.sh
.PHONY: all format clean publish-release \
python python-versions datasette sqlite-utils npm deno ruby version \
test test-loadable test-watch httpbin \
loadable