emscripten: various fixes (#7700)

* emscripten: update to 2.0.31 (deps)

* emscripten: move depends to recommends

* emscripten: move directory from lib to opt

* emscripten: patch to fix x86 build error

* emscripten: improve build script
This commit is contained in:
Jia Yuan Lo 2021-10-08 17:13:20 +08:00 committed by GitHub
parent 69a7ab0e0c
commit 9b9b7a492a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 128 additions and 49 deletions

View File

@ -3,12 +3,11 @@ TERMUX_PKG_DESCRIPTION="Emscripten: An LLVM-to-WebAssembly Compiler"
TERMUX_PKG_LICENSE="MIT"
TERMUX_PKG_MAINTAINER="@truboxl"
TERMUX_PKG_VERSION=2.0.31
TERMUX_PKG_REVISION=1
TERMUX_PKG_REVISION=2
TERMUX_PKG_SRCURL=https://github.com/emscripten-core/emscripten.git
TERMUX_PKG_GIT_BRANCH=$TERMUX_PKG_VERSION
TERMUX_PKG_DEPENDS="python, nodejs, debianutils"
TERMUX_PKG_PLATFORM_INDEPENDENT=true
TERMUX_PKG_RECOMMENDS="emscripten-llvm, emscripten-binaryen"
TERMUX_PKG_RECOMMENDS="emscripten-llvm, emscripten-binaryen, python, nodejs-lts | nodejs, debianutils"
TERMUX_PKG_BUILD_IN_SRC=true
TERMUX_PKG_HOSTBUILD=true
TERMUX_PKG_NO_STATICSPLIT=true
@ -28,34 +27,35 @@ TERMUX_PKG_NO_STATICSPLIT=true
# https://github.com/emscripten-core/emscripten/issues/11362
# can switch to stable LLVM to save space once above is fixed
LLVM_COMMIT=9016b2a1cae244eb8f26826427eeb90eded0da20
LLVM_TGZ_SHA256=174253005e14d2fe7ba412f71b4e13cfdcf7fdd3b471b3dc988283f9198bfc19
LLVM_COMMIT=8fa2394bad433558f3083cee158043e2fb66d781
LLVM_TGZ_SHA256=5199e1e459a9b1308e145d775c540bac72d0a75b81a4558d08ffd7444412f8d1
# https://github.com/emscripten-core/emscripten/issues/12252
# upstream says better bundle the right binaryen revision for now
BINARYEN_COMMIT=c2007eab91ed60ac4bc8a6a555e9dc3e76ef2242
BINARYEN_TGZ_SHA256=f49e71078e7bdded666d81e715dd799ef6aaa65decd5bbff7f35551879d36799
BINARYEN_COMMIT=65bcde2c30e82047a892332b95b114bc86f89614
BINARYEN_TGZ_SHA256=093bf206d34a7e239b4ae9dd9e9f393099622cebaa781d859b0f85e2305735d4
# https://github.com/emscripten-core/emsdk/blob/main/emsdk.py
# https://chromium.googlesource.com/emscripten-releases/+/refs/heads/main/src/build.py
# https://github.com/llvm/llvm-project
LLVM_BUILD_ARGS="
-DCMAKE_BUILD_TYPE=Release
-DCMAKE_BUILD_TYPE=MinSizeRel
-DCMAKE_CROSSCOMPILING=ON
-DCMAKE_INSTALL_PREFIX=$TERMUX_PREFIX/lib/emscripten-llvm
-DCMAKE_INSTALL_PREFIX=$TERMUX_PREFIX/opt/emscripten-llvm
-DDEFAULT_SYSROOT=$(dirname $TERMUX_PREFIX)
-DGENERATOR_IS_MULTI_CONFIG=ON
-DLLVM_INCLUDE_EXAMPLES=OFF
-DLLVM_INCLUDE_TESTS=OFF
-DLLVM_INSTALL_TOOLCHAIN_ONLY=ON
-DLLVM_ENABLE_ASSERTIONS=OFF
-DLLVM_ENABLE_ASSERTIONS=ON
-DLLVM_ENABLE_BINDINGS=OFF
-DLLVM_ENABLE_LIBEDIT=OFF
-DLLVM_ENABLE_LIBPFM=OFF
-DLLVM_ENABLE_LIBXML2=OFF
-DLLVM_ENABLE_PROJECTS='clang;compiler-rt;libunwind;lld'
-DLLVM_ENABLE_PROJECTS=clang;compiler-rt;libunwind;lld
-DLLVM_ENABLE_TERMINFO=OFF
-DLLVM_INCLUDE_EXAMPLES=OFF
-DLLVM_INCLUDE_TESTS=OFF
-DLLVM_INSTALL_TOOLCHAIN_ONLY=ON
-DLLVM_LINK_LLVM_DYLIB=ON
-DLLVM_TABLEGEN=$TERMUX_PKG_HOSTBUILD_DIR/bin/llvm-tblgen
-DCLANG_ENABLE_ARCMT=OFF
@ -75,8 +75,8 @@ LLVM_BUILD_ARGS="
# https://github.com/WebAssembly/binaryen/blob/main/CMakeLists.txt
BINARYEN_BUILD_ARGS="
-DCMAKE_BUILD_TYPE=Release
-DCMAKE_INSTALL_PREFIX=$TERMUX_PREFIX/lib/emscripten-binaryen
-DCMAKE_BUILD_TYPE=MinSizeRel
-DCMAKE_INSTALL_PREFIX=$TERMUX_PREFIX/opt/emscripten-binaryen
"
termux_step_post_get_source() {
@ -90,6 +90,9 @@ termux_step_post_get_source() {
"$BINARYEN_TGZ_SHA256"
tar -xf "$TERMUX_PKG_CACHEDIR/llvm.tar.gz" -C "$TERMUX_PKG_CACHEDIR"
tar -xf "$TERMUX_PKG_CACHEDIR/binaryen.tar.gz" -C "$TERMUX_PKG_CACHEDIR"
cd "$TERMUX_PKG_CACHEDIR/llvm-project-$LLVM_COMMIT"
git apply "$TERMUX_PKG_BUILDER_DIR/llvm-project.git-patch.txt"
}
termux_step_host_build() {
@ -98,8 +101,8 @@ termux_step_host_build() {
cmake \
-G Ninja \
-DLLVM_ENABLE_PROJECTS='clang' \
"$TERMUX_PKG_CACHEDIR/llvm-project-$LLVM_COMMIT/llvm"
-S "$TERMUX_PKG_CACHEDIR/llvm-project-$LLVM_COMMIT/llvm" \
-DLLVM_ENABLE_PROJECTS=clang
cmake \
--build "$TERMUX_PKG_HOSTBUILD_DIR" \
-j "$TERMUX_MAKE_PROCESSES" \
@ -129,9 +132,9 @@ termux_step_make() {
cmake \
-G Ninja \
$LLVM_BUILD_ARGS \
-S "$TERMUX_PKG_CACHEDIR/llvm-project-$LLVM_COMMIT/llvm" \
-B "$TERMUX_PKG_CACHEDIR/build-llvm"
-B "$TERMUX_PKG_CACHEDIR/build-llvm" \
$LLVM_BUILD_ARGS
cmake \
--build "$TERMUX_PKG_CACHEDIR/build-llvm" \
-j "$TERMUX_MAKE_PROCESSES" \
@ -139,9 +142,9 @@ termux_step_make() {
cmake \
-G Ninja \
$BINARYEN_BUILD_ARGS \
-S "$TERMUX_PKG_CACHEDIR/binaryen-$BINARYEN_COMMIT" \
-B "$TERMUX_PKG_CACHEDIR/build-binaryen"
-B "$TERMUX_PKG_CACHEDIR/build-binaryen" \
$BINARYEN_BUILD_ARGS
cmake \
--build "$TERMUX_PKG_CACHEDIR/build-binaryen" \
-j "$TERMUX_MAKE_PROCESSES" \
@ -150,64 +153,81 @@ termux_step_make() {
termux_step_make_install() {
# skip using Makefile which does host npm install, tar archive and extract steps
rm -fr "$TERMUX_PREFIX/lib/emscripten"
./tools/install.py "$TERMUX_PREFIX/lib/emscripten"
rm -fr "$TERMUX_PREFIX/opt/emscripten"
./tools/install.py "$TERMUX_PREFIX/opt/emscripten"
# first run generates .emscripten and exits immediately
rm -f "$TERMUX_PKG_SRCDIR/.emscripten"
./emcc
sed -i .emscripten -e "s|^EMSCRIPTEN_ROOT.*|EMSCRIPTEN_ROOT = '$TERMUX_PREFIX/lib/emscripten' # directory|"
sed -i .emscripten -e "s|^LLVM_ROOT.*|LLVM_ROOT = '$TERMUX_PREFIX/lib/emscripten-llvm/bin' # directory|"
sed -i .emscripten -e "s|^BINARYEN_ROOT.*|BINARYEN_ROOT = '$TERMUX_PREFIX/lib/emscripten-binaryen' # directory|"
sed -i .emscripten -e "s|^EMSCRIPTEN_ROOT.*|EMSCRIPTEN_ROOT = '$TERMUX_PREFIX/opt/emscripten' # directory|"
sed -i .emscripten -e "s|^LLVM_ROOT.*|LLVM_ROOT = '$TERMUX_PREFIX/opt/emscripten-llvm/bin' # directory|"
sed -i .emscripten -e "s|^BINARYEN_ROOT.*|BINARYEN_ROOT = '$TERMUX_PREFIX/opt/emscripten-binaryen' # directory|"
sed -i .emscripten -e "s|^NODE_JS.*|NODE_JS = '$TERMUX_PREFIX/bin/node' # executable|"
grep "$TERMUX_PREFIX" "$TERMUX_PKG_SRCDIR/.emscripten"
install -Dm644 "$TERMUX_PKG_SRCDIR/.emscripten" "$TERMUX_PREFIX/lib/emscripten/.emscripten"
install -Dm644 "$TERMUX_PKG_SRCDIR/.emscripten" "$TERMUX_PREFIX/opt/emscripten/.emscripten"
# https://github.com/emscripten-core/emscripten/issues/9098 (fixed in 2.0.17)
cat <<- EOF > "$TERMUX_PKG_TMPDIR/emscripten.sh"
#!$TERMUX_PREFIX/bin/sh
export PATH=\$PATH:$TERMUX_PREFIX/lib/emscripten
export PATH=\$PATH:$TERMUX_PREFIX/opt/emscripten
EOF
install -Dm644 "$TERMUX_PKG_TMPDIR/emscripten.sh" "$TERMUX_PREFIX/etc/profile.d/emscripten.sh"
# remove unneeded files
for tool in clang-{check,cl,cpp,extdef-mapping,format,func-mapping,import-test,offload-bundler,refactor,rename,scan-deps} \
lld-link ld.lld ld64.lld llvm-lib ld64.lld.darwin{new,old}; do
rm -f "$TERMUX_PREFIX/lib/emscripten-llvm/bin/$tool"
rm -f "$TERMUX_PREFIX/opt/emscripten-llvm/bin/$tool"
done
rm -f $TERMUX_PREFIX/lib/emscripten-llvm/lib/libclang.so*
rm -fr "$TERMUX_PREFIX/lib/emscripten-llvm/share"
rm -f $TERMUX_PREFIX/opt/emscripten-llvm/lib/libclang.so*
rm -fr "$TERMUX_PREFIX/opt/emscripten-llvm/share"
# termux_step_install_license also handles LICENSE file
rm -f "$TERMUX_PREFIX/opt/emscripten/LICENSE"
# add useful tools not installed by LLVM_INSTALL_TOOLCHAIN_ONLY=ON
for tool in FileCheck llc llvm-{as,dis,link,mc,nm,objdump,readobj,size,dwarfdump,dwp} opt; do
install -Dm755 "$TERMUX_PKG_CACHEDIR/build-llvm/bin/$tool" "$TERMUX_PREFIX/lib/emscripten-llvm/bin/$tool"
install -Dm755 "$TERMUX_PKG_CACHEDIR/build-llvm/bin/$tool" "$TERMUX_PREFIX/opt/emscripten-llvm/bin/$tool"
done
}
termux_step_create_debscripts() {
cat <<- EOF > postinst
#!$TERMUX_PREFIX/bin/sh
echo 'Running "npm ci --no-optional --production" in $TERMUX_PREFIX/lib/emscripten ...'
cd "$TERMUX_PREFIX/lib/emscripten"
if [ -n "\$(which npm)" ]; then
echo 'Running "npm ci --no-optional --production" in $TERMUX_PREFIX/opt/emscripten ...'
cd "$TERMUX_PREFIX/opt/emscripten"
npm ci --no-optional --production
echo
echo 'Post-install notice:'
echo 'If this is the first time installing Emscripten,'
echo 'please start a new session to take effect.'
echo 'If you are upgrading, you may want to clear the'
echo 'cache by running the command below to fix issues.'
echo '"emcc --clear-cache"'
echo 'Optional: Run the command below in Emscripten'
echo 'directory to install tests dependencies before'
echo 'running test suite.'
echo '"npm ci --no-optional"'
else
echo 'Warning: npm is not installed! Emscripten may not work properly without installing node modules!' >&2
fi
echo '
====================
Post-install notice:
If this is the first time installing Emscripten,
please start a new session to take effect.
If you are upgrading, you may want to clear the
cache by running the command below to fix issues.
"emcc --clear-cache"
Optional: Run the command below in Emscripten
directory to install tests dependencies before
running test suite.
"npm ci --no-optional"'
if [ -d "$TERMUX_PREFIX/lib/emscripten" ]; then
echo '
Note: The old Emscripten path has been deprecated.
To delete, simply run the command below.
"rm -fr $TERMUX_PREFIX/lib/emscripten"'
fi
echo '
===================='
EOF
cat <<- EOF > postrm
#!$TERMUX_PREFIX/bin/sh
case "\$1" in
purge|remove)
rm -fr "$TERMUX_PREFIX/lib/emscripten"
rm -fr "$TERMUX_PREFIX/opt/emscripten"
esac
EOF
}

View File

@ -1,3 +1,3 @@
TERMUX_SUBPKG_DESCRIPTION="Emscripten-compatible Binaryen"
TERMUX_SUBPKG_PLATFORM_INDEPENDENT=false
TERMUX_SUBPKG_INCLUDE="lib/emscripten-binaryen"
TERMUX_SUBPKG_INCLUDE="opt/emscripten-binaryen"

View File

@ -1,3 +1,3 @@
TERMUX_SUBPKG_DESCRIPTION="Emscripten-compatible LLVM"
TERMUX_SUBPKG_PLATFORM_INDEPENDENT=false
TERMUX_SUBPKG_INCLUDE="lib/emscripten-llvm"
TERMUX_SUBPKG_INCLUDE="opt/emscripten-llvm"

View File

@ -0,0 +1,59 @@
diff --git a/libunwind/CMakeLists.txt b/libunwind/CMakeLists.txt
index 16331d948b12..c99b3574e218 100644
--- a/libunwind/CMakeLists.txt
+++ b/libunwind/CMakeLists.txt
@@ -188,6 +188,10 @@ endif()
add_compile_flags_if_supported(-Werror=return-type)
if (LIBUNWIND_ENABLE_CET)
+ if (NOT "libunwind" IN_LIST LLVM_ENABLE_RUNTIMES
+ AND "clang" IN_LIST LLVM_ENABLE_PROJECTS)
+ include_directories("${CMAKE_CURRENT_SOURCE_DIR}/../clang/lib/Headers")
+ endif()
add_compile_flags_if_supported(-fcf-protection=full)
add_compile_flags_if_supported(-mshstk)
if (NOT LIBUNWIND_SUPPORTS_FCF_PROTECTION_EQ_FULL_FLAG)
diff --git a/libunwind/src/assembly.h b/libunwind/src/assembly.h
index e38d32336929..aadb4bc6a083 100644
--- a/libunwind/src/assembly.h
+++ b/libunwind/src/assembly.h
@@ -15,7 +15,7 @@
#ifndef UNWIND_ASSEMBLY_H
#define UNWIND_ASSEMBLY_H
-#if (defined(__i386__) || defined(__x86_64__)) && defined(__linux__)
+#if (defined(__i386__) || defined(__x86_64__)) && defined(__linux__) && defined(_LIBUNWIND_USE_CET)
#include <cet.h>
#define _LIBUNWIND_CET_ENDBR _CET_ENDBR
#else
diff --git a/llvm/tools/llvm-rtdyld/llvm-rtdyld.cpp b/llvm/tools/llvm-rtdyld/llvm-rtdyld.cpp
index 02c11f7689fb..eb6a02ec9198 100644
--- a/llvm/tools/llvm-rtdyld/llvm-rtdyld.cpp
+++ b/llvm/tools/llvm-rtdyld/llvm-rtdyld.cpp
@@ -285,7 +285,7 @@ private:
uintptr_t SlabSize = 0;
uintptr_t CurrentSlabOffset = 0;
SectionIDMap *SecIDMap = nullptr;
-#if defined(__x86_64__) && defined(__ELF__)
+#if defined(__x86_64__) && defined(__ELF__) && !defined(__TERMUX__)
unsigned UsedTLSStorage = 0;
#endif
};
@@ -347,7 +347,7 @@ uint8_t *TrivialMemoryManager::allocateDataSection(uintptr_t Size,
// In case the execution needs TLS storage, we define a very small TLS memory
// area here that will be used in allocateTLSSection().
-#if defined(__x86_64__) && defined(__ELF__)
+#if defined(__x86_64__) && defined(__ELF__) && !defined(__TERMUX__)
extern "C" {
alignas(16) __attribute__((visibility("hidden"), tls_model("initial-exec"),
used)) thread_local char LLVMRTDyldTLSSpace[16];
@@ -358,7 +358,7 @@ TrivialMemoryManager::TLSSection
TrivialMemoryManager::allocateTLSSection(uintptr_t Size, unsigned Alignment,
unsigned SectionID,
StringRef SectionName) {
-#if defined(__x86_64__) && defined(__ELF__)
+#if defined(__x86_64__) && defined(__ELF__) && !defined(__TERMUX__)
if (Size + UsedTLSStorage > sizeof(LLVMRTDyldTLSSpace)) {
return {};
}