File wasi-libcxx.spec of Package wasi-libcxx
#
# spec file for package wasi-compiler-rt
#
# Copyright (c) 2022 SUSE LLC
#
# All modifications and additions to the file contributed by third parties
# remain the property of their copyright owners, unless otherwise agreed
# upon. The license for this file, and modifications and additions to the
# file, is the same license as for the pristine package itself (unless the
# license for the pristine package is not an Open Source License, in which
# case the license is the MIT License). An "Open Source License" is a
# license that conforms to the Open Source Definition (Version 1.9)
# published by the Open Source Initiative.
# Please submit bugfixes or comments via https://bugs.opensuse.org/
#
%define _relver 14.0.6
%define _version %_relver%{?_rc:rc%_rc}
%define _tagver %_relver%{?_rc:-rc%_rc}
%define _minor 14.0
%define _sonum 14
%define _itsme14 1
# Integer version used by update-alternatives
%define _uaver 1406
%define _soclang 13
%define _socxx 1
%define wasi_sysroot %{_datadir}/wasi-sysroot/
Name: wasi-libcxx
Version: %_relver%{?_rc:~rc%_rc}
Release: 0
Summary: WASI version of libc++/libc++abi for WebAssembly
License: Apache-2.0 WITH LLVM-exception AND NCSA
Group: Development/Languages/Other
URL: https://www.llvm.org
Source0: https://github.com/llvm/llvm-project/releases/download/llvmorg-%{_tagver}/llvm-%{_version}.src.tar.xz
Source4: https://github.com/llvm/llvm-project/releases/download/llvmorg-%{_tagver}/libcxx-%{_version}.src.tar.xz
Source5: https://github.com/llvm/llvm-project/releases/download/llvmorg-%{_tagver}/libcxxabi-%{_version}.src.tar.xz
BuildRequires: clang14
BuildRequires: llvm14
BuildRequires: glibc-devel
BuildRequires: llvm14-devel
BuildRequires: cmake >= 3.13.4
BuildRequires: fdupes
BuildRequires: lld14
BuildRequires: wasi-libc
%description
WASI version of libc++/libc++abi for WebAssembly
%prep
%setup -q -a 0 -a 4 -a 5 -c
# Move into right place
mv llvm-%{_version}.src llvm
mv libcxx-%{_version}.src libcxx
mv libcxxabi-%{_version}.src libcxxabi
%build
export CC=clang
export CXX=clang++
export AR=llvm-ar
export RANLIB=llvm-ranlib
# Stack protection doesn't work with this lib
%global optflags %{nil}
export CFLAGS="-O2"
BUILD_FLAGS="-DCMAKE_BUILD_TYPE=RelWithDebugInfo \
-DCMAKE_C_COMPILER_WORKS=ON \
-DCMAKE_CXX_COMPILER_WORKS=ON \
-DCMAKE_CXX_COMPILER_TARGET=wasm32-wasi \
-DCMAKE_INSTALL_PREFIX:PATH=%{wasi_sysroot}/ \
-DCMAKE_SYSROOT=%{wasi_sysroot} \
-DCMAKE_VERBOSE_MAKEFILE:BOOL=ON \
-DCMAKE_FIND_ROOT_PATH_MODE_LIBRARY=ONLY \
-DCMAKE_FIND_ROOT_PATH_MODE_INCLUDE=ONLY \
-DCMAKE_FIND_ROOT_PATH_MODE_PACKAGE=ONLY \
-DCMAKE_AR=%{_bindir}/llvm-ar \
-DCMAKE_RANLIB=%{_bindir}/llvm-ranlib \
-DCXX_SUPPORTS_CXX11=ON \
-DDEFAULT_SYSROOT=%{wasi-sysroot} \
-DLIBCXXABI_BUILD_EXTERNAL_THREAD_LIBRARY:BOOL=OFF \
-DLIBCXXABI_ENABLE_EXCEPTIONS:BOOL=OFF \
-DLIBCXXABI_SUPPORTS_FNO_EXCEPTIONS_FLAG:BOOL=ON \
-DLIBCXXABI_ENABLE_PIC:BOOL=OFF \
-DLIBCXXABI_ENABLE_SHARED:BOOL=OFF \
-DLIBCXXABI_ENABLE_THREADS:BOOL=OFF \
-DLIBCXXABI_HAS_EXTERNAL_THREAD_API:BOOL=OFF \
-DLIBCXXABI_HAS_PTHREAD_API:BOOL=OFF \
-DLIBCXXABI_HAS_WIN32_THREAD_API:BOOL=OFF \
-DLIBCXXABI_SILENT_TERMINATE:BOOL=ON \
-DLIBCXX_ABI_VERSION=2 \
-DLIBCXX_BUILD_EXTERNAL_THREAD_LIBRARY:BOOL=OFF \
-DLIBCXX_CXX_ABI_INCLUDE_PATHS=../../libcxxabi/include \
-DLIBCXX_CXX_ABI=libcxxabi \
-DLIBCXX_ENABLE_EXCEPTIONS:BOOL=OFF \
-DLIBCXX_SUPPORTS_FNO_EXCEPTIONS_FLAG:BOOL=ON \
-DLIBCXX_ENABLE_EXPERIMENTAL_LIBRARY:BOOL=OFF \
-DLIBCXX_ENABLE_FILESYSTEM:BOOL=OFF \
-DLIBCXX_ENABLE_SHARED:BOOL=OFF \
-DLIBCXX_ENABLE_THREADS:BOOL=OFF \
-DLIBCXX_HAS_EXTERNAL_THREAD_API:BOOL=OFF \
-DLIBCXX_HAS_PTHREAD_API:BOOL=OFF \
-DLIBCXX_HAS_WIN32_THREAD_API:BOOL=OFF \
-DLIBCXX_INCLUDE_BENCHMARKS:BOOL=FALSE \
-DLIBCXX_INCLUDE_TESTS:BOOL=FALSE \
-DLIBCXX_LIBDIR_SUFFIX=/wasm32-wasi \
-DLLVM_COMPILER_CHECKED=ON \
-DLLVM_DEFAULT_TARGET_TRIPLE=wasm32-wasi \
-DLLVM_TARGETS_TO_BUILD=WebAssembly \
-DUNIX:BOOL=ON"
mkdir build_libcxx
cd build_libcxx
%cmake \
$BUILD_FLAGS \
../../libcxx/
%cmake_build
# Macro above enters into a directory, so we need to go back twice
cd ../..
mkdir build_libcxxabi
cd build_libcxxabi/
%cmake \
$BUILD_FLAGS \
-DLIBCXXABI_LIBCXX_INCLUDES=../../build_libcxx/build/include/c++/v1 \
-DLIBCXXABI_LIBDIR_SUFFIX=/wasm32-wasi \
../../libcxxabi/
%cmake_build
%install
make install DESTDIR="%{buildroot}" -C build_libcxx/build
make install DESTDIR="%{buildroot}" -C build_libcxxabi/build
# OBS uses system strip and ar, which both can't handle wasm-files
export NO_BRP_AR=true
export NO_BRP_STRIP_DEBUG=true
%files
%{wasi_sysroot}/lib/wasm32-wasi/
%{wasi_sysroot}/include
%changelog