Skip to content

Commit 3a201ec

Browse files
committed
Build packed soljson.js.
1 parent 6895972 commit 3a201ec

File tree

6 files changed

+74
-6
lines changed

6 files changed

+74
-6
lines changed

.circleci/config.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -982,10 +982,10 @@ jobs:
982982
command: |
983983
scripts/ci/build_emscripten.sh
984984
- store_artifacts:
985-
path: emscripten_build/libsolc/soljson.js
985+
path: upload/soljson.js
986986
destination: soljson.js
987987
- run: mkdir -p workspace
988-
- run: cp emscripten_build/libsolc/soljson.js workspace/soljson.js
988+
- run: cp upload/soljson.js workspace/soljson.js
989989
- run: scripts/get_version.sh > workspace/version.txt
990990
- persist_to_workspace:
991991
root: workspace

cmake/EthCompilerSettings.cmake

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,8 +142,6 @@ if (("${CMAKE_CXX_COMPILER_ID}" MATCHES "GNU") OR ("${CMAKE_CXX_COMPILER_ID}" MA
142142
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -s WASM=1")
143143
# Set webassembly build to synchronous loading.
144144
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -s WASM_ASYNC_COMPILATION=0")
145-
# Output a single js file with the wasm binary embedded as base64 string.
146-
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -s SINGLE_FILE=1")
147145
# Allow new functions to be added to the wasm module via addFunction.
148146
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -s ALLOW_TABLE_GROWTH=1")
149147
# Disable warnings about not being pure asm.js due to memory growth.

cmake/templates/license.h.in

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,36 @@ evmc:
137137
See the License for the specific language governing permissions and
138138
limitations under the License.
139139

140+
mini-lz4:
141+
The file scripts/ci/mini-lz4.js is derived from the emscripten adaptation of
142+
node-lz4 and licensed under the following terms:
143+
144+
Copyright (c) 2012 Pierre Curto
145+
146+
Permission is hereby granted, free of charge, to any person obtaining a copy
147+
of this software and associated documentation files (the "Software"), to deal
148+
in the Software without restriction, including without limitation the rights
149+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
150+
copies of the Software, and to permit persons to whom the Software is
151+
furnished to do so, subject to the following conditions:
152+
153+
The above copyright notice and this permission notice shall be included in
154+
all copies or substantial portions of the Software.
155+
156+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
157+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
158+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
159+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
160+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
161+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
162+
THE SOFTWARE.
163+
164+
base64:
165+
The file scripts/ci/base64DecToArr.js is derived from a code example
166+
in the MDN Web Docs, which permits use under CC0 terms:
167+
168+
Any copyright is dedicated to the Public Domain. http://creativecommons.org/publicdomain/zero/1.0/
169+
140170

141171
All other code is licensed under GPL version 3:
142172

scripts/ci/build_emscripten.sh

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ else
4040
BUILD_DIR="$1"
4141
fi
4242

43+
apt-get update && apt-get install lz4
44+
4345
WORKSPACE=/root/project
4446

4547
cd $WORKSPACE
@@ -71,8 +73,8 @@ make soljson
7173

7274
cd ..
7375
mkdir -p upload
74-
cp "$BUILD_DIR/libsolc/soljson.js" upload/
75-
cp "$BUILD_DIR/libsolc/soljson.js" ./
76+
scripts/ci/pack_soljson.sh "$BUILD_DIR/libsolc/soljson.js" "$BUILD_DIR/libsolc/soljson.wasm" upload/soljson.js
77+
cp upload/soljson.js ./
7678

7779
OUTPUT_SIZE=$(ls -la soljson.js)
7880

scripts/ci/mini-lz4.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
function uncompress(source, uncompressedSize) {
22
/*
33
based off https://github.com/emscripten-core/emscripten/blob/main/third_party/mini-lz4.js
4+
The license only applies to the body of this function (``uncompress``).
45
====
56
MiniLZ4: Minimal LZ4 block decoding and encoding.
67

scripts/ci/pack_soljson.sh

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
4+
script_dir="$(realpath "$(dirname "$0")")"
5+
soljson_js="$1"
6+
soljson_wasm="$2"
7+
soljson_wasm_size=$(wc -c "${soljson_wasm}" | cut -d ' ' -f 1)
8+
output="$3"
9+
10+
(( $# == 3 )) || { >&2 echo "Usage: $0 soljson.js soljson.wasm packed_soljson.js"; exit 1; }
11+
12+
# If this changes in an emscripten update, it's probably nothing to worry about,
13+
# but we should double-check when it happens and adjust the tail command below.
14+
[[ $(head -c 5 "${soljson_js}") == "null;" ]] || { >&2 echo 'Expected soljson.js to start with "null;"'; exit 1; }
15+
16+
echo "Packing $soljson_js and $soljson_wasm to $output."
17+
(
18+
echo -n 'var Module = Module || {}; Module["wasmBinary"] = '
19+
echo -n '(function(source, uncompressedSize) {'
20+
# Note that base64DecToArr assumes no trailing equals signs.
21+
cpp "${script_dir}/base64DecToArr.js" | grep -v "^#.*"
22+
# Note that mini-lz4.js assumes no file header and no frame crc checksums.
23+
cpp "${script_dir}/mini-lz4.js" | grep -v "^#.*"
24+
echo 'return uncompress(base64DecToArr(source), uncompressedSize);})('
25+
echo -n '"'
26+
# We fix lz4 format settings, remove the 8 bytes file header and remove the trailing equals signs of the base64 encoding.
27+
lz4c --no-frame-crc --best --favor-decSpeed "${soljson_wasm}" - | tail -c +8 | base64 -w 0 | sed 's/[^A-Za-z0-9\+\/]//g'
28+
echo '",'
29+
echo -n "${soljson_wasm_size});"
30+
# Remove "null;" from the js wrapper.
31+
tail -c +6 "${soljson_js}"
32+
) > "$output"
33+
34+
echo "Testing $output."
35+
echo "process.stdout.write(require('$(realpath "${output}")').wasmBinary)" | node | cmp "${soljson_wasm}" && echo "Binaries match."
36+
# Allow the wasm binary to be garbage collected after compilation.
37+
echo 'Module["wasmBinary"] = undefined;' >> "${output}"

0 commit comments

Comments
 (0)