Skip to content

Commit

Permalink
Build script updates:
Browse files Browse the repository at this point in the history
* Removed curses modules.
* Added ctypes module (disabled by defualt).
* Switched to using LLVM optimization from emscripten.py.
* Added sign/overflow correction for modules (no lines defined yet).
* Avoided mapping python.js to the virtual filesystem.
* Minor cleanup not affecting functionality.
  • Loading branch information
max99x committed Aug 18, 2011
1 parent 614f2f6 commit 7e1c8de
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 55 deletions.
66 changes: 19 additions & 47 deletions build
Expand Up @@ -58,8 +58,6 @@ MODULES[gdbm]="gdbmmodule.c"
MODULES[termios]="termios.c"
MODULES[resource]="resource.c"
MODULES[nis]="nismodule.c"
MODULES[_curses]="_cursesmodule.c"
MODULES[_curses_panel]="_curses_panel.c"
MODULES[zlib]="zlibmodule.c"
MODULES[binascii]="binascii.c"
MODULES[bz2]="bz2module.c"
Expand All @@ -76,6 +74,9 @@ MODULES[pyexpat]="pyexpat.c expat/xmlparse.c expat/xmlrole.c expat/xmltok.c"
MODULES[parser]="parsermodule.c"
MODULES[_struct]="_struct.c"

# These are disabled because of problems with libffi.
# MODULES[_ctypes]="_ctypes/_ctypes.c _ctypes/callbacks.c _ctypes/callproc.c _ctypes/stgdict.c _ctypes/cfield.c"

# These are baked into the main executable but can also be built separately.
# MODULES[_symtable]="symtablemodule.c"
# MODULES[zipimport]="zipimport.c"
Expand All @@ -98,7 +99,7 @@ CORRECT_SIGNS_LINES='["compile.c:3433","compile.c:3542","compile.c:3670","compil
################################################################################

