Skip to content

Instantly share code, notes, and snippets.

@VictorLaskin VictorLaskin/Dockerfile
Last active Aug 29, 2015

Embed
What would you like to do?
# Dockerfile for COMPILATION C++ into JS using EMSCRIPTEN
FROM stackbrew/ubuntu:saucy
MAINTAINER "Victor Laskin"
RUN apt-get update
RUN apt-get install -y --no-install-recommends \
wget curl apache2 \
ca-certificates git build-essential make cmake scons \
python nodejs default-jre-headless clang-3.4 llvm-3.4
RUN git clone --depth=1 https://github.com/kripken/emscripten /opt/emscripten
RUN for prog in em++ em-config emar emcc emconfigure emmake emranlib emrun emscons; do \
ln -sf /opt/emscripten/$prog /usr/local/bin; done
RUN git clone https://github.com/kripken/emscripten-fastcomp /opt/emscripten-fastcomp && \
cd /opt/emscripten-fastcomp && \
git clone https://github.com/kripken/emscripten-fastcomp-clang tools/clang && \
mkdir build
RUN cd /opt/emscripten-fastcomp/build && cmake .. -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
RUN cd /opt/emscripten-fastcomp/build && make && ls /opt/emscripten-fastcomp/build/bin
# set LLVM_ROOT variable inside ~/.emscripten
RUN emcc -v && cd ~ && sed -i.bak 's/^\(LLVM_ROOT = \).*/\1"\/opt\/emscripten-fastcomp\/build\/bin"/' .emscripten && cat .emscripten
# lets print out some enviroment variables
RUN emcc -v && \
cat ~/.emscripten
# build an example code
RUN emcc --version && \
mkdir -p /tmp/emscripten_temp && cd /tmp/emscripten_temp && \
EMCC_FORCE_STDLIBS=1 em++ -O2 /opt/emscripten/tests/hello_world_sdl.cpp -o hello.js && \
(nodejs hello.js 2> /dev/null | grep hello) && \
rm -rf /tmp/emscripten_temp
# Setup apache
ENV APACHE_RUN_USER www-data
ENV APACHE_RUN_GROUP www-data
ENV APACHE_LOG_DIR /var/log/apache2
ENV APACHE_LOCK_DIR /var/lock/apache2
ENV APACHE_PID_FILE /var/run/apache2.pid
EXPOSE 80
# Make and put example into /var/www
RUN mkdir /src
COPY . /src
RUN cd /src && ls && make all && ls && cp *.js /var/www && cp *.html /var/www && cp *.html.mem /var/www && ls /var/www
CMD /usr/sbin/apache2ctl -D FOREGROUND
#include <iostream>
#ifdef EMSCRIPTEN
#include <emscripten.h>
#endif
using namespace std;
int main()
{
[](){ cout << "HELLO from C++11" << endl; }();
return 0;
}
CC=em++
SOURCES=main.cpp
OBJECTS=$(SOURCES:.cpp=.bc)
LDFLAGS=-O2 --llvm-opts 2
OUTPUT=test.html
all: $(OUTPUT)
$(OUTPUT): $(OBJECTS)
$(CC) -o $@ $(OBJECTS) -s FULL_ES2=1 -std=c++11 $(LDFLAGS)
%.bc: %.cpp
$(CC) -s FULL_ES2=1 -std=c++11 $(LDFLAGS) -o $@ $<
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.