-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathbuild.sh
executable file
·145 lines (122 loc) · 5.33 KB
/
build.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
#!/bin/sh -ex
export SOURCE_DATE_EPOCH=$(git log -1 --format=%ct)
PYTHON=$(which ${PYTHON:-python})
WASI_SDK=wasi-sdk-22.0
WASI_SDK_URL=https://github.com/WebAssembly/wasi-sdk/releases/download/wasi-sdk-22/wasi-sdk-22.0-linux.tar.gz
if ! [ -d ${WASI_SDK} ]; then curl -L ${WASI_SDK_URL} | tar xzf -; fi
WASI_SDK_PATH=$(pwd)/${WASI_SDK}
BOOST=boost-1.81.0
BOOST_URL=https://github.com/boostorg/boost/releases/download/boost-1.81.0/boost-1.81.0.tar.gz
if ! [ -d ${BOOST} ]; then curl -L ${BOOST_URL} | tar xzf -; fi
EIGEN=eigen-3.4.0
EIGEN_URL=https://gitlab.com/libeigen/eigen/-/archive/3.4.0/eigen-3.4.0.tar.gz
if ! [ -d ${EIGEN} ]; then curl -L ${EIGEN_URL} | tar xzf -; fi
# Threading is currently experimental.
WASI_TARGET="wasm32-wasi"
WASI_SYSROOT="--sysroot ${WASI_SDK_PATH}/share/wasi-sysroot"
WASI_CFLAGS="-flto"
WASI_LDFLAGS="-flto -Wl,--strip-all"
BOOST_THREADING="single"
BOOST_ADD_CXXFLAGS="-DBOOST_NO_CXX11_HDR_MUTEX"
BOOST_ADD_LIBRARIES=""
if [ ${THREADS:-0} -ne 0 ]; then
WASI_TARGET="${WASI_TARGET}-threads"
WASI_CFLAGS="${WASI_CFLAGS} -pthread"
WASI_LDFLAGS="${WASI_LDFLAGS} -Wl,--import-memory,--export-memory,--max-memory=4294967296"
BOOST_THREADING="multi"
BOOST_ADD_CXXFLAGS=""
BOOST_ADD_LIBRARIES="--with-thread"
fi
cat >Toolchain-WASI.cmake <<END
cmake_minimum_required(VERSION 3.4...3.31)
set(WASI TRUE)
set(CMAKE_SYSTEM_NAME Generic)
set(CMAKE_SYSTEM_VERSION 1)
set(CMAKE_SYSTEM_PROCESSOR wasm32)
set(CMAKE_C_COMPILER ccache ${WASI_SDK_PATH}/bin/clang)
set(CMAKE_CXX_COMPILER ccache ${WASI_SDK_PATH}/bin/clang++)
set(CMAKE_LINKER ${WASI_SDK_PATH}/bin/wasm-ld CACHE STRING "wasienv build")
set(CMAKE_AR ${WASI_SDK_PATH}/bin/ar CACHE STRING "wasienv build")
set(CMAKE_RANLIB ${WASI_SDK_PATH}/bin/ranlib CACHE STRING "wasienv build")
set(CMAKE_C_COMPILER_TARGET ${WASI_TARGET})
set(CMAKE_CXX_COMPILER_TARGET ${WASI_TARGET})
set(CMAKE_C_FLAGS "${WASI_SYSROOT} ${WASI_CFLAGS}" CACHE STRING "wasienv build")
set(CMAKE_CXX_FLAGS "${WASI_SYSROOT} ${WASI_CFLAGS}" CACHE STRING "wasienv build")
set(CMAKE_EXE_LINKER_FLAGS "${WASI_LDFLAGS}" CACHE STRING "wasienv build")
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)
END
if ! [ -f ${BOOST}/tools/build/src/engine/b2 ]; then
(cd ${BOOST}/tools/build/src/engine && ./build.sh);
fi
cat >${BOOST}/project-config.jam <<END
using clang : : ccache clang++ --target=${WASI_TARGET} ${WASI_SYSROOT} ${WASI_CFLAGS} -D_WASI_EMULATED_MMAN -DBOOST_NO_EXCEPTIONS ${BOOST_ADD_CXXFLAGS} ;
project : default-build <toolset>clang ;
libraries = --with-program_options --with-iostreams --with-filesystem --with-system ${BOOST_ADD_LIBRARIES} ;
END
(cd ${BOOST} && PATH=${WASI_SDK_PATH}/bin:$PATH ./tools/build/src/engine/b2 threading=${BOOST_THREADING} link=static stage)
cmake -B eigen-build -S ${EIGEN} -DCMAKE_INSTALL_PREFIX=$(pwd)/eigen-prefix
make -C eigen-build install
make -C icestorm-src EXE=".wasm" \
CXX="ccache ${WASI_SDK_PATH}/bin/clang++" \
CXXFLAGS="--target=${WASI_TARGET} ${WASI_SYSROOT} ${WASI_CFLAGS} -fno-exceptions" \
LDFLAGS="--target=${WASI_TARGET} ${WASI_SYSROOT} ${WASI_LDFLAGS}" \
SUBDIRS="icebox icepack icemulti icepll icebram" \
PREFIX="" DESTDIR=$(pwd)/icestorm-prefix \
install
cp icestorm-src/icefuzz/timings_*.txt $(pwd)/icestorm-prefix/share/icebox/
cmake -B prjtrellis-build -S prjtrellis-src/libtrellis \
-DCMAKE_TOOLCHAIN_FILE=../Toolchain-WASI.cmake \
-DCMAKE_PREFIX_PATH=$(pwd)/${BOOST}/stage/ \
-DBOOST_ROOT=$(pwd)/${BOOST} \
-DSTATIC_BUILD=ON \
-DBUILD_SHARED=OFF \
-DBUILD_PYTHON=OFF
cmake --build prjtrellis-build
cmake -B libtrellis-build -S prjtrellis-src/libtrellis \
-DCMAKE_INSTALL_PREFIX=$(pwd)/libtrellis-prefix \
-DPython3_EXECUTABLE=${PYTHON} \
-DBUILD_ECPBRAM=OFF \
-DBUILD_ECPPACK=OFF \
-DBUILD_ECPUNPACK=OFF \
-DBUILD_ECPPLL=OFF \
-DBUILD_ECPMULTI=OFF
make -C libtrellis-build install
# Rustc doesn't yet implement wasm32-wasi-threads; see:
# https://github.com/rust-lang/compiler-team/issues/574
cargo build --target-dir prjoxide-build \
--manifest-path prjoxide-src/libprjoxide/prjoxide/Cargo.toml \
--target wasm32-wasip1 \
--release
cargo install --target-dir prjoxide-build \
--path prjoxide-src/libprjoxide/prjoxide \
--root prjoxide-prefix
cmake -B nextpnr-bba-build -S nextpnr-src/bba
cmake --build nextpnr-bba-build
${PYTHON} -m venv apycula-prefix
./apycula-prefix/bin/pip install -r apycula-meta/requirements.txt
mkdir -p nextpnr-build
cmake -B nextpnr-build -S nextpnr-src \
-DCMAKE_TOOLCHAIN_FILE=../Toolchain-WASI.cmake \
-DCMAKE_PREFIX_PATH=$(pwd)/${BOOST}/stage/ \
-DCMAKE_CXX_COMPILER_LAUNCHER=ccache \
-DPython3_EXECUTABLE=${PYTHON} \
-DSTATIC_BUILD=ON \
-DBOOST_ROOT=$(pwd)/${BOOST} \
-DEigen3_DIR=$(pwd)/eigen-prefix/share/eigen3/cmake \
-DBBA_IMPORT=$(pwd)/nextpnr-bba-build/bba-export.cmake \
-DBUILD_GUI=OFF \
-DBUILD_PYTHON=OFF \
-DEXTERNAL_CHIPDB=ON \
-DEXTERNAL_CHIPDB_ROOT=/share \
-DARCH="ice40;ecp5;machxo2;nexus;gowin;himbaechel" \
-DHIMBAECHEL_SPLIT=ON \
-DHIMBAECHEL_UARCH="gowin" \
-DICESTORM_INSTALL_PREFIX=$(pwd)/icestorm-prefix \
-DTRELLIS_INSTALL_PREFIX=$(pwd)/libtrellis-prefix \
-DOXIDE_INSTALL_PREFIX=$(pwd)/prjoxide-prefix \
-DGOWIN_BBA_EXECUTABLE=$(pwd)/apycula-prefix/bin/gowin_bba \
-DAPYCULA_INSTALL_PREFIX=$(pwd)/apycula-prefix
cmake --build nextpnr-build