mirror of
https://github.com/raysan5/raylib.git
synced 2025-12-25 10:22:33 -05:00
Update examples collection
This commit is contained in:
131
emsdk-cache/emsdk-main/docker/Dockerfile
Normal file
131
emsdk-cache/emsdk-main/docker/Dockerfile
Normal file
@ -0,0 +1,131 @@
|
||||
FROM ubuntu:jammy AS stage_build
|
||||
|
||||
ARG EMSCRIPTEN_VERSION=tot
|
||||
ENV EMSDK /emsdk
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
|
||||
RUN echo "## Start building" \
|
||||
&& echo "## Update and install packages" \
|
||||
&& apt-get -qq -y update \
|
||||
&& apt-get -qq install -y --no-install-recommends \
|
||||
binutils \
|
||||
build-essential \
|
||||
ca-certificates \
|
||||
file \
|
||||
git \
|
||||
python3 \
|
||||
python3-pip \
|
||||
&& echo "## Done"
|
||||
|
||||
# Copy the contents of this repository to the container
|
||||
COPY . ${EMSDK}
|
||||
|
||||
RUN echo "## Install Emscripten" \
|
||||
&& cd ${EMSDK} \
|
||||
&& ./emsdk install ${EMSCRIPTEN_VERSION} \
|
||||
&& echo "## Done"
|
||||
|
||||
# This generates configuration that contains all valid paths according to installed SDK
|
||||
# TODO(sbc): We should be able to use just emcc -v here but it doesn't
|
||||
# currently create the sanity file.
|
||||
RUN cd ${EMSDK} \
|
||||
&& echo "## Generate standard configuration" \
|
||||
&& ./emsdk activate ${EMSCRIPTEN_VERSION} \
|
||||
&& chmod 777 ${EMSDK}/upstream/emscripten \
|
||||
&& chmod -R 777 ${EMSDK}/upstream/emscripten/cache \
|
||||
&& echo "int main() { return 0; }" > hello.c \
|
||||
&& ${EMSDK}/upstream/emscripten/emcc -c hello.c \
|
||||
&& cat ${EMSDK}/upstream/emscripten/cache/sanity.txt \
|
||||
&& echo "## Done"
|
||||
|
||||
# Cleanup Emscripten installation and strip some symbols
|
||||
RUN echo "## Aggressive optimization: Remove debug symbols" \
|
||||
&& cd ${EMSDK} && . ./emsdk_env.sh \
|
||||
# Remove debugging symbols from embedded node (extra 7MB)
|
||||
&& strip -s `which node` \
|
||||
# Tests consume ~80MB disc space
|
||||
&& rm -fr ${EMSDK}/upstream/emscripten/tests \
|
||||
# strip out symbols from clang (~extra 50MB disc space)
|
||||
&& find ${EMSDK}/upstream/bin -type f -exec strip -s {} + || true \
|
||||
&& echo "## Done"
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# -------------------------------- STAGE DEPLOY --------------------------------
|
||||
# ------------------------------------------------------------------------------
|
||||
|
||||
FROM ubuntu:jammy AS stage_deploy
|
||||
|
||||
COPY --from=stage_build /emsdk /emsdk
|
||||
|
||||
# These fallback environment variables are intended for situations where the
|
||||
# entrypoint is not utilized (as in a derived image) or overridden (e.g. when
|
||||
# using `--entrypoint /bin/bash` in CLI).
|
||||
# This corresponds to the env variables set during: `source ./emsdk_env.sh`
|
||||
ENV EMSDK=/emsdk \
|
||||
PATH="/emsdk:/emsdk/upstream/emscripten:/emsdk/node/22.16.0_64bit/bin:${PATH}"
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Create a 'standard` 1000:1000 user
|
||||
# Thanks to that this image can be executed as non-root user and created files
|
||||
# will not require root access level on host machine Please note that this
|
||||
# solution even if widely spread (i.e. Node.js uses it) is far from perfect as
|
||||
# user 1000:1000 might not exist on host machine, and in this case running any
|
||||
# docker image will cause other random problems (mostly due `$HOME` pointing to
|
||||
# `/`)
|
||||
RUN echo "## Create emscripten user (1000:1000)" \
|
||||
&& groupadd --gid 1000 emscripten \
|
||||
&& useradd --uid 1000 --gid emscripten --shell /bin/bash --create-home emscripten \
|
||||
&& echo "## Done"
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
|
||||
RUN echo "## Update and install packages" \
|
||||
&& apt-get -qq -y update \
|
||||
# Somewhere in here apt sets up tzdata which asks for your time zone and blocks
|
||||
# waiting for the answer which you can't give as docker build doesn't read from
|
||||
# the terminal. The env vars set here avoid the interactive prompt and set the TZ.
|
||||
&& DEBIAN_FRONTEND="noninteractive" TZ="America/San_Francisco" apt-get -qq install -y --no-install-recommends \
|
||||
sudo \
|
||||
libxml2 \
|
||||
ca-certificates \
|
||||
python3 \
|
||||
python3-pip \
|
||||
wget \
|
||||
curl \
|
||||
zip \
|
||||
unzip \
|
||||
git \
|
||||
git-lfs \
|
||||
ssh-client \
|
||||
build-essential \
|
||||
make \
|
||||
ant \
|
||||
libidn12 \
|
||||
cmake \
|
||||
openjdk-11-jre-headless \
|
||||
# Standard Cleanup on Debian images
|
||||
&& apt-get -y clean \
|
||||
&& apt-get -y autoclean \
|
||||
&& apt-get -y autoremove \
|
||||
&& rm -rf /var/lib/apt/lists/* \
|
||||
&& rm -rf /var/cache/debconf/*-old \
|
||||
&& rm -rf /usr/share/doc/* \
|
||||
&& rm -rf /usr/share/man/?? \
|
||||
&& rm -rf /usr/share/man/??_* \
|
||||
&& echo "## Done"
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Use commonly used /src as working directory
|
||||
WORKDIR /src
|
||||
|
||||
ENTRYPOINT ["/emsdk/docker/entrypoint.sh"]
|
||||
|
||||
LABEL maintainer="kontakt@trzeci.eu" \
|
||||
org.label-schema.name="emscripten" \
|
||||
org.label-schema.description="The official container with Emscripten SDK" \
|
||||
org.label-schema.url="https://emscripten.org" \
|
||||
org.label-schema.vcs-url="https://github.com/emscripten-core/emsdk" \
|
||||
org.label-schema.docker.dockerfile="/docker/Dockerfile"
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
31
emsdk-cache/emsdk-main/docker/Makefile
Normal file
31
emsdk-cache/emsdk-main/docker/Makefile
Normal file
@ -0,0 +1,31 @@
|
||||
# A Makefile to build, test, tag and publish the Emscripten SDK Docker container.
|
||||
|
||||
# Emscripten version to build: Should match the version that has been already released.
|
||||
# i.e.: 1.39.18
|
||||
version =
|
||||
alias =
|
||||
only_alias =
|
||||
|
||||
image_name ?= emscripten/emsdk
|
||||
|
||||
.TEST:
|
||||
ifndef version
|
||||
$(error argument 'version' is not set. Please call `make version=SOME_VERSION ...`)
|
||||
endif
|
||||
|
||||
build: Dockerfile .TEST
|
||||
cd .. && docker build --progress=plain --network host --build-arg=EMSCRIPTEN_VERSION=${version} -t ${image_name}:${version} -f docker/$< .
|
||||
|
||||
test: test_dockerimage.sh .TEST
|
||||
# test as non-root
|
||||
# test fallback env variables by overriding the entrypoint
|
||||
docker run --rm -u `id -u`:`id -g` -w /emsdk/docker --net=host --entrypoint /bin/bash ${image_name}:${version} $<
|
||||
|
||||
push: .TEST
|
||||
ifndef only_alias
|
||||
docker push ${image_name}:${version}
|
||||
endif
|
||||
ifdef alias
|
||||
docker tag ${image_name}:${version} ${image_name}:${alias}
|
||||
docker push ${image_name}:${alias}
|
||||
endif
|
||||
125
emsdk-cache/emsdk-main/docker/README.md
Normal file
125
emsdk-cache/emsdk-main/docker/README.md
Normal file
@ -0,0 +1,125 @@
|
||||
# Dockerfile for EMSDK
|
||||
|
||||
This Dockerfile builds a self-contained version of Emscripten SDK that enables Emscripten to be used without any
|
||||
other installation on the host system.
|
||||
|
||||
It is published at https://hub.docker.com/r/emscripten/emsdk.
|
||||
|
||||
### Usage
|
||||
|
||||
Simple usage of this container to compile a hello-world
|
||||
```bash
|
||||
# create helloworld.cpp
|
||||
cat << EOF > helloworld.cpp
|
||||
#include <iostream>
|
||||
int main() {
|
||||
std::cout << "Hello World!" << std::endl;
|
||||
return 0;
|
||||
}
|
||||
EOF
|
||||
```
|
||||
|
||||
```bash
|
||||
# compile with docker image
|
||||
docker run \
|
||||
--rm \
|
||||
-v "$(pwd):$(pwd)" \
|
||||
-u $(id -u):$(id -g) \
|
||||
emscripten/emsdk \
|
||||
emcc helloworld.cpp -o helloworld.js
|
||||
|
||||
# execute on host machine
|
||||
node helloworld.js
|
||||
```
|
||||
|
||||
Teardown of compilation command:
|
||||
|
||||
|part|description|
|
||||
|---|---|
|
||||
|`docker run`| A standard command to run a command in a container|
|
||||
|`--rm`|remove a container after execution (optimization)|
|
||||
|`-v "$(pwd):$(pwd)"`|Mounting current folder from the host system into mirrored path on the container<br>TIP: This helps to investigate possible problem as we preserve exactly the same paths like in host. In such case modern editors (like Sublime, Atom, VS Code) let us to CTRL+Click on a problematic file |
|
||||
|`-u $(id -u):$(id -g)`| Run the container as a non-root user with the same UID and GID as local user. Hence all files produced by this are accessible to non-root users|
|
||||
|`emscripten/emsdk`|Get the latest tag of this container|
|
||||
|`emcc helloworld.cpp -o helloworld.js`|Execute `emcc` command with following arguments inside container, effectively compile our source code|
|
||||
|
||||
|
||||
|
||||
### Building Dockerfile
|
||||
|
||||
This image has following optional arguments
|
||||
|
||||
| arg | default value | description |
|
||||
| --- | --- | --- |
|
||||
| `EMSCRIPTEN_VERSION` | `tot`<br/>(special case, tip-of-tree) | One of released version of Emscripten. For example `2.0.0`<br/> Minimal supported version is **1.39.0** |
|
||||
|
||||
**Building**
|
||||
|
||||
This step will build Dockerfile as given tag on local machine
|
||||
```bash
|
||||
# using docker
|
||||
docker build \
|
||||
--network host \
|
||||
--build-arg=EMSCRIPTEN_VERSION=1.39.17 \
|
||||
-t emscripten/emsdk:1.39.17 \
|
||||
-f docker/Dockerfile \
|
||||
.
|
||||
```
|
||||
```bash
|
||||
# using predefined make target
|
||||
make version=1.39.17 build test
|
||||
```
|
||||
|
||||
**Tagging**
|
||||
|
||||
In case of using `docker build` command directly, given `--tag` should match version of released Emscripten (you can see list of non-legacy versions by executing `emsdk list`).
|
||||
|
||||
**Pushing**
|
||||
|
||||
This step will take local image and push to default docker registry. You need to make sure that you logged in docker cli (`docker login`) and you have rights to push to that registry.
|
||||
|
||||
```bash
|
||||
# using docker
|
||||
docker push emscripten/emsdk:1.39.17
|
||||
```
|
||||
```bash
|
||||
# using predefined make target
|
||||
make version=1.39.17 push
|
||||
```
|
||||
|
||||
In case of pushing the most recent version, this version should be also tagged as `latest` and pushed.
|
||||
```bash
|
||||
# using docker cli
|
||||
docker tag emscripten/emsdk:1.39.17 emscripten/emsdk:latest
|
||||
docker push emscripten/emsdk:latest
|
||||
|
||||
```bash
|
||||
# using make
|
||||
make version=1.39.17 alias=latest push
|
||||
```
|
||||
|
||||
### Extending
|
||||
|
||||
If your project uses packages that this image doesn't provide you might want to:
|
||||
* Contribute to this repo: Maybe your dependency is either non-intrusive or could be useful for other people
|
||||
* Create custom image that bases on this image
|
||||
|
||||
1. create own Dockerfile that holds:
|
||||
```dockerfile
|
||||
# Point at any base image that you find suitable to extend.
|
||||
FROM emscripten/emsdk:1.39.17
|
||||
|
||||
# Install required tools that are useful for your project i.e. ninja-build
|
||||
RUN apt update && apt install -y ninja-build
|
||||
```
|
||||
|
||||
2. build it
|
||||
```bash
|
||||
docker build -t extended_emscripten .
|
||||
```
|
||||
|
||||
3. test
|
||||
```bash
|
||||
docker run --rm extended_emscripten ninja --version
|
||||
# 1.10.0
|
||||
```
|
||||
7
emsdk-cache/emsdk-main/docker/entrypoint.sh
Normal file
7
emsdk-cache/emsdk-main/docker/entrypoint.sh
Normal file
@ -0,0 +1,7 @@
|
||||
#!/bin/bash
|
||||
set -e
|
||||
|
||||
# Set-up PATH and other environment variables
|
||||
EMSDK_QUIET=1 source /emsdk/emsdk_env.sh
|
||||
|
||||
exec "$@"
|
||||
29
emsdk-cache/emsdk-main/docker/test_dockerimage.sh
Normal file
29
emsdk-cache/emsdk-main/docker/test_dockerimage.sh
Normal file
@ -0,0 +1,29 @@
|
||||
#!/usr/bin/env bash
|
||||
set -ex
|
||||
|
||||
if [ $EUID -eq 0 ]; then
|
||||
sudo -u nobody `which emcc` --version
|
||||
fi
|
||||
|
||||
which emsdk
|
||||
node --version
|
||||
npm --version
|
||||
python3 --version
|
||||
pip3 --version
|
||||
em++ --version
|
||||
emcc --version
|
||||
java -version
|
||||
cmake --version
|
||||
|
||||
exit_code=0
|
||||
|
||||
# test emcc compilation
|
||||
echo 'int main() { return 0; }' | emcc -o /tmp/main.js -xc -
|
||||
node /tmp/main.js || exit_code=$?
|
||||
if [ $exit_code -ne 0 ]; then
|
||||
echo "Node exited with non-zero exit code: $exit_code"
|
||||
exit $exit_code
|
||||
fi
|
||||
|
||||
# test embuilder
|
||||
embuilder build zlib --force
|
||||
Reference in New Issue
Block a user