From 95b5aef265c0eccccbd75f67967736d0f5aa1223 Mon Sep 17 00:00:00 2001 From: "H. Vetinari" Date: Fri, 13 Sep 2024 14:43:28 +0200 Subject: [PATCH 1/7] add emscripten-activation --- recipes/emscripten-activation/activate.sh | 62 +++++++++++++++++++ .../conda_build_config.yaml | 12 ++++ recipes/emscripten-activation/deactivate.sh | 12 ++++ .../install_emscripten.sh | 13 ++++ .../install_emscripten_impl.sh | 11 ++++ recipes/emscripten-activation/meta.yaml | 62 +++++++++++++++++++ recipes/emscripten-activation/testfile.c | 15 +++++ 7 files changed, 187 insertions(+) create mode 100644 recipes/emscripten-activation/activate.sh create mode 100644 recipes/emscripten-activation/conda_build_config.yaml create mode 100644 recipes/emscripten-activation/deactivate.sh create mode 100644 recipes/emscripten-activation/install_emscripten.sh create mode 100644 recipes/emscripten-activation/install_emscripten_impl.sh create mode 100644 recipes/emscripten-activation/meta.yaml create mode 100644 recipes/emscripten-activation/testfile.c diff --git a/recipes/emscripten-activation/activate.sh b/recipes/emscripten-activation/activate.sh new file mode 100644 index 0000000000000..3910d7150a8bc --- /dev/null +++ b/recipes/emscripten-activation/activate.sh @@ -0,0 +1,62 @@ +if [ -z ${CONDA_FORGE_EMSCRIPTEN_ACTIVATED+x} ]; then + + export CONDA_FORGE_EMSCRIPTEN_ACTIVATED=1 + + export EMSDK_PYTHON=${CONDA_PREFIX}/bin/python3 + export PYTHON=${CONDA_PREFIX}/bin/python3 + + CONDA_EMSDK_DIR=$CONDA_PREFIX/opt/emsdk + + export EMSCRIPTEN_VERSION=$PKG_VERSION + export EMSCRIPTEN_FORGE_EMSDK_DIR=$CONDA_EMSDK_DIR + + # clear all prexisting cmake args / CC / CXX / AR / RANLIB + export CC="emcc" + export CXX="em++" + export AR="emar" + export RANLIB="emranlib" + + export CMAKE_ARGS="" + + # set the emscripten toolchain + export CMAKE_ARGS="$CMAKE_ARGS -DCMAKE_TOOLCHAIN_FILE=$CONDA_EMSDK_DIR/upstream/emscripten/cmake/Modules/Platform/Emscripten.cmake" + + # conda prefix path + export CMAKE_ARGS="$CMAKE_ARGS -DCMAKE_PREFIX_PATH=$PREFIX" + + # install prefix + export CMAKE_ARGS="$CMAKE_ARGS -DCMAKE_INSTALL_PREFIX=$PREFIX" + + # find root path mode package + export CMAKE_ARGS="$CMAKE_ARGS -DCMAKE_FIND_ROOT_PATH_MODE_PACKAGE=ON" + + # fpic + export CMAKE_ARGS="$CMAKE_ARGS -DCMAKE_POSITION_INDEPENDENT_CODE:BOOL=true" + + cmake () { + emcmake cmake "$@" + } + + # useful variables + export PY_SIDE_LD_FLAGV + + # basics + export EM_FORGE_OPTFLAGS="-O2" + export EM_FORGE_DBGFLAGS="-g0" + + # basics ld + export EM_FORGE_LDFLAGS_BASE="-s MODULARIZE=1 -s LINKABLE=1 -s EXPORT_ALL=1 -s WASM=1 -std=c++14 -s LZ4=1" + export EM_FORGE_LDFLAGS_BASE="${EM_FORGE_OPTFLAGS} ${EM_FORGE_DBGFLAGS} ${EM_FORGE_LDFLAGS_BASE}" + + # basics cflags + export EM_FORGE_CFLAGS_BASE="-fPIC" + export EM_FORGE_CFLAGS_BASE="${EM_FORGE_OPTFLAGS} ${EM_FORGE_DBGFLAGS} ${EM_FORGE_CFLAGS_BASE}" + + # side module + export EM_FORGE_SIDE_MODULE_LDFLAGS="${LDFLAGS_BASE} -s SIDE_MODULE=1" + export EM_FORGE_SIDE_MODULE_CFLAGS="${EM_FORGE_CFLAGS_BASE} -I${PREFIX}/include" + + # wasm bigint + export LDFLAGS="$LDFLAGS -sWASM_BIGINT" + +fi diff --git a/recipes/emscripten-activation/conda_build_config.yaml b/recipes/emscripten-activation/conda_build_config.yaml new file mode 100644 index 0000000000000..9c8026f99249d --- /dev/null +++ b/recipes/emscripten-activation/conda_build_config.yaml @@ -0,0 +1,12 @@ +CBUILD: + - x86_64-conda-linux-gnu + +CHOST: + - wasm32-unknown-emscripten + +cross_target_platform: + - emscripten-wasm32 + +# needs clang 19 +channel_sources: + - conda-forge/label/llvm_rc,conda-forge diff --git a/recipes/emscripten-activation/deactivate.sh b/recipes/emscripten-activation/deactivate.sh new file mode 100644 index 0000000000000..7e5e73c164476 --- /dev/null +++ b/recipes/emscripten-activation/deactivate.sh @@ -0,0 +1,12 @@ +#!/bin/bash + +unset cmake + +unset CONDA_FORGE_EMSCRIPTEN_ACTIVATED +unset PY_SIDE_LD_FLAGV +unset EM_FORGE_OPTFLAGS +unset EM_FORGE_DBGFLAGS +unset EM_FORGE_LDFLAGS_BASE +unset EM_FORGE_CFLAGS_BASE +unset EM_FORGE_SIDE_MODULE_LDFLAGS +unset EM_FORGE_SIDE_MODULE_CFLAGS diff --git a/recipes/emscripten-activation/install_emscripten.sh b/recipes/emscripten-activation/install_emscripten.sh new file mode 100644 index 0000000000000..1212d73397b70 --- /dev/null +++ b/recipes/emscripten-activation/install_emscripten.sh @@ -0,0 +1,13 @@ +#!/bin/bash +set -ex + +# Copy the [de]activate scripts to $PREFIX/etc/conda/[de]activate.d. +# This will allow them to be run on environment activation. +for CHANGE in "activate" "deactivate" +do + mkdir -p "${PREFIX}/etc/conda/${CHANGE}.d" + envsubst '$PKG_VERSION' < "${RECIPE_DIR}/${CHANGE}.sh" > "${PREFIX}/etc/conda/${CHANGE}.d/${PKG_NAME}_${CHANGE}.sh" +done + +mkdir -p ${PREFIX}/bin +cp "${PREFIX}/etc/conda/${CHANGE}.d/${PKG_NAME}_${CHANGE}.sh" ${PREFIX}/bin/activate_emscripten.sh diff --git a/recipes/emscripten-activation/install_emscripten_impl.sh b/recipes/emscripten-activation/install_emscripten_impl.sh new file mode 100644 index 0000000000000..82d178e27d1bd --- /dev/null +++ b/recipes/emscripten-activation/install_emscripten_impl.sh @@ -0,0 +1,11 @@ +#!/bin/bash +set -ex + +pushd "${PREFIX}"/bin + for BINARY in "em++" "em-config" "emar" "embuilder" "emcc" "emcmake" "emconfigure" "emmake" "emranlib" "emrun" "emscons" "emsize" "emstrip" "emsymbolizer"; do + ln -s $BINARY ${CHOST}-$BINARY + if [[ "${CBUILD}" != ${CHOST} ]]; then + ln -s $BINARY ${CBUILD}-$BINARY + fi + done +popd diff --git a/recipes/emscripten-activation/meta.yaml b/recipes/emscripten-activation/meta.yaml new file mode 100644 index 0000000000000..c0b0a8557dda3 --- /dev/null +++ b/recipes/emscripten-activation/meta.yaml @@ -0,0 +1,62 @@ +{% set version = "3.1.58" %} +# emscripten expects specific clang version, see +# https://github.com/emscripten-core/emscripten/blob/3.1.58/tools/shared.py#L62 +{% set clang_version = 19 %} + +package: + name: emscripten-activation + version: {{ version }} + +build: + number: 0 + skip: true # [win] + +outputs: + - name: emscripten_impl_{{ cross_target_platform }} + script: install_emscripten_impl.sh # [unix] + requirements: + - emscripten ={{ version }} + - clang {{ clang_version }} + - clangxx {{ clang_version }} + test: + commands: + - {{ CBUILD }}-emcc --version # [unix] + - {{ CHOST }}-emcc --version # [unix] + + - name: emscripten_{{ cross_target_platform }} + script: install_emscripten.sh # [unix] + run_exports: + strong: + - {{ pin_subpackage("emscripten-abi", lower_bound="x.x.x", upper_bound="x.x.x") }} + requirements: + run: + - {{ pin_subpackage("emscripten_impl_" ~ cross_target_platform, exact=True) }} + test: + files: + - testfile.c + commands: + - emcc ./testfile.c + - node a.out.js + + - name: emscripten-abi + build: + noarch: generic + test: + commands: + - echo "emscripten abi is built." + +about: + home: https://emscripten.org + license: MIT + license_file: LICENSE.txt + summary: An LLVM-to-WebAssembly Compiler + description: Emscripten compiles C and C++ to WebAssembly using LLVM and Binaryen. Emscripten output can run on the Web, in Node.js, and in wasm runtimes. + dev_url: https://github.com/emscripten-core/emscripten + doc_url: https://emscripten.org/ + +extra: + recipe-maintainers: + - DerThorsten + - wolfv + - h-vetinari + - conda-forge/emscripten diff --git a/recipes/emscripten-activation/testfile.c b/recipes/emscripten-activation/testfile.c new file mode 100644 index 0000000000000..5f9c40e408b41 --- /dev/null +++ b/recipes/emscripten-activation/testfile.c @@ -0,0 +1,15 @@ +/* + * Copyright 2011 The Emscripten Authors. All rights reserved. + * Emscripten is available under two separate licenses, the MIT license and the + * University of Illinois/NCSA Open Source License. Both these licenses can be + * found in the LICENSE file. + */ + +#include + +int main() { + printf("hello, world!\n"); + return 0; +} + + From 68cc1995166cbf0cc9a9445240acba4bc3e2243a Mon Sep 17 00:00:00 2001 From: "H. Vetinari" Date: Fri, 13 Sep 2024 14:44:51 +0200 Subject: [PATCH 2/7] use BSD-3 license for compiler activation --- recipes/emscripten-activation/LICENSE | 28 +++++++++++++++++++++++++ recipes/emscripten-activation/meta.yaml | 4 ++-- 2 files changed, 30 insertions(+), 2 deletions(-) create mode 100644 recipes/emscripten-activation/LICENSE diff --git a/recipes/emscripten-activation/LICENSE b/recipes/emscripten-activation/LICENSE new file mode 100644 index 0000000000000..9aab6814c6ea8 --- /dev/null +++ b/recipes/emscripten-activation/LICENSE @@ -0,0 +1,28 @@ +BSD 3-Clause License + +Copyright (c) 2012, Anaconda, Inc. +Copyright (c) 2015-2019, conda-forge +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + * Neither the name of the copyright holder nor the names of its + contributors may be used to endorse or promote products + derived from this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY +DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND +ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/recipes/emscripten-activation/meta.yaml b/recipes/emscripten-activation/meta.yaml index c0b0a8557dda3..f0b03bfd0c993 100644 --- a/recipes/emscripten-activation/meta.yaml +++ b/recipes/emscripten-activation/meta.yaml @@ -47,8 +47,8 @@ outputs: about: home: https://emscripten.org - license: MIT - license_file: LICENSE.txt + license: BSD-3-Clause + license_file: LICENSE summary: An LLVM-to-WebAssembly Compiler description: Emscripten compiles C and C++ to WebAssembly using LLVM and Binaryen. Emscripten output can run on the Web, in Node.js, and in wasm runtimes. dev_url: https://github.com/emscripten-core/emscripten From aec227a1859390b6a759b809c3991eb268589047 Mon Sep 17 00:00:00 2001 From: "H. Vetinari" Date: Fri, 13 Sep 2024 14:55:55 +0200 Subject: [PATCH 3/7] remove left-over rattler-build syntax --- recipes/emscripten-activation/meta.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/recipes/emscripten-activation/meta.yaml b/recipes/emscripten-activation/meta.yaml index f0b03bfd0c993..75aba57bb4e25 100644 --- a/recipes/emscripten-activation/meta.yaml +++ b/recipes/emscripten-activation/meta.yaml @@ -27,7 +27,7 @@ outputs: script: install_emscripten.sh # [unix] run_exports: strong: - - {{ pin_subpackage("emscripten-abi", lower_bound="x.x.x", upper_bound="x.x.x") }} + - {{ pin_subpackage("emscripten-abi", max_pin="x.x.x") }} requirements: run: - {{ pin_subpackage("emscripten_impl_" ~ cross_target_platform, exact=True) }} From 045fc22671404acd39d06d6d8907f219e64850ec Mon Sep 17 00:00:00 2001 From: "H. Vetinari" Date: Fri, 13 Sep 2024 15:03:24 +0200 Subject: [PATCH 4/7] add gettext for bin/envsubst --- recipes/emscripten-activation/meta.yaml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/recipes/emscripten-activation/meta.yaml b/recipes/emscripten-activation/meta.yaml index 75aba57bb4e25..dad1f9ae6f49a 100644 --- a/recipes/emscripten-activation/meta.yaml +++ b/recipes/emscripten-activation/meta.yaml @@ -29,6 +29,8 @@ outputs: strong: - {{ pin_subpackage("emscripten-abi", max_pin="x.x.x") }} requirements: + build: + - gettext run: - {{ pin_subpackage("emscripten_impl_" ~ cross_target_platform, exact=True) }} test: From fb7dad88c7b4920c7dd8c3831064b44439b2902b Mon Sep 17 00:00:00 2001 From: "H. Vetinari" Date: Sun, 15 Sep 2024 10:42:33 +0200 Subject: [PATCH 5/7] remove some redundant variables from activation --- recipes/emscripten-activation/activate.sh | 10 +--------- recipes/emscripten-activation/deactivate.sh | 2 -- 2 files changed, 1 insertion(+), 11 deletions(-) diff --git a/recipes/emscripten-activation/activate.sh b/recipes/emscripten-activation/activate.sh index 3910d7150a8bc..0fd95717669c6 100644 --- a/recipes/emscripten-activation/activate.sh +++ b/recipes/emscripten-activation/activate.sh @@ -3,12 +3,8 @@ if [ -z ${CONDA_FORGE_EMSCRIPTEN_ACTIVATED+x} ]; then export CONDA_FORGE_EMSCRIPTEN_ACTIVATED=1 export EMSDK_PYTHON=${CONDA_PREFIX}/bin/python3 - export PYTHON=${CONDA_PREFIX}/bin/python3 - CONDA_EMSDK_DIR=$CONDA_PREFIX/opt/emsdk - - export EMSCRIPTEN_VERSION=$PKG_VERSION - export EMSCRIPTEN_FORGE_EMSDK_DIR=$CONDA_EMSDK_DIR + export CONDA_EMSDK_DIR=${CONDA_PREFIX}/opt/emsdk # clear all prexisting cmake args / CC / CXX / AR / RANLIB export CC="emcc" @@ -33,10 +29,6 @@ if [ -z ${CONDA_FORGE_EMSCRIPTEN_ACTIVATED+x} ]; then # fpic export CMAKE_ARGS="$CMAKE_ARGS -DCMAKE_POSITION_INDEPENDENT_CODE:BOOL=true" - cmake () { - emcmake cmake "$@" - } - # useful variables export PY_SIDE_LD_FLAGV diff --git a/recipes/emscripten-activation/deactivate.sh b/recipes/emscripten-activation/deactivate.sh index 7e5e73c164476..dab0c5434927d 100644 --- a/recipes/emscripten-activation/deactivate.sh +++ b/recipes/emscripten-activation/deactivate.sh @@ -1,7 +1,5 @@ #!/bin/bash -unset cmake - unset CONDA_FORGE_EMSCRIPTEN_ACTIVATED unset PY_SIDE_LD_FLAGV unset EM_FORGE_OPTFLAGS From ceb338f58840df7e7d6869ab22733a9f169d791a Mon Sep 17 00:00:00 2001 From: "H. Vetinari" Date: Sun, 15 Sep 2024 10:48:42 +0200 Subject: [PATCH 6/7] remove `EM_FORGE_` prefix --- recipes/emscripten-activation/activate.sh | 16 ++++++++-------- recipes/emscripten-activation/deactivate.sh | 12 ++++++------ 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/recipes/emscripten-activation/activate.sh b/recipes/emscripten-activation/activate.sh index 0fd95717669c6..ca187f7beb6ed 100644 --- a/recipes/emscripten-activation/activate.sh +++ b/recipes/emscripten-activation/activate.sh @@ -33,20 +33,20 @@ if [ -z ${CONDA_FORGE_EMSCRIPTEN_ACTIVATED+x} ]; then export PY_SIDE_LD_FLAGV # basics - export EM_FORGE_OPTFLAGS="-O2" - export EM_FORGE_DBGFLAGS="-g0" + export OPTFLAGS_USED="-O2" + export DBGFLAGS_USED="-g0" # basics ld - export EM_FORGE_LDFLAGS_BASE="-s MODULARIZE=1 -s LINKABLE=1 -s EXPORT_ALL=1 -s WASM=1 -std=c++14 -s LZ4=1" - export EM_FORGE_LDFLAGS_BASE="${EM_FORGE_OPTFLAGS} ${EM_FORGE_DBGFLAGS} ${EM_FORGE_LDFLAGS_BASE}" + export LDFLAGS_BASE="-s MODULARIZE=1 -s LINKABLE=1 -s EXPORT_ALL=1 -s WASM=1 -std=c++14 -s LZ4=1" + export LDFLAGS_BASE="${OPTFLAGS_USED} ${DBGFLAGS_USED} ${LDFLAGS_BASE}" # basics cflags - export EM_FORGE_CFLAGS_BASE="-fPIC" - export EM_FORGE_CFLAGS_BASE="${EM_FORGE_OPTFLAGS} ${EM_FORGE_DBGFLAGS} ${EM_FORGE_CFLAGS_BASE}" + export CFLAGS_BASE="-fPIC" + export CFLAGS_BASE="${OPTFLAGS_USED} ${DBGFLAGS_USED} ${CFLAGS_BASE}" # side module - export EM_FORGE_SIDE_MODULE_LDFLAGS="${LDFLAGS_BASE} -s SIDE_MODULE=1" - export EM_FORGE_SIDE_MODULE_CFLAGS="${EM_FORGE_CFLAGS_BASE} -I${PREFIX}/include" + export SIDE_MODULE_LDFLAGS="${LDFLAGS_BASE} -s SIDE_MODULE=1" + export SIDE_MODULE_CFLAGS="${CFLAGS_BASE} -I${PREFIX}/include" # wasm bigint export LDFLAGS="$LDFLAGS -sWASM_BIGINT" diff --git a/recipes/emscripten-activation/deactivate.sh b/recipes/emscripten-activation/deactivate.sh index dab0c5434927d..300da889b17b6 100644 --- a/recipes/emscripten-activation/deactivate.sh +++ b/recipes/emscripten-activation/deactivate.sh @@ -2,9 +2,9 @@ unset CONDA_FORGE_EMSCRIPTEN_ACTIVATED unset PY_SIDE_LD_FLAGV -unset EM_FORGE_OPTFLAGS -unset EM_FORGE_DBGFLAGS -unset EM_FORGE_LDFLAGS_BASE -unset EM_FORGE_CFLAGS_BASE -unset EM_FORGE_SIDE_MODULE_LDFLAGS -unset EM_FORGE_SIDE_MODULE_CFLAGS +unset OPTFLAGS_USED +unset DBGFLAGS_USED +unset LDFLAGS_BASE +unset CFLAGS_BASE +unset SIDE_MODULE_LDFLAGS +unset SIDE_MODULE_CFLAGS From eb92c0d73753c1bd9e6a10fadd2f797329d7702f Mon Sep 17 00:00:00 2001 From: "H. Vetinari" Date: Sun, 15 Sep 2024 10:49:13 +0200 Subject: [PATCH 7/7] remove `-std=c++14` from activation --- recipes/emscripten-activation/activate.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/recipes/emscripten-activation/activate.sh b/recipes/emscripten-activation/activate.sh index ca187f7beb6ed..e2d090ce5f5f7 100644 --- a/recipes/emscripten-activation/activate.sh +++ b/recipes/emscripten-activation/activate.sh @@ -37,7 +37,7 @@ if [ -z ${CONDA_FORGE_EMSCRIPTEN_ACTIVATED+x} ]; then export DBGFLAGS_USED="-g0" # basics ld - export LDFLAGS_BASE="-s MODULARIZE=1 -s LINKABLE=1 -s EXPORT_ALL=1 -s WASM=1 -std=c++14 -s LZ4=1" + export LDFLAGS_BASE="-sMODULARIZE=1 -sLINKABLE=1 -sEXPORT_ALL=1 -sWASM=1 -sLZ4=1" export LDFLAGS_BASE="${OPTFLAGS_USED} ${DBGFLAGS_USED} ${LDFLAGS_BASE}" # basics cflags