Skip to content

Commit 22466ac

Browse files
committed
Experimental wasm rebuild scripts
1 parent 3d4a221 commit 22466ac

File tree

6 files changed

+493
-0
lines changed

6 files changed

+493
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
#!/usr/bin/env bash
2+
3+
#------------------------------------------------------------------------------
4+
# Script used for cross-platform comparison as part of the travis automation.
5+
# Splits all test source code into multiple files, generates bytecode and
6+
# uploads the bytecode into github.com/ethereum/solidity-test-bytecode where
7+
# another travis job is triggered to do the actual comparison.
8+
#
9+
# ------------------------------------------------------------------------------
10+
# This file is part of solidity.
11+
#
12+
# solidity is free software: you can redistribute it and/or modify
13+
# it under the terms of the GNU General Public License as published by
14+
# the Free Software Foundation, either version 3 of the License, or
15+
# (at your option) any later version.
16+
#
17+
# solidity is distributed in the hope that it will be useful,
18+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
19+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20+
# GNU General Public License for more details.
21+
#
22+
# You should have received a copy of the GNU General Public License
23+
# along with solidity. If not, see <http://www.gnu.org/licenses/>
24+
#
25+
# (c) 2017 solidity contributors.
26+
#------------------------------------------------------------------------------
27+
28+
set -e
29+
30+
SCRIPTDIR=$(dirname "$0")
31+
SCRIPTDIR=$(realpath "${SCRIPTDIR}")
32+
33+
34+
echo "Compiling all test contracts into bytecode..."
35+
TMPDIR=$(mktemp -d)
36+
(
37+
cd "${TMPDIR}"
38+
"${SCRIPTDIR}/isolate_tests.py" /src/test/
39+
40+
cat > solc <<EOF
41+
#!/usr/bin/env node
42+
var process = require('process')
43+
var fs = require('fs')
44+
45+
var compiler = require('/root/solc-js/wrapper.js')(require("${1}"))
46+
47+
for (var optimize of [false, true])
48+
{
49+
for (var filename of process.argv.slice(2))
50+
{
51+
if (filename !== undefined)
52+
{
53+
var inputs = {}
54+
inputs[filename] = { content: fs.readFileSync(filename).toString() }
55+
var input = {
56+
language: 'Solidity',
57+
sources: inputs,
58+
settings: {
59+
optimizer: { enabled: optimize },
60+
outputSelection: { '*': { '*': ['*'] } }
61+
}
62+
}
63+
try {
64+
var result = JSON.parse(compiler.compile(JSON.stringify(input)))
65+
if (
66+
!('contracts' in result) ||
67+
Object.keys(result['contracts']).length === 0
68+
)
69+
{
70+
// NOTE: do not exit here because this may be run on source which cannot be compiled
71+
console.log(filename + ': ERROR')
72+
}
73+
else
74+
{
75+
for (var outputName in result['contracts'])
76+
for (var contractName in result['contracts'][outputName])
77+
{
78+
var contractData = result['contracts'][outputName][contractName];
79+
if (contractData.evm !== undefined && contractData.evm.bytecode !== undefined)
80+
console.log(filename + ':' + contractName + ' ' + contractData.evm.bytecode.object)
81+
else
82+
console.log(filename + ':' + contractName + ' NO BYTECODE')
83+
console.log(filename + ':' + contractName + ' ' + contractData.metadata)
84+
}
85+
}
86+
} catch (e) {
87+
console.log(filename + ': FATAL ERROR')
88+
console.error(filename)
89+
console.error(inputs)
90+
}
91+
}
92+
}
93+
}
94+
EOF
95+
chmod +x solc
96+
./solc *.sol > /tmp/report.txt
97+
)
98+
rm -rf "$TMPDIR"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
#!/usr/bin/env python2
2+
3+
import sys
4+
import re
5+
import os
6+
import hashlib
7+
from os.path import join, isfile
8+
9+
10+
def extract_test_cases(path):
11+
lines = open(path, 'rb').read().splitlines()
12+
13+
inside = False
14+
delimiter = ''
15+
tests = []
16+
17+
for l in lines:
18+
if inside:
19+
if l.strip().endswith(')' + delimiter + '";'):
20+
tests[-1] += l.strip()[:-(3 + len(delimiter))]
21+
inside = False
22+
else:
23+
tests[-1] += l + '\n'
24+
else:
25+
m = re.search(r'R"([^(]*)\((.*)$', l.strip())
26+
if m:
27+
inside = True
28+
delimiter = m.group(1)
29+
tests += [m.group(2)]
30+
31+
return tests
32+
33+
def extract_and_write(f, path):
34+
if f.endswith('.sol'):
35+
cases = [open(path, 'r').read()]
36+
else:
37+
cases = extract_test_cases(path)
38+
write_cases(f, cases)
39+
40+
def write_cases(f, tests):
41+
cleaned_filename = f.replace(".","_").replace("-","_").replace(" ","_").lower()
42+
for test in tests:
43+
remainder = re.sub(r'^ {4}', '', test, 0, re.MULTILINE)
44+
open('test_%s_%s.sol' % (hashlib.sha256(test).hexdigest(), cleaned_filename), 'w').write(remainder)
45+
46+
47+
if __name__ == '__main__':
48+
path = sys.argv[1]
49+
50+
for root, subdirs, files in os.walk(path):
51+
if '_build' in subdirs:
52+
subdirs.remove('_build')
53+
for f in files:
54+
path = join(root, f)
55+
extract_and_write(f, path)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#!/bin/bash
2+
3+
TAG="$1"
4+
SOLJSON_JS="$2"
5+
6+
# If we ever want to patch the binaries e.g. for compatibility with older solc-js versions,
7+
# we can do that here.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
#!/bin/bash -e
2+
3+
# Do not call this script directly.
4+
5+
# This script is expected to be run inside the docker image trzeci/emscripten:sdk-tag-1.39.3-64bit and
6+
# be called by ./rebuild_tags.sh.
7+
8+
echo "========== STAGE 1: PREPARE ========== ($(date))"
9+
COMMIT_DATE="$(git show -s --format=%cI HEAD)"
10+
git rev-parse --short=8 HEAD >commit_hash.txt
11+
echo -e "" >prerelease.txt
12+
sed -i -e 's/-Wl,--gc-sections//' cmake/EthCompilerSettings.cmake
13+
echo "set(CMAKE_CXX_FLAGS \"\${CMAKE_CXX_FLAGS} -s EXTRA_EXPORTED_RUNTIME_METHODS=['cwrap','addFunction','removeFunction','UTF8ToString','lengthBytesUTF8','_malloc','stringToUTF8','setValue'] -s WASM=1 -s WASM_ASYNC_COMPILATION=0 -s SINGLE_FILE=1 -Wno-almost-asm\")" >>cmake/EthCompilerSettings.cmake
14+
# Needed for < 0.5.0.
15+
sed -i -e 's/-Werror/-Wno-error/' cmake/EthCompilerSettings.cmake
16+
17+
echo "========== STAGE 2: BUILD ========== ($(date))"
18+
scripts/travis-emscripten/install_deps.sh
19+
if [ -d cryptopp ]; then
20+
# Needed for < 0.4.4. Will not affect >= 0.4.5.
21+
# Unfortunately we need to update to the latest
22+
# release in the 5.6 series for it to build.
23+
# Hopefully we don't miss any bugs.
24+
rm -rf cryptopp
25+
git clone https://github.com/weidai11/cryptopp/
26+
(
27+
set -e
28+
cd cryptopp
29+
git checkout CRYPTOPP_5_6_5
30+
ln -s . src
31+
)
32+
fi
33+
if [ -d jsoncpp ]; then
34+
# Needed for < 0.4.4. Will not affect >= 0.4.5.
35+
(
36+
set -e
37+
cd jsoncpp
38+
# Checkout the latest commit at the time of our release.
39+
git checkout $(git rev-list -1 --before=$COMMIT_DATE master)
40+
)
41+
fi
42+
43+
set +e
44+
scripts/travis-emscripten/build_emscripten.sh
45+
set -e
46+
47+
mkdir -p upload
48+
49+
if [ ! -f upload/soljson.js ]; then
50+
if [ -f build/solc/soljson.js ]; then
51+
cp build/solc/soljson.js upload
52+
elif [ -f build/libsolc/soljson.js ]; then
53+
cp build/libsolc/soljson.js upload
54+
elif [ -f emscripten_build/solc/soljson.js ]; then
55+
cp emscripten_build/solc/soljson.js upload
56+
elif [ -f emscripten_build/libsolc/soljson.js ]; then
57+
cp emscripten_build/libsolc/soljson.js upload
58+
fi
59+
fi
60+
61+
if [ -f upload/soljson.js ]; then
62+
echo "========== SUCCESS ========== ($(date))"
63+
exit 0
64+
else
65+
echo "========== FAILURE ========== ($(date))"
66+
exit 1
67+
fi

0 commit comments

Comments
 (0)