Skip to content

Instantly share code, notes, and snippets.

@cosinusoidally
Last active December 6, 2016 00:35
Show Gist options
  • Save cosinusoidally/16ad712d2659dbf4f65a1d823ae35fbd to your computer and use it in GitHub Desktop.
Save cosinusoidally/16ad712d2659dbf4f65a1d823ae35fbd to your computer and use it in GitHub Desktop.
WIP setting up Emscripten in a Centos 6 proot
Tested on an Ubuntu 12.04 and Ubuntu 14.04 host:
We first need an CentOS 6 chroot. I wanted to do this without requring root on the host machine.
I order to do this I used a piece of software called PRoot https://github.com/proot-me/PRoot .
PRoot provides chroot emulation without requiring root. I does this by intercepting and modifying syscalls using ptrace.
You'll need libtalloc to build proot. Ubuntu has packages:
apt-get install libtalloc2 libtalloc-dev
Checkout PRoot:
git clone https://github.com/proot-me/PRoot.git
build proot:
cd PRoot/src
make
This will give you the proot binary.
Next we will need a Centos 6 root filesystem. Although we are not using Docker we can use the Docker
image provided by Centos https://github.com/CentOS/sig-cloud-instance-images/tree/CentOS-6/docker/
Download centos-6-docker.tar.xz and centos-6-docker.tar.xz.asc . Verify the signature on the image using gpg:
gpg --verify centos-6-docker.tar.xz.asc
extract:
mkdir centos_root
cd centos_root
tar xvf ../centos-6-docker.tar.xz
We now have a Centos 6 root filesystem. We will need to update the filesystem and install all the
required build tools. First we will need to copy our system's resolve.conf into the root filesystem:
cd etc
rm resolv.conf
cp /etc/resolve.conf .
We are now ready to proot into the root filesystem. Use the following command:
proot -0 -r centos_root/ -b /proc:/proc -b /run/shm/:/run/shm/ -b /dev:/dev
The -0 means simulate root access. The -r specifies the root filesystem.
The -b emulates bind mounts from the host into the proot.
First fix permissions on the root directory:
chmod 700 /root
Next we need to clear the enviromental veriables to avoid polution from the host:
env -i bash
export USER=root
export HOME=/root
source /etc/profile
Update yum
yum update
Install software:
yum install yum-utils
yum-builddep gcc
yum-builddep cmake
yum-builddep python
yum install git
yum install python
yum install cmake
We will need to build the following:
Python 2.7
GCC 4.8.5 (picked because it's the same version Mozilla uses to build Firefox/Spidermonkey)
CMake 3.5.2
Make sure you download and verify the signatures for each of the packages you download.
Building Python 2.7:
https://www.python.org/downloads/release/python-2712/
tar xvf Python-2.7.12.tgz
cd Python-2.7.12
./configure --prefix=/opt/python2.7
make
make install
GCC 4.8.5
wget https://ftp.gnu.org/gnu/gcc/gcc-4.8.5/gcc-4.8.5.tar.bz2
wget https://ftp.gnu.org/gnu/gcc/gcc-4.8.5/gcc-4.8.5.tar.bz2.sig
gpg --verify gcc-4.8.5.tar.bz2.sig
tar xvf gcc-4.8.5.tar.bz2
cd gcc-4.8.5
At this point you need to fetch some gcc dependencies. There is a script that does this, but I was worried as
it did not check any signatures/SHA sums. If you want to live dangerously you can just run:
./contrib/download_prerequisites
If you're like me you will want to know whether those prerequisites are legit. Unfortunately
there are no signatures to be found on the gnu site. I downloaded the dependencies separately
and Googled the SHA256 sums in order to try and reassure myself. Not a good situation though.
Build:
./configure --prefix=/opt/gcc4.8.5 --enable-languages=c,c++
make
make install
CMake:
wget https://cmake.org/files/v3.5/cmake-3.5.2.tar.gz
wget https://cmake.org/files/v3.5/cmake-3.5.2-SHA-256.txt
wget https://cmake.org/files/v3.5/cmake-3.5.2-SHA-256.txt.asc
Verify signatures (gpg --verify cmake-3.5.2-SHA-256.txt.asc and then grep for the
sha256sum of cmake-3.5.2.tar.gz in cmake-3.5.2-SHA-256.txt ).
cd cmake-3.5.2
./bootstrap --prefix=/opt/cmake-3.5.2
make
make install
Now we have all the dependencies to build fastcomp. Next checkout fastcomp:
git clone https://github.com/kripken/emscripten-fastcomp
cd emscripten-fastcomp
git clone https://github.com/kripken/emscripten-fastcomp-clang tools/clang
Checkout 1.36.14 from emscripten-fastcomp
git checkout 1.36.14
and then for clang:
cd tools/clang
git checkout 1.36.14
Next we need GCC and CMake in our path (we also put in Python 2.7 for good measure).
We also need libstdc++ from GCC 4.8.5 in our LD_LIBRARY_PATH (since LLVM/Clang will
build/run C++11 code during the build process):
export PATH=/opt/gcc4.8.5/bin/:/opt/cmake3.5.2/bin/:/opt/python2.7/bin/:${PATH}
export LD_LIBRARY_PATH=/opt/gcc4.8.5/lib64/
We are now ready to build fastcomp:
cd emscritpen-fastcomp
mkdir build
cd build
cmake .. -DCMAKE_C_COMPILER=/opt/gcc4.8.5/bin/gcc -CMAKE_CXX_COMPILER=/opt/gcc4.8.5/g++ -DCMAKE_BUILD_TYPE=Release -DLLVM_TARGETS_TO_BUILD="X86;JSBackend" -DLLVM_INCLUDE_EXAMPLES=OFF -DLLVM_INCLUDE_TESTS=OFF -DCLANG_INCLUDE_EXAMPLES=OFF -DCLANG_INCLUDE_TESTS=OFF
Note I've specified CMAKE_C_COMPILER and CMAKE_CXX_COMPILER this is because CMake will pointlessly
ignore the fact that the new GCC is PATH and instead find the system GCC. Build:
make
Then copy bin across to /opt :
cp bin /opt/emscripten-fastcomp
also copy across emscripten-version.txt :
cp ../emscripten-version.txt /opt/emscripten-fastcomp
Next get Emscripten:
git clone https://github.com/kripken/emscripten.git
cd emscripten
git checkout 1.36.14
mv emscripen /opt
We now need Node.js, Spidermonkey and the JRE:
node.js:
wget https://nodejs.org/dist/v4.6.2/node-v4.6.2-linux-x64.tar.xz
wget https://nodejs.org/dist/v4.6.2/SHASUMS256.txt.asc
gpg --verify *c
tar xvf node-v4.6.2-linux-x64.tar.xz
Move the directory to /opt
Spidermonkey:
wget https://ftp.mozilla.org/pub/firefox/candidates/50.0.2-candidates/build1/jsshell-linux-x86_64.zip
wget https://ftp.mozilla.org/pub/firefox/candidates/50.0.2-candidates/build1/linux-x86_64/en-US/firefox-50.0.2.checksums
wget https://ftp.mozilla.org/pub/firefox/candidates/50.0.2-candidates/build1/linux-x86_64/en-US/firefox-50.0.2.checksums.asc
gpg --verify firefox-50.0.2.checksums.asc
and then grep for the sha256sum of jsshell-linux-x86_64.zip in firefox-50.0.2.checksums
mkdir js50
cd js50
unzip jsshell-linux-x86_64.zip
JRE:
Go to the Java site. I used jre-8u111-linux-x64.tar.gz (check SHA256 sum)
tar xvf jre-8u111-linux-x64.tar.gz
mv jre1.8.0_111 /opt
Should all now be built and installed under /opt . Next we must set up our environment:
export PATH=/opt/python2.7/bin/:/opt/cmake3.5.2/bin/:/opt/emscripten/:/opt/emscripten-fastcomp/:/opt/gcc4.8.5/bin/:/opt/jre1.8.0_111/bin/:/opt/js50/:/opt/node-v4.6.2-linux-x64/bin/:${PATH}
export LD_LIBRARY_PATH=/opt/gcc4.8.5/lib64/:/opt/js50/:$LD_LIBRARY_PATH
Then run emcc twice:
ljw@localhost:~$ emcc
==============================================================================
Welcome to Emscripten!
This is the first time any of the Emscripten tools has been run.
A settings file has been copied to ~/.emscripten, at absolute path: /home/ljw/.emscripten
It contains our best guesses for the important paths, which are:
LLVM_ROOT = /opt/emscripten-fastcomp
NODE_JS = /opt/node-v4.6.2-linux-x64/bin/node
EMSCRIPTEN_ROOT = /opt/emscripten
Please edit the file if any of those are incorrect.
This command will now exit. When you are done editing those paths, re-run it.
==============================================================================
(precise)ljw@localhost:~$ emcc
INFO:root:generating system asset: is_vanilla.txt... (this will be cached in "/home/ljw/.emscripten_cache/is_vanilla.txt" for subsequent builds)
INFO:root: - ok
INFO:root:(Emscripten: Running sanity checks)
Change the last line of ~/.emscripten to read:
JS_ENGINES = [NODE_JS, SPIDERMONKEY_ENGINE]
Should now be ready to use (for good measure run the test suite).
In order to get this working on Ubuntu 12.04 I did the following:
Copied /opt from the proot elsewhere.
Bind mounted to /opt on the host:
proot -b wherever_the_opt_from_the_rootfs_is:/opt
I also had to do:
export LIBRARY_PATH=/usr/lib/x86_64-linux-gnu:$LIBRARY_PATH
In order to get gcc4.8.5 working.
I had to build my own copy of Python 2.7.12 as Emscripten didn't seem to like the version in Ubuntu 12.04 and
the one from the proot wouldn't work properly when outside the proot.
So my PATH was:
export PATH=/opt/cmake3.5.2/bin/:/opt/emscripten/:/opt/emscripten-fastcomp/:/opt/gcc4.8.5/bin/:/opt/jre1.8.0_111/bin/:/opt/js50/:/opt/node-v4.6.2-linux-x64/bin/:${PATH}
and my LD_LIBRARY_PATH was:
export LD_LIBRARY_PATH=/opt/gcc4.8.5/lib64/:/opt/js50/:$LD_LIBRARY_PATH
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment