From f00061d87ac117d90cc71ab362ec06e85008ce32 Mon Sep 17 00:00:00 2001 From: Yanshu Wang Date: Sat, 18 Jul 2026 23:26:38 +0800 Subject: [PATCH 1/6] add M2 --- recipes/recipes_emscripten/M2/build.sh | 71 +++++++++++++++++++ recipes/recipes_emscripten/M2/recipe.yaml | 85 +++++++++++++++++++++++ 2 files changed, 156 insertions(+) create mode 100644 recipes/recipes_emscripten/M2/build.sh create mode 100644 recipes/recipes_emscripten/M2/recipe.yaml diff --git a/recipes/recipes_emscripten/M2/build.sh b/recipes/recipes_emscripten/M2/build.sh new file mode 100644 index 0000000000..d167eb3008 --- /dev/null +++ b/recipes/recipes_emscripten/M2/build.sh @@ -0,0 +1,71 @@ +#!/usr/bin/env bash +set -euxo pipefail + +cd M2/BUILD/build + +mkdir install_prefix + +# Strip the CMP0167 line +sed -i '/CMP0167/d' ../../cmake/check-libraries.cmake + +# Excise the missing submodules (mathicgb, mathic, memtailor) from CMake targets +sed -i '/add_subdirectory(memtailor)/d' ../../Macaulay2/e/CMakeLists.txt +sed -i '/add_subdirectory(mathic)/d' ../../Macaulay2/e/CMakeLists.txt +sed -i '/add_subdirectory(mathicgb)/d' ../../Macaulay2/e/CMakeLists.txt +sed -i '/target_compile_options(mathicgb/,/)/d' ../../Macaulay2/e/CMakeLists.txt +sed -i '/install(TARGETS.*mathicgb/,/)/d' ../../Macaulay2/e/CMakeLists.txt +sed -i '/export(TARGETS.*mathicgb/,/)/d' ../../Macaulay2/CMakeLists.txt + +# Patch FindNauty.cmake to prevent it from shadowing the CLI variables +sed -i '/set(NAUTY_INCLUDE_DIR NOTFOUND)/d' ../../cmake/FindNauty.cmake +sed -i '/set(NAUTY_LIBRARIES NOTFOUND)/d' ../../cmake/FindNauty.cmake +sed -i '/_NAUTY_check_version()/d' ../../cmake/FindNauty.cmake + +# Patch gc-include.h to stop it from forcing multithreading on Boehm GC +sed -i '/#define GC_THREADS 1/d' ../../include/M2/gc-include.h +sed -i '/#define GC_LINUX_THREADS/d' ../../include/M2/gc-include.h + +# Create active dummy executables that return a clean exit 0 +mkdir -p $PREFIX/bin + +echo '#!/bin/sh' > $PREFIX/bin/normaliz +echo 'exit 0' >> $PREFIX/bin/normaliz +chmod +x $PREFIX/bin/normaliz + +echo '#!/bin/sh' > $PREFIX/bin/dreadnaut +echo 'exit 0' >> $PREFIX/bin/dreadnaut +chmod +x $PREFIX/bin/dreadnaut + +emcmake cmake -S ../.. -B . \ + -DCMAKE_BUILD_TYPE=Release \ + -DCMAKE_INSTALL_PREFIX=install_prefix \ + -DCMAKE_PREFIX_PATH=$PREFIX \ + -DCMAKE_FIND_ROOT_PATH=$PREFIX \ + -DBLA_VENDOR=OpenBLAS \ + -DBLAS_LIBRARIES=$PREFIX/lib/libopenblas.a \ + -DLAPACK_LIBRARIES=$PREFIX/lib/libopenblas.a \ + -DBoost_NO_BOOST_CMAKE=ON \ + -DWITH_OMP=OFF \ + -DCMAKE_C_FLAGS="-fopenmp -DGC_NO_THREAD_REDIRECTS -DGC_NO_THREADS=2" \ + -DCMAKE_CXX_FLAGS="-fopenmp -DGC_NO_THREAD_REDIRECTS -DGC_NO_THREADS=2" \ + -DCMAKE_EXE_LINKER_FLAGS="-s ALLOW_MEMORY_GROWTH=1 -s NODERAWFS=1" \ + -DREADLINE_INCLUDE_DIR=$PREFIX/include \ + -DREADLINE_LIBRARY=$PREFIX/lib/libreadline.a \ + -DHISTORY_INCLUDE_DIR=$PREFIX/include \ + -DHISTORY_LIBRARY=$PREFIX/lib/libhistory.a \ + -DWITH_PYTHON=OFF \ + -DCMAKE_DISABLE_FIND_PACKAGE_LATEX=ON \ + -DCHECK_LIBRARY_COMPATIBILITY=OFF \ + -DNAUTY_EXECUTABLE=$PREFIX/bin/dreadnaut \ + -DNAUTY_INCLUDE_DIR=$PREFIX/include \ + -DNAUTY_LIBRARIES=$PREFIX/lib/libnauty.a \ + -DNAUTY_VERSION_OK=ON \ + -DNORMALIZ_EXECUTABLE=$PREFIX/bin/normaliz \ + -DNORMALIZ_INCLUDE_DIR=$PREFIX/include \ + -DNORMALIZ_LIBRARIES=$PREFIX/lib/libnormaliz.a \ + -DBUILD_NATIVE=OFF + +emmake make build-libraries +emmake make M2-binary M2-core +emmake make build-programs +emmake install-packages \ No newline at end of file diff --git a/recipes/recipes_emscripten/M2/recipe.yaml b/recipes/recipes_emscripten/M2/recipe.yaml new file mode 100644 index 0000000000..6040828e0f --- /dev/null +++ b/recipes/recipes_emscripten/M2/recipe.yaml @@ -0,0 +1,85 @@ +context: + name: M2 + version: 1.26.06 + +package: + name: ${{ name }} + version: ${{ version }} + +source: + url: https://github.com/Macaulay2/M2/releases/download/release-${{ version }}/Macaulay2-${{ version }}.tar.gz + sha256: 9ba54041626f6364036f84b4168704d74136d1bec2dbe08d9d0fb3fef2a0c854 + +build: + number: 0 + +requirements: + build: + - autoconf + - automake + - libtool + - make + - ${{ compiler("c") }} + - ${{ compiler('cxx') }} + - pkg-config + - autoconf-archive + - bison + - flex + - diffutils + - patch + - gettext + - nodejs >=22 + - gfortran + host: + - 4ti2 + - libgc + - boost-cpp + - cddlib + - csdp + - eigen + - fflas-ffpack + - libflint + - givaro + - glpk + - jansson + - libxml2 + - lrslib + - mpfi + - topcom + - cohomcalg + - fplll + - libfrobby + - glpk + - gmp + - xz + - memtailor + - mathic + - mathicgb + - mpfr + - mpsolve + - nauty + - normaliz + - ntl + - openblas + - singular + - lrslib + - onetbb + - zlib + - libffi + - gfanlib + - msolve + - gdbm + - ncurses + - gtest + - zlib + - readline + +about: + homepage: https://macaulay2.com/ + license: GPL-2.0-or-later + license_file: README.md + summary: The primary source code repository for Macaulay2, a system for computing in commutative algebra, algebraic geometry and related fields. + +extra: + recipe-maintainers: + - wangyenshu \ No newline at end of file From aa0a407d55eb691cb22cb0277fe8203096496e76 Mon Sep 17 00:00:00 2001 From: Yanshu Wang Date: Sun, 19 Jul 2026 09:51:40 +0800 Subject: [PATCH 2/6] update --- recipes/recipes_emscripten/M2/build.sh | 14 ++++++++++---- recipes/recipes_emscripten/M2/recipe.yaml | 3 ++- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/recipes/recipes_emscripten/M2/build.sh b/recipes/recipes_emscripten/M2/build.sh index d167eb3008..a1c3d2c992 100644 --- a/recipes/recipes_emscripten/M2/build.sh +++ b/recipes/recipes_emscripten/M2/build.sh @@ -8,14 +8,17 @@ mkdir install_prefix # Strip the CMP0167 line sed -i '/CMP0167/d' ../../cmake/check-libraries.cmake -# Excise the missing submodules (mathicgb, mathic, memtailor) from CMake targets +# Excise the missing submodules from CMake targets sed -i '/add_subdirectory(memtailor)/d' ../../Macaulay2/e/CMakeLists.txt sed -i '/add_subdirectory(mathic)/d' ../../Macaulay2/e/CMakeLists.txt sed -i '/add_subdirectory(mathicgb)/d' ../../Macaulay2/e/CMakeLists.txt sed -i '/target_compile_options(mathicgb/,/)/d' ../../Macaulay2/e/CMakeLists.txt -sed -i '/install(TARGETS.*mathicgb/,/)/d' ../../Macaulay2/e/CMakeLists.txt sed -i '/export(TARGETS.*mathicgb/,/)/d' ../../Macaulay2/CMakeLists.txt +# Patch e/CMakeLists.txt using the EXACT text from your unmodified source file +sed -i "s|PUBLIC memtailor mathic mathicgb|PUBLIC $PREFIX/lib/libmemtailor.a $PREFIX/lib/libmathic.a $PREFIX/lib/libmathicgb.a|g" ../../Macaulay2/e/CMakeLists.txt +sed -i 's|mathicgb mathic memtailor||g' ../../Macaulay2/e/CMakeLists.txt + # Patch FindNauty.cmake to prevent it from shadowing the CLI variables sed -i '/set(NAUTY_INCLUDE_DIR NOTFOUND)/d' ../../cmake/FindNauty.cmake sed -i '/set(NAUTY_LIBRARIES NOTFOUND)/d' ../../cmake/FindNauty.cmake @@ -25,6 +28,9 @@ sed -i '/_NAUTY_check_version()/d' ../../cmake/FindNauty.cmake sed -i '/#define GC_THREADS 1/d' ../../include/M2/gc-include.h sed -i '/#define GC_LINUX_THREADS/d' ../../include/M2/gc-include.h +# Force static linking of OpenBLAS by deleting the dynamic library from the build prefix +rm -f $PREFIX/lib/libopenblas.so* + # Create active dummy executables that return a clean exit 0 mkdir -p $PREFIX/bin @@ -46,8 +52,8 @@ emcmake cmake -S ../.. -B . \ -DLAPACK_LIBRARIES=$PREFIX/lib/libopenblas.a \ -DBoost_NO_BOOST_CMAKE=ON \ -DWITH_OMP=OFF \ - -DCMAKE_C_FLAGS="-fopenmp -DGC_NO_THREAD_REDIRECTS -DGC_NO_THREADS=2" \ - -DCMAKE_CXX_FLAGS="-fopenmp -DGC_NO_THREAD_REDIRECTS -DGC_NO_THREADS=2" \ + -DCMAKE_C_FLAGS="-DGC_NO_THREAD_REDIRECTS -DGC_NO_THREADS=2" \ + -DCMAKE_CXX_FLAGS="-DGC_NO_THREAD_REDIRECTS -DGC_NO_THREADS=2" \ -DCMAKE_EXE_LINKER_FLAGS="-s ALLOW_MEMORY_GROWTH=1 -s NODERAWFS=1" \ -DREADLINE_INCLUDE_DIR=$PREFIX/include \ -DREADLINE_LIBRARY=$PREFIX/lib/libreadline.a \ diff --git a/recipes/recipes_emscripten/M2/recipe.yaml b/recipes/recipes_emscripten/M2/recipe.yaml index 6040828e0f..dbecbb71ba 100644 --- a/recipes/recipes_emscripten/M2/recipe.yaml +++ b/recipes/recipes_emscripten/M2/recipe.yaml @@ -73,6 +73,7 @@ requirements: - gtest - zlib - readline + - cocoalib about: homepage: https://macaulay2.com/ @@ -82,4 +83,4 @@ about: extra: recipe-maintainers: - - wangyenshu \ No newline at end of file + - xxx \ No newline at end of file From a3dfda7b9b3b0d2d2eb9b13ba45c1739b76580ba Mon Sep 17 00:00:00 2001 From: Yanshu Wang Date: Sun, 19 Jul 2026 11:28:17 +0800 Subject: [PATCH 3/6] update --- recipes/recipes_emscripten/M2/recipe.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/recipes/recipes_emscripten/M2/recipe.yaml b/recipes/recipes_emscripten/M2/recipe.yaml index dbecbb71ba..6b30de1b03 100644 --- a/recipes/recipes_emscripten/M2/recipe.yaml +++ b/recipes/recipes_emscripten/M2/recipe.yaml @@ -83,4 +83,4 @@ about: extra: recipe-maintainers: - - xxx \ No newline at end of file + - wangyenshu \ No newline at end of file From 5d15aea3c0571387d4321326247ea8b80fc4ec4d Mon Sep 17 00:00:00 2001 From: wangyenshu <155622798+wangyenshu@users.noreply.github.com> Date: Mon, 20 Jul 2026 15:29:37 +0800 Subject: [PATCH 4/6] Update build.sh --- recipes/recipes_emscripten/M2/build.sh | 77 +++++++++++++++++++++++--- 1 file changed, 70 insertions(+), 7 deletions(-) diff --git a/recipes/recipes_emscripten/M2/build.sh b/recipes/recipes_emscripten/M2/build.sh index a1c3d2c992..deae8ad294 100644 --- a/recipes/recipes_emscripten/M2/build.sh +++ b/recipes/recipes_emscripten/M2/build.sh @@ -15,15 +15,62 @@ sed -i '/add_subdirectory(mathicgb)/d' ../../Macaulay2/e/CMakeLists.txt sed -i '/target_compile_options(mathicgb/,/)/d' ../../Macaulay2/e/CMakeLists.txt sed -i '/export(TARGETS.*mathicgb/,/)/d' ../../Macaulay2/CMakeLists.txt -# Patch e/CMakeLists.txt using the EXACT text from your unmodified source file +# Patch e/CMakeLists.txt to explicitly link the absolute paths of the conda-forge math packages sed -i "s|PUBLIC memtailor mathic mathicgb|PUBLIC $PREFIX/lib/libmemtailor.a $PREFIX/lib/libmathic.a $PREFIX/lib/libmathicgb.a|g" ../../Macaulay2/e/CMakeLists.txt sed -i 's|mathicgb mathic memtailor||g' ../../Macaulay2/e/CMakeLists.txt +# Scrub the hardcoded 'quadmath' linking rule from the M2-interpreter CMake configuration +sed -i '/quadmath/d' ../../Macaulay2/d/CMakeLists.txt + +# Remove Readline and History dependencies from the CMake configuration +sed -i '/find_package(Readline/d' ../../cmake/check-libraries.cmake +sed -i '/find_package(History/d' ../../cmake/check-libraries.cmake +sed -i 's/READLINE HISTORY //g' ../../cmake/check-libraries.cmake + +# Patch M2lib.c to replace Readline with standard WebAssembly-compatible I/O +sed -i '/readline\/readline.h/d' ../../Macaulay2/d/M2lib.c +sed -i '/readline\/history.h/d' ../../Macaulay2/d/M2lib.c +sed -i '/Functions dealing with libreadline/,$d' ../../Macaulay2/d/M2lib.c + +cat << 'EOF' >> ../../Macaulay2/d/M2lib.c +#include +#include + +int system_readHistory(char *filename) { return 0; } +int system_appendHistory(int n, char *filename) { return 0; } +void system_addHistory(char *buf) { } +char *system_getHistory(const int n) { return NULL; } +int system_historyLength() { return 0; } +void system_initReadlineVariables(void) { } + +int system_readline(M2_string buffer, int len, int offset, M2_string prompt) { + char *p = M2_tocharstar(prompt); + printf("%s", p); + fflush(stdout); + freemem(p); + + char *buf_ptr = (char *)buffer->array + offset; + if (fgets(buf_ptr, len, stdin) == NULL) return 0; + + int r = strlen(buf_ptr); + /* Optional: replace trailing newline with null terminator if strictly needed */ + return r; +} +EOF + +# Patch version.dd to remove readline version queries +sed -i '/readline\/readline.h/d' ../../Macaulay2/d/version.dd +sed -i 's/"readline version" => Ccode(constcharstar,"stringize(RL_VERSION_MAJOR) \\".\\" stringize(RL_VERSION_MINOR)"),/"readline version" => "not present",/g' ../../Macaulay2/d/version.dd + # Patch FindNauty.cmake to prevent it from shadowing the CLI variables sed -i '/set(NAUTY_INCLUDE_DIR NOTFOUND)/d' ../../cmake/FindNauty.cmake sed -i '/set(NAUTY_LIBRARIES NOTFOUND)/d' ../../cmake/FindNauty.cmake sed -i '/_NAUTY_check_version()/d' ../../cmake/FindNauty.cmake +# Forcefully append hidden dependencies to Find modules so they are guaranteed to link +echo "list(APPEND NORMALIZ_LIBRARIES \"$PREFIX/lib/libcocoa.a\")" >> ../../cmake/FindNormaliz.cmake +echo "list(APPEND FACTORY_LIBRARIES \"$PREFIX/lib/libomalloc.a\" \"$PREFIX/lib/libsingular_resources.a\")" >> ../../cmake/FindFactory.cmake + # Patch gc-include.h to stop it from forcing multithreading on Boehm GC sed -i '/#define GC_THREADS 1/d' ../../include/M2/gc-include.h sed -i '/#define GC_LINUX_THREADS/d' ../../include/M2/gc-include.h @@ -31,6 +78,26 @@ sed -i '/#define GC_LINUX_THREADS/d' ../../include/M2/gc-include.h # Force static linking of OpenBLAS by deleting the dynamic library from the build prefix rm -f $PREFIX/lib/libopenblas.so* +# Create a dummy library to stub the unsupported pthread_kill signal +echo "int pthread_kill(long t, int s) { return 0; }" > dummy_pthread.c +emcc -c dummy_pthread.c -o dummy_pthread.o +emar rcs $PREFIX/lib/libdummy_pthread.a dummy_pthread.o + +sed -i 's/if(LDD)/if(FALSE)/g' ../../Macaulay2/bin/CMakeLists.txt +sed -i 's/exec `/exec node --max-old-space-size=4096 `/g' ../../Macaulay2/bin/CMakeLists.txt + +cat << 'EOF' >> ../../Macaulay2/bin/CMakeLists.txt + +target_link_options(M2-binary PRIVATE + "-sTOTAL_STACK=32mb" + "-sINITIAL_MEMORY=512mb" + "-sALLOW_MEMORY_GROWTH=1" + "-sMAXIMUM_MEMORY=4gb" + "-sFORCE_FILESYSTEM=1" + "-sNODERAWFS=1" +) +EOF + # Create active dummy executables that return a clean exit 0 mkdir -p $PREFIX/bin @@ -54,11 +121,7 @@ emcmake cmake -S ../.. -B . \ -DWITH_OMP=OFF \ -DCMAKE_C_FLAGS="-DGC_NO_THREAD_REDIRECTS -DGC_NO_THREADS=2" \ -DCMAKE_CXX_FLAGS="-DGC_NO_THREAD_REDIRECTS -DGC_NO_THREADS=2" \ - -DCMAKE_EXE_LINKER_FLAGS="-s ALLOW_MEMORY_GROWTH=1 -s NODERAWFS=1" \ - -DREADLINE_INCLUDE_DIR=$PREFIX/include \ - -DREADLINE_LIBRARY=$PREFIX/lib/libreadline.a \ - -DHISTORY_INCLUDE_DIR=$PREFIX/include \ - -DHISTORY_LIBRARY=$PREFIX/lib/libhistory.a \ + -DCMAKE_EXE_LINKER_FLAGS="-s ALLOW_MEMORY_GROWTH=1 -s NODERAWFS=1 -L$PREFIX/lib -ldummy_pthread -s TOTAL_STACK=32MB -s INITIAL_MEMORY=512MB -s MAXIMUM_MEMORY=4GB -s FORCE_FILESYSTEM=1" \ -DWITH_PYTHON=OFF \ -DCMAKE_DISABLE_FIND_PACKAGE_LATEX=ON \ -DCHECK_LIBRARY_COMPATIBILITY=OFF \ @@ -74,4 +137,4 @@ emcmake cmake -S ../.. -B . \ emmake make build-libraries emmake make M2-binary M2-core emmake make build-programs -emmake install-packages \ No newline at end of file +emmake install-packages From cd66f90ce39f67541d10d734bf977dcf8cd793fc Mon Sep 17 00:00:00 2001 From: wangyenshu <155622798+wangyenshu@users.noreply.github.com> Date: Mon, 20 Jul 2026 15:30:13 +0800 Subject: [PATCH 5/6] Update recipe.yaml --- recipes/recipes_emscripten/M2/recipe.yaml | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/recipes/recipes_emscripten/M2/recipe.yaml b/recipes/recipes_emscripten/M2/recipe.yaml index 6b30de1b03..493c9a367f 100644 --- a/recipes/recipes_emscripten/M2/recipe.yaml +++ b/recipes/recipes_emscripten/M2/recipe.yaml @@ -69,10 +69,8 @@ requirements: - gfanlib - msolve - gdbm - - ncurses - gtest - zlib - - readline - cocoalib about: @@ -83,4 +81,4 @@ about: extra: recipe-maintainers: - - wangyenshu \ No newline at end of file + - wangyenshu From 43b97729583315fbfa45ae4a741c3ce61eac2215 Mon Sep 17 00:00:00 2001 From: wangyenshu <155622798+wangyenshu@users.noreply.github.com> Date: Mon, 20 Jul 2026 15:36:22 +0800 Subject: [PATCH 6/6] use 2gb initial memory --- recipes/recipes_emscripten/M2/build.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/recipes/recipes_emscripten/M2/build.sh b/recipes/recipes_emscripten/M2/build.sh index deae8ad294..67195bbb4b 100644 --- a/recipes/recipes_emscripten/M2/build.sh +++ b/recipes/recipes_emscripten/M2/build.sh @@ -90,7 +90,7 @@ cat << 'EOF' >> ../../Macaulay2/bin/CMakeLists.txt target_link_options(M2-binary PRIVATE "-sTOTAL_STACK=32mb" - "-sINITIAL_MEMORY=512mb" + "-sINITIAL_MEMORY=2gb" "-sALLOW_MEMORY_GROWTH=1" "-sMAXIMUM_MEMORY=4gb" "-sFORCE_FILESYSTEM=1" @@ -121,7 +121,7 @@ emcmake cmake -S ../.. -B . \ -DWITH_OMP=OFF \ -DCMAKE_C_FLAGS="-DGC_NO_THREAD_REDIRECTS -DGC_NO_THREADS=2" \ -DCMAKE_CXX_FLAGS="-DGC_NO_THREAD_REDIRECTS -DGC_NO_THREADS=2" \ - -DCMAKE_EXE_LINKER_FLAGS="-s ALLOW_MEMORY_GROWTH=1 -s NODERAWFS=1 -L$PREFIX/lib -ldummy_pthread -s TOTAL_STACK=32MB -s INITIAL_MEMORY=512MB -s MAXIMUM_MEMORY=4GB -s FORCE_FILESYSTEM=1" \ + -DCMAKE_EXE_LINKER_FLAGS="-s ALLOW_MEMORY_GROWTH=1 -s NODERAWFS=1 -L$PREFIX/lib -ldummy_pthread -s TOTAL_STACK=32MB -s INITIAL_MEMORY=2GB -s MAXIMUM_MEMORY=4GB -s FORCE_FILESYSTEM=1" \ -DWITH_PYTHON=OFF \ -DCMAKE_DISABLE_FIND_PACKAGE_LATEX=ON \ -DCHECK_LIBRARY_COMPATIBILITY=OFF \