AtlatestRepositorysigil-web-repl

sigil-web-repl / tree / scriptsemsdk-shell

1#!/usr/bin/env bash
2#
3# emsdk-shell - Run commands in an Emscripten environment on Guix
4#
5# This script creates an FHS-compatible container with emsdk available.
6# emsdk is installed to ~/.emsdk/emsdk and persists between invocations.
7#
8# Usage:
9# ./scripts/emsdk-shell # Interactive shell with emcc available
10# ./scripts/emsdk-shell emcc --help # Run a single command
11# ./scripts/emsdk-shell make wasm # Run make with wasm target
13# First run will install emsdk (~400MB download).
16set -e
18SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
19PROJECT_DIR="$(cd "$SCRIPT_DIR/.." && pwd)"
20EMSDK_HOME="${EMSDK_HOME:-$HOME/.emsdk}"
22# Packages needed for FHS container
23GUIX_PACKAGES=(
24 coreutils
25 bash
26 gcc-toolchain
27 python
28 git
29 node
30 xz
31 nss-certs
32 tar
33 gzip
34 zlib
35 make
36 grep
37 sed
40# Ensure emsdk directory exists
41mkdir -p "$EMSDK_HOME"
43# Build the guix shell command
44GUIX_CMD=(
45 guix shell
46 --container
47 --emulate-fhs
48 --network
49 --share="$PROJECT_DIR=/project"
50 --share="$EMSDK_HOME=/emsdk-home"
53# Add all packages
54for pkg in "${GUIX_PACKAGES[@]}"; do
55 GUIX_CMD+=("$pkg")
56done
58# Setup script to run inside the container
59SETUP_SCRIPT='
60export SSL_CERT_DIR=/etc/ssl/certs
61export EMSDK_QUIET=1
63# Prevent Emscripten from finding host headers
64# These vars would cause emcc to use host includes, which breaks the build
65unset CPATH
66unset C_INCLUDE_PATH
67unset CPLUS_INCLUDE_PATH
69# Install emsdk if not present
70if [ ! -d "/emsdk-home/emsdk" ]; then
71 echo "Installing emsdk (first-time setup)..."
72 cd /emsdk-home
73 git clone https://github.com/emscripten-core/emsdk.git
74 cd emsdk
75 ./emsdk install latest
76 ./emsdk activate latest
77 echo "emsdk installation complete."
78fi
80# Activate emsdk
81cd /emsdk-home/emsdk
82source ./emsdk_env.sh 2>/dev/null
84# Change to project directory
85cd /project
88if [ $# -eq 0 ]; then
89 # Interactive shell
90 FULL_SCRIPT="$SETUP_SCRIPT
91exec bash"
92 exec "${GUIX_CMD[@]}" -- bash -c "$FULL_SCRIPT"
93else
94 # Run provided command
95 FULL_SCRIPT="$SETUP_SCRIPT
96$*"
97 exec "${GUIX_CMD[@]}" -- bash -c "$FULL_SCRIPT"
98fi