Skip to content

Commit

Permalink
Enable the WASM target (#84)
Browse files Browse the repository at this point in the history
  • Loading branch information
IsabelParedes authored Jun 3, 2024
1 parent 69a27e8 commit ea73953
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 3 deletions.
15 changes: 15 additions & 0 deletions recipe/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,16 @@ set -ex

export CXXFLAGS="${CXXFLAGS} -D__STDC_FORMAT_MACROS -D_LIBCPP_DISABLE_AVAILABILITY"

# Install emsdk
pushd emsdk
./emsdk install 3.1.59
./emsdk activate 3.1.59
source ./emsdk_env.sh
rm ./node/18.20.3_64bit/bin/node
ln -s $(which node) ./node/18.20.3_64bit/bin/node
export EMSDK_PATH=${EMSDK}
popd

if [[ "${CONDA_BUILD_CROSS_COMPILATION:-0}" == 1 ]]; then
WRT=no
(
Expand Down Expand Up @@ -32,6 +42,7 @@ if [[ "${CONDA_BUILD_CROSS_COMPILATION:-0}" == 1 ]]; then
-DWITH_XEUS=yes \
-DWITH_RUNTIME_LIBRARY=yes \
-DWITH_RUNTIME_STACKTRACE=yes \
-DWITH_TARGET_WASM=yes \
-DCMAKE_INSTALL_LIBDIR=share/lfortran/lib \
$SRC_DIR
make
Expand All @@ -52,9 +63,13 @@ cmake ${CMAKE_ARGS} \
-DWITH_XEUS=yes \
-DWITH_RUNTIME_LIBRARY=$WRT \
-DWITH_RUNTIME_STACKTRACE=yes \
-DWITH_TARGET_WASM=yes \
-DCMAKE_INSTALL_LIBDIR=share/lfortran/lib \
$SRC_DIR

echo "FIND CONFIG FILE"
find . -iname "*config.h"

make -j${CPU_COUNT}
make install
if [[ "${CONDA_BUILD_CROSS_COMPILATION:-0}" == 1 ]]; then
Expand Down
2 changes: 1 addition & 1 deletion recipe/conda_build_config.yaml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
MACOSX_SDK_VERSION: # [osx and x86_64]
- "10.12" # [osx and x86_64]
- "10.13" # [osx and x86_64]
11 changes: 9 additions & 2 deletions recipe/meta.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,23 @@ package:
version: {{ version }}

source:
url: https://github.com/lfortran/lfortran/releases/download/v{{ version }}/{{ name }}-{{ version }}.tar.gz
- url: https://github.com/lfortran/lfortran/releases/download/v{{ version }}/{{ name }}-{{ version }}.tar.gz
sha256: 6b3b7cb1380e96a98a9fd3166a3e7e43c3339f736f76029c246436784ffc868f
patches:
- patches/ctrlib_dir.patch
- patches/libasr_config.patch
- git_url: https://github.com/emscripten-core/emsdk.git
folder: emsdk

build:
number: 0
number: 1

requirements:
build:
- {{ compiler('c') }}
- {{ stdlib("c") }}
- {{ compiler('cxx') }}
- {{ stdlib("c") }}
- cmake =3.21.1
- make # [unix]
- xeus =3.0.5 # [build_platform != target_platform]
Expand All @@ -27,6 +33,7 @@ requirements:
- cppzmq # [build_platform != target_platform]
- zlib # [build_platform != target_platform]
- zstd-static =1.5.5 # [build_platform != target_platform]
- nodejs
host:
- xeus =3.0.5
- xeus-zmq =1.0.2
Expand Down
35 changes: 35 additions & 0 deletions recipe/patches/ctrlib_dir.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
diff --git a/src/runtime/legacy/CMakeLists.txt b/src/runtime/legacy/CMakeLists.txt
index 7eff9c5..fdab1a8 100644
--- a/src/runtime/legacy/CMakeLists.txt
+++ b/src/runtime/legacy/CMakeLists.txt
@@ -1,5 +1,5 @@
set(SRC
- ../../../src/libasr/runtime/lfortran_intrinsics.c
+ ${CMAKE_CURRENT_SOURCE_DIR}/../../../src/libasr/runtime/lfortran_intrinsics.c
)

if(WIN32)
@@ -33,16 +33,18 @@ if(WITH_TARGET_WASM)
endif()

if (DEFINED ENV{EMSDK_PATH})
- add_custom_command(OUTPUT lfortran_runtime_wasm_emcc.o
+ add_custom_command(OUTPUT ${CMAKE_CURRENT_SOURCE_DIR}/lfortran_runtime_wasm_emcc.o
COMMAND $ENV{EMSDK_PATH}/upstream/emscripten/emcc -I${libasr_SOURCE_DIR}/.. -DCOMPILE_TO_WASM
- -c --target=wasm32-unknown-emscripten ${SRC} -o lfortran_runtime_wasm_emcc.o
+ -c --target=wasm32-unknown-emscripten ${SRC} -o ${CMAKE_CURRENT_SOURCE_DIR}/lfortran_runtime_wasm_emcc.o
COMMENT "Cross compiling lfortran_intrinscs.c to lfortran_runtime_wasm_emcc.o"
DEPENDS ${SRC})
- add_custom_target(lfortran_runtime_wasm_emcc ALL DEPENDS lfortran_runtime_wasm_emcc.o)
- install(FILES lfortran_runtime_wasm_emcc.o
+ add_custom_target(lfortran_runtime_wasm_emcc ALL DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/lfortran_runtime_wasm_emcc.o)
+ install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/lfortran_runtime_wasm_emcc.o
DESTINATION ${CMAKE_INSTALL_LIBDIR})
- install(FILES lfortran_runtime_wasm_emcc.o
+ install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/lfortran_runtime_wasm_emcc.o
DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/..)
+ install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/lfortran_runtime_wasm_emcc.o
+ DESTINATION ${CMAKE_BINARY_DIR})
endif()

if (DEFINED ENV{WASI_SDK_PATH})
13 changes: 13 additions & 0 deletions recipe/patches/libasr_config.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
diff --git a/src/libasr/CMakeLists.txt b/src/libasr/CMakeLists.txt
index aaf9db9..7f981a8 100644
--- a/src/libasr/CMakeLists.txt
+++ b/src/libasr/CMakeLists.txt
@@ -12,7 +12,7 @@ if (NOT LFORTRAN_VERSION)
CACHE STRING "LFortran version" FORCE)
endif ()

-configure_file(config.h.in config.h)
+configure_file(config.h.in ${CMAKE_CURRENT_SOURCE_DIR}/config.h)

set(SRC
codegen/asr_to_cpp.cpp

0 comments on commit ea73953

Please sign in to comment.