Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add emscripten-activation #27576

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions recipes/emscripten-activation/LICENSE
Original file line number Diff line number Diff line change
@@ -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.
62 changes: 62 additions & 0 deletions recipes/emscripten-activation/activate.sh
Original file line number Diff line number Diff line change
@@ -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
h-vetinari marked this conversation as resolved.
Show resolved Hide resolved

CONDA_EMSDK_DIR=$CONDA_PREFIX/opt/emsdk

export EMSCRIPTEN_VERSION=$PKG_VERSION
h-vetinari marked this conversation as resolved.
Show resolved Hide resolved
export EMSCRIPTEN_FORGE_EMSDK_DIR=$CONDA_EMSDK_DIR
h-vetinari marked this conversation as resolved.
Show resolved Hide resolved

# 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 "$@"
}
h-vetinari marked this conversation as resolved.
Show resolved Hide resolved

# useful variables
export PY_SIDE_LD_FLAGV
Comment on lines +32 to +33
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the use of this variable?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@DerThorsten, could you comment?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is very likely some leftover from some debugging in the past, should be removable


# 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"
h-vetinari marked this conversation as resolved.
Show resolved Hide resolved

# wasm bigint
export LDFLAGS="$LDFLAGS -sWASM_BIGINT"

fi
12 changes: 12 additions & 0 deletions recipes/emscripten-activation/conda_build_config.yaml
Original file line number Diff line number Diff line change
@@ -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
12 changes: 12 additions & 0 deletions recipes/emscripten-activation/deactivate.sh
Original file line number Diff line number Diff line change
@@ -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
13 changes: 13 additions & 0 deletions recipes/emscripten-activation/install_emscripten.sh
Original file line number Diff line number Diff line change
@@ -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
11 changes: 11 additions & 0 deletions recipes/emscripten-activation/install_emscripten_impl.sh
Original file line number Diff line number Diff line change
@@ -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
64 changes: 64 additions & 0 deletions recipes/emscripten-activation/meta.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
{% 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", max_pin="x.x.x") }}
requirements:
build:
- gettext
run:
- {{ pin_subpackage("emscripten_impl_" ~ cross_target_platform, exact=True) }}
test:
files:
- testfile.c
commands:
- emcc ./testfile.c
- node a.out.js
Comment on lines +40 to +41
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add an example for a shared library building and use?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fair enough. @DerThorsten, do you have a handy example we could use?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

to compile a shared library one needs the -s SIDE_MODULE=1 flag.
For cmake, one needs and additonal

set_property(GLOBAL PROPERTY TARGET_SUPPORTS_SHARED_LIBS TRUE)

without that line above cmake will compile static libraries even when a shared library is demanded.

The -s SIDE_MODULE=1 can be passed like:

set(CMAKE_SHARED_LIBRARY_CREATE_C_FLAGS "-s SIDE_MODULE=1")
set(CMAKE_SHARED_LIBRARY_CREATE_CXX_FLAGS "-s SIDE_MODULE=1")

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the question was about actually building some concrete example of a shared library as part of the testing for the activation feedstock, rather than just testfile.c.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


- name: emscripten-abi
build:
noarch: generic
test:
commands:
- echo "emscripten abi is built."

about:
home: https://emscripten.org
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
doc_url: https://emscripten.org/

extra:
recipe-maintainers:
- DerThorsten
- wolfv
- h-vetinari
- conda-forge/emscripten
15 changes: 15 additions & 0 deletions recipes/emscripten-activation/testfile.c
Original file line number Diff line number Diff line change
@@ -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 <stdio.h>

int main() {
printf("hello, world!\n");
return 0;
}


Loading