function build_module {
echo "Building $1..."
echo " Building $1..."

# Compile.
FLAGS="-c -emit-llvm -fPIC -fno-strict-aliasing -I. -IInclude -I../cpython/Include -Wstrict-prototypes"
Expand All @@ -111,18 +112,13 @@ function build_module {
# Link.
../ccproxy.py $FILES -o $1.so.bc

# Optimize.
if [ $OPTIMIZED -eq 1 ]; then
${LLVM}/opt -O3 -o $1.so.opt.bc $1.so.bc
else
cp $1.so.bc $1.so.opt.bc
fi

# Emscript.
python2 ../emscripten/emscripten.py $1.so.opt.bc \
python2 ../emscripten/emscripten.py $1.so.bc \
-o $1.so.js \
-s BUILD_AS_SHARED_LIB=1 \
-s EXPORTED_FUNCTIONS="[\"_init$1\"]" \
-s CORRECT_SIGNS=2 -s CORRECT_SIGNS_LINES=$CORRECT_SIGNS_LINES \
-s CORRECT_OVERFLOWS=2 -s CORRECT_OVERFLOWS_LINES=$CORRECT_OVERFLOWS_LINES \
$OPTIMIZATION_ARGS

# Copy the new module to dist.
Expand All @@ -142,10 +138,11 @@ set -e

# Setup optimization flags for all future emscripting.
if [ $OPTIMIZED -eq 1 ]; then
# TODO: Figure out if reloop is useful.
OPTIMIZATION_ARGS="-s OPTIMIZE=1 -s RELOOP=0 -s ASSERTIONS=0"
# TODO: Figure out if reloop is possible and useful.
# TODO: Find the bug with USE_TYPED_ARRAYS=1 and =2.
OPTIMIZATION_ARGS="-O -s OPTIMIZE=1 -s RELOOP=0 -s ASSERTIONS=0"
else
OPTIMIZATION_ARGS="-s OPTIMIZE=0 -s RELOOP=0 -s ASSERTIONS=1"
OPTIMIZATION_ARGS=" -s OPTIMIZE=0 -s RELOOP=0 -s ASSERTIONS=1"
fi

# Create two folders for intermediate and final files, respectively.
Expand All @@ -154,7 +151,7 @@ mkdir -p dist

# Remove old build.
rm -rf obj/*
rm -rf dist/*
rm -rf dist/{python.js,lib}

# Start building in the obj folder.
cd obj
Expand Down Expand Up @@ -188,17 +185,9 @@ ${LLVM}/llvm-link -o=python.bc *.o
cp python.bc ..
cd ..

# Run LLVM optimizations.
if [ $OPTIMIZED -eq 1 ]; then
echo 'Running LLVM optimizations...'
${LLVM}/opt -O3 -o python.opt.bc python.bc
else
cp python.bc python.opt.bc
fi

# Compile the bytecode into JS using Emscripten.
echo 'Emscripting...'
python2 ../emscripten/emscripten.py python.opt.bc \
python2 ../emscripten/emscripten.py python.bc \
-m \
-o python.js \
-s INVOKE_RUN=0 \
Expand All @@ -216,29 +205,12 @@ cp python.js ../dist/python.js
mkdir -p ../dist/lib
mkdir -p ../dist/lib/python2.7
cp -r ../cpython/Lib/* ../dist/lib/python2.7
rm -rf ../dist/lib/python2.7/idlelib
rm -rf ../dist/lib/python2.7/lib-tk
rm -rf ../dist/lib/python2.7/plat-aix3
rm -rf ../dist/lib/python2.7/plat-aix4
rm -rf ../dist/lib/python2.7/plat-atheos
rm -rf ../dist/lib/python2.7/plat-beos5
rm -rf ../dist/lib/python2.7/plat-darwin
rm -rf ../dist/lib/python2.7/plat-freebsd4
rm -rf ../dist/lib/python2.7/plat-freebsd5
rm -rf ../dist/lib/python2.7/plat-freebsd6
rm -rf ../dist/lib/python2.7/plat-freebsd7
rm -rf ../dist/lib/python2.7/plat-freebsd8
rm -rf ../dist/lib/python2.7/plat-generic
rm -rf ../dist/lib/python2.7/plat-irix5
rm -rf ../dist/lib/python2.7/plat-irix6
rm -rf ../dist/lib/python2.7/plat-mac
rm -rf ../dist/lib/python2.7/plat-netbsd1
rm -rf ../dist/lib/python2.7/plat-next3
rm -rf ../dist/lib/python2.7/plat-os2emx
rm -rf ../dist/lib/python2.7/plat-riscos
rm -rf ../dist/lib/python2.7/plat-sunos5
rm -rf ../dist/lib/python2.7/plat-unixware7
# TODO: Precompile pure modules.
rm -rf ../dist/lib/python2.7/{idlelib,lib-tk}
rm -rf ../dist/lib/python2.7/plat-{aix3,aix4,atheos,beos5,darwin,freebsd4,freebsd5,freebsd6,freebsd7,freebsd8,generic,irix5,irix6,mac,netbsd1,next3,os2emx,riscos,sunos5,unixware7}
# TODO: Precompile pure modules instead.
find ../dist -name '*.pyc' | xargs rm
# Make sure everything is readable and folders are executable (browseable).
chmod -R ugo+rX ../dist

# Build dynamically loaded modules.
echo 'Building dynamic modules...'
Expand Down
16 changes: 8 additions & 8 deletions demo/index.html
Expand Up @@ -14,14 +14,14 @@
});

button.onclick = function() {
output.value = '';
if (!Python.isFinished(input.value)) {
output.value += 'Command not finished.';
return;
}
var result = Python.eval(input.value);
if (result !== null && result !== undefined) {
output.value += '\n--------------------------\nResult: ' + result;
if (Python.isFinished(input.value)) {
output.value = '';
var result = Python.eval(input.value);
if (result !== null && result !== undefined) {
output.value += '\n--------------------------\nResult: ' + result;
}
} else {
output.value = 'Command not finished.';
}
}
};
Expand Down
2 changes: 2 additions & 0 deletions map_filesystem.py
Expand Up @@ -11,6 +11,8 @@ def main(root):
commands.append('FS.createFolder("%s", "%s", true, true);' %
(dirpath, folder))
for filename in filenames:
# NOTE: Remove the python.js entry to prevent unnecesary re-reading.
if dirpath == '.' and filename == 'python.js': continue
jsless_filename = filename[:-3] if filename.endswith('.js') else filename
commands.append('FS.createLazyFile("%s", "%s", "%s", true, false);' %
(dirpath, jsless_filename, dirpath + '/' + filename))
Expand Down

0 comments on commit 7e1c8de

Please sign in to comment.