-
Notifications
You must be signed in to change notification settings - Fork 0
/
justfile
190 lines (163 loc) · 5.16 KB
/
justfile
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
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
set dotenv-load
depot_tools_repo := "https://chromium.googlesource.com/chromium/tools/depot_tools.git"
pdfium_repo := "https://pdfium.googlesource.com/pdfium.git"
pdfium_version := env_var_or_default("PDFIUM_VERSION", "6666")
target_os := env_var("TARGET_OS")
target_cpu := env_var("TARGET_CPU")
debug := env_var_or_default("DEBUG", "false") # release or debug
static_lib := env_var_or_default("STATIC_LIB", "true") # static or shared
enable_v8 := env_var_or_default("ENABLE_V8", "false") # v8
target := if env_var("TARGET_OS") == env_var("TARGET_CPU") { "$TARGET_OS" } else { "$TARGET_OS-$TARGET_CPU" }
args := env_var("PWD") / "args"
dist := env_var("PWD") / "dist"
patches := env_var("PWD") / "patches"
pdfium := env_var("PWD") / "pdfium"
packages := env_var("PWD") / "packages"
clone-depot-tools:
[ -d "depot_tools" ] || git clone {{depot_tools_repo}}
clone-pdfium:
[ -d "pdfium" ] || gclient config --unmanaged {{pdfium_repo}} --custom-var checkout_configuration=minimal
if [ -f ".gclient" ]; then \
if [ $(grep -c "target_os" .gclient) -eq 0 ]; then \
echo "target_os = ['$TARGET_OS']" >> .gclient; \
else \
sed -i -e 's/target_os = \[.*\]/target_os = \['\'$TARGET_OS\''\]/g' .gclient; \
fi \
fi
gclient sync -r origin/chromium/{{pdfium_version}} --no-history --shallow
build: clone-depot-tools
#!/usr/bin/env bash
set -euox pipefail
export PATH="$PATH:$PWD/depot_tools"
export DEPOT_TOOLS_WIN_TOOLCHAIN=0
for folder in pdfium \
pdfium/build \
pdfium/third_party/libjpeg_turbo \
pdfium/base/allocator/partition_allocator; do
if [ -e "$folder" ]; then
git -C $folder checkout .
git -C $folder reset --hard
git -C $folder clean -df
fi
done
just clone-pdfium
mkdir -p {{pdfium}}/out/{{target}}
env=$(
echo 'target_os = "{{target_os}}"'
echo 'target_cpu = "{{target_cpu}}"'
echo 'pdf_is_complete_lib = {{static_lib}}'
echo 'is_debug = {{debug}}'
echo 'pdf_enable_v8 = {{enable_v8}}'
cat {{args}}/common.gn
if [ "{{debug}}" == "false" ]; then
cat {{args}}/release.gn
fi
if [ -f {{args}}/$TARGET_OS.gn ]; then
cat {{args}}/$TARGET_OS.gn
fi
if [ -f {{args}}/$TARGET_OS.$TARGET_CPU.gn ]; then
cat {{args}}/$TARGET_OS.$TARGET_CPU.gn
fi
)
args="$(echo $env | sed 's/ = /=/g' | sort)"
[ "{{static_lib}}" == "false" ] && patch -d {{pdfium}} -p1 < {{patches}}/shared.patch
case "$TARGET_OS" in
ios)
patch -d {{pdfium}} -p1 < {{patches}}/ios.patch
patch -d {{pdfium}}/build -p1 < {{patches}}/ios.build.patch
;;
wasm)
patch -d {{pdfium}} -p1 < {{patches}}/wasm.patch
patch -d {{pdfium}}/build -p1 < {{patches}}/wasm.build.patch
;;
win)
patch -d {{pdfium}}/build -p1 < {{patches}}/win.build.patch
;;
esac
pushd {{pdfium}}
gn gen out/{{target}} --args="$args"
ninja -C out/{{target}} pdfium -v
popd
pack-base:
mkdir -p {{dist}}
mkdir -p {{dist}}/lib
mkdir -p {{dist}}/include
patch -d {{pdfium}} -p1 < {{patches}}/headers.patch
cp -r {{pdfium}}/public/* {{dist}}/include/
rm -f {{dist}}/include/DEPS
rm -f {{dist}}/include/README
rm -f {{dist}}/include/PRESUBMIT.py
[linux]
pack: pack-base
if "{{static_lib}}" == "true"; then \
cp {{pdfium}}/out/{{target}}/obj/libpdfium.a {{dist}}/lib; \
else \
cp {{pdfium}}/out/{{target}}/libpdfium.so {{dist}}/lib; \
fi
[macos]
pack: pack-base
if "{{static_lib}}" == "true"; then \
cp {{pdfium}}/out/{{target}}/obj/libpdfium.a {{dist}}/lib; \
else \
cp {{pdfium}}/out/{{target}}/libpdfium.dylib {{dist}}/lib; \
fi
[windows]
pack: pack-base
if "{{static_lib}}" == "true"; then \
cp {{pdfium}}/out/{{target}}/obj/pdfium.lib {{dist}}/lib; \
else \
cp {{pdfium}}/out/{{target}}/pdfium.dll {{dist}}/lib; \
cp {{pdfium}}/out/{{target}}/pdfium.dll.lib {{dist}}/lib; \
fi
# https://github.com/emscripten-core/emscripten/blob/main/src/settings.js
# `emc++ --help`
[group('wasm')]
build-wasm name='createPDFium' esm='1' flag=(if debug == "true" {"-g"} else {"-Oz"}):
em++ \
{{flag}} \
-s EXPORTED_FUNCTIONS=[_malloc,_free,`just list-exported-functions | paste -sd "," -`] \
-s EXPORTED_RUNTIME_METHODS=[`just list-runtime-methods | sed 's/ /,/g'`] \
-s EXPORT_ES6={{esm}} \
-s EXPORT_NAME={{name}} \
-s DEMANGLE_SUPPORT=0 \
-s USE_ZLIB=1 \
-s USE_LIBJPEG=1 \
-s ASSERTIONS=1 \
-s ALLOW_MEMORY_GROWTH=1 \
-s MODULARIZE=1 \
-s WASM=1 \
-s ENVIRONMENT=worker \
-std=c++11 \
-Wall \
--no-entry \
-I{{dist}}/include \
-L{{dist}}/lib \
-lpdfium \
-o {{dist}}/pdfium.js
[group('wasm')]
list-exported-functions:
llvm-nm {{dist}}/lib/libpdfium.a --format=just-symbols --quiet \
| grep "^FPDF\|^FSDK\|^FORM\|^IFSDK" \
| sed 's/^/_/' \
| sort \
| uniq
[group('wasm')]
list-runtime-methods:
echo \
ccall \
cwrap \
wasmExports \
stringToUTF8 \
stringToNewUTF8 \
lengthBytesUTF8 \
UTF8ToString \
UTF16ToString \
intArrayToString \
getValue
[group('wasm')]
install-wasm:
mkdir -p {{packages}}/pdfium/dist
cp {{dist}}/pdfium.js {{packages}}/pdfium/dist/index.js
cp {{dist}}/pdfium.wasm {{packages}}/pdfium/dist
test:
echo "test"