fayalite-deps/build-container.sh
Jacob Lifshay e352a82e9b
Some checks failed
/ podman-rootless-build (push) Has been cancelled
/ build (push) Failing after 25s
WIP creating build script
2025-10-13 19:54:00 -07:00

180 lines
No EOL
5.7 KiB
Bash
Executable file

#!/bin/bash
# SPDX-License-Identifier: LGPL-3.0-or-later
# See Notices.txt for copyright information
set -e
function build_in_container()
{
if [[ "$0" != "/build.sh" ]]; then
echo "you shouldn't run this outside of the container being built" >&2
return 1
fi
set -xe
mkdir -p /build
cd /build
update-ccache-symlinks # ccache seems to miss cc/c++ when installing, try to fix that here
export PATH="/usr/lib/ccache:$PATH"
python3 -m venv /opt/fayalite-deps/venv
source /opt/fayalite-deps/venv/bin/activate
git clone --depth=1 --recursive --branch=0.45 https://git.libre-chip.org/mirrors/yosys /build/yosys
cd /build/yosys
make -j"$(nproc)" PRETTY=0
make install
pip install click==8.1.3
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --default-toolchain 1.89.0
source "$HOME/.cargo/env"
rustup component add rust-src
git clone https://github.com/SymbiFlow/prjxray.git /build/prjxray
cd /build/prjxray
git checkout c9f02d8576042325425824647ab5555b1bc77833
git submodule update --init --recursive
mkdir -p build
cd build
cmake ..
make -j$(nproc)
make install
cd ..
sed -i 's/-e //' requirements.txt
pip install -r requirements.txt
git clone https://github.com/openXC7/prjxray-db.git /opt/fayalite-deps/prjxray-db
cd /opt/fayalite-deps/prjxray-db
git checkout 381966a746cb4cf4a7f854f0e53caa3bf74fbe62
git clone https://github.com/chipsalliance/f4pga-xc-fasm.git /build/f4pga-xc-fasm
cd /build/f4pga-xc-fasm
git checkout 25dc605c9c0896204f0c3425b52a332034cf5e5c
pip install .
git clone https://github.com/openXC7/nextpnr-xilinx.git /build/nextpnr-xilinx
cd /build/nextpnr-xilinx
git checkout 724db28b41e68568690a5ea1dd9ce5082362bb91
git submodule update --init --recursive
mkdir -p build
cd build
cmake -DARCH=xilinx -DUSE_OPENMP=ON -DBUILD_GUI=OFF ..
make -j$(nproc)
make install
install bbasm /usr/local/bin/
cd /build
wget -O firrtl.tar.gz https://github.com/llvm/circt/releases/download/firtool-1.86.0/firrtl-bin-linux-x64.tar.gz
sha256sum -c - <<<'bf6f4ab18ae76f135c944efbd81e25391c31c1bd0617c58ab0592640abefee14 firrtl.tar.gz'
tar -xvaf firrtl.tar.gz
install firtool-1.86.0/bin/firtool /usr/local/bin/
git clone --depth=1 --branch=yosys-0.45 https://git.libre-chip.org/mirrors/sby /build/sby
cd /build/sby
make install
git clone --depth=1 --recursive --branch=z3-4.13.3 https://git.libre-chip.org/mirrors/z3 /build/z3
cd /build/z3
PYTHON=python3 ./configure --prefix=/usr/local
cd build
make -j"$(nproc)"
make install
# get rid of caches and stuff
rm -rf \
/build \
/var/lib/apt/lists/*Packages* \
/var/lib/apt/lists/*Release* \
/var/lib/apt/lists/lock \
/etc/apt/apt.conf.d/01autoremove-kernels \
/var/log/apt/history.log \
/var/log/apt/term.log \
/var/lib/systemd/catalog/database
}
function prepare_mounts()
{
mount --rbind /proc build/rootfs/proc
mount --rbind /dev build/rootfs/dev
mount --rbind /sys build/rootfs/sys
mount --rbind .cache/.ccache build/rootfs/root/.ccache
mount --rbind .cache/.cache build/rootfs/root/.cache
mount --rbind .cache/apt build/rootfs/var/cache/apt
exec chroot build/rootfs /build.sh --build-in-container
}
function build_container()
{
rm -rf build-container/ build/
skopeo copy docker://debian:12 oci:build-container:latest
umoci unpack --rootless --image=build-container:latest build
cp "$0" build/rootfs/build.sh
mkdir -p .cache/.ccache
mkdir -p .cache/.cache
mkdir -p .cache/apt
mv build/rootfs/var/cache/apt build/rootfs/var/cache/apt_old
mkdir -p build/rootfs/root/.ccache
mkdir -p build/rootfs/root/.cache
mkdir -p build/rootfs/var/cache/apt
# ln -s "$(realpath .cache/.ccache)" build/rootfs/root/.ccache
# ln -s "$(realpath .cache/.cache)" build/rootfs/root/.cache
# ln -s "$(realpath .cache/apt)" build/rootfs/var/cache/apt
mv build/rootfs/etc/apt/apt.conf.d/docker-clean build/rootfs/etc/apt/
fakechroot fakeroot chroot build/rootfs apt-get -qq update
fakechroot fakeroot chroot build/rootfs apt-get -qq install \
bison \
build-essential \
ccache \
clang \
cmake \
curl \
cvc5 \
default-jre-headless \
flex \
g++ \
gawk \
git \
libantlr4-runtime-dev \
libboost-filesystem-dev \
libboost-iostreams-dev \
libboost-program-options-dev \
libboost-python-dev \
libboost-system-dev \
libboost-thread-dev \
libeigen3-dev \
libffi-dev \
libreadline-dev \
lld \
openfpgaloader \
pkg-config \
python3 \
python3-click \
python3-venv \
tcl-dev \
uuid-dev \
wget \
zlib1g-dev
unshare -fr --user --mount --kill-child --keep-caps \
env -i \
"PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin" \
"TERM=xterm" \
"HOME=/root" \
"CCACHE_COMPILERCHECK=content" \
bash build/rootfs/build.sh --prepare-mounts < /dev/null
mv build/rootfs/etc/apt/docker-clean build/rootfs/etc/apt/apt.conf.d/
rm build/rootfs/root/.ccache build/rootfs/root/.cache build/rootfs/var/cache/apt
mv build/rootfs/var/cache/apt_old build/rootfs/var/cache/apt
rm build/rootfs/build.sh
umoci repack --image=build-container:latest build
rm -rf build
echo "built oci container is in ./build-container:latest"
}
if [[ "$*" == "--build-in-container" ]]; then
build_in_container
elif [[ "$*" == "--prepare-mounts" ]]; then
prepare_mounts
else
build_container
fi