Skip to content
This repository has been archived by the owner on Nov 4, 2021. It is now read-only.

Commit

Permalink
Merge pull request #16 from open-tool-forge/feature/4-add-ghdl
Browse files Browse the repository at this point in the history
Feature/4 add ghdl
  • Loading branch information
edbordin authored May 18, 2020
2 parents 5dc6882 + 1bff8ed commit e72e380
Show file tree
Hide file tree
Showing 9 changed files with 284 additions and 39 deletions.
35 changes: 34 additions & 1 deletion azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,44 @@ stages:
matrix:
linux_x86_64:
ARCH: linux_x86_64
vm_image: ubuntu-18.04
vm_image: ubuntu-16.04
container_image: ubuntu:20.04
pool:
vmImage: '$(vm_image)'

container:
image: $[ variables['container_image'] ]
options: "--name ci-container -v /usr/bin/docker:/tmp/docker:ro"

steps:
- download: current
artifact: ecp5-bba
- bash: |
RELEASE_TAG=nightly-$(date +'%Y%m%d')
# create pipeline variable
echo "##vso[task.setvariable variable=RELEASE_TAG]$RELEASE_TAG"
- bash: cp $(Pipeline.Workspace)/ecp5-bba/ecp5-bba-linux_x86_64-nightly.tar.gz $(Build.Repository.LocalPath)/chipdb.tar.gz
displayName: Copy BBA artifact
- script: |
/tmp/docker exec -t -u 0 ci-container \
sh -c "apt-get update && DEBIAN_FRONTEND=noninteractive apt-get -o Dpkg::Options::="--force-confold" -y install sudo"
displayName: Set up sudo
- bash: ./build.sh $(ARCH)
displayName: Build toolchain
name: build_toolchain
- publish: _packages/build_$(ARCH)/fpga-toolchain-$(ARCH)-$(RELEASE_TAG).tar.gz
artifact: fpga-toolchain-$(ARCH)-$(RELEASE_TAG)
- job: build_toolchain_osx
displayName: Build toolchain OS X
timeoutInMinutes: 0
strategy:
matrix:
osx:
ARCH: darwin
vm_image: macOS-10.15
pool:
vmImage: '$(vm_image)'

steps:
- download: current
artifact: ecp5-bba
Expand All @@ -57,6 +89,7 @@ stages:
name: build_toolchain
- publish: _packages/build_$(ARCH)/fpga-toolchain-$(ARCH)-$(RELEASE_TAG).tar.gz
artifact: fpga-toolchain-$(ARCH)-$(RELEASE_TAG)

- job: build_toolchain_windows_amd64
displayName: Build toolchain windows_amd64
timeoutInMinutes: 0
Expand Down
8 changes: 7 additions & 1 deletion build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ COMPILE_NEXTPNR_ICE40=1
COMPILE_NEXTPNR_ECP5=1
COMPILE_ECPPROG=1
COMPILE_IVERILOG=1
COMPILE_GHDL=1
CREATE_PACKAGE=1

# -- Store current dir
Expand Down Expand Up @@ -60,7 +61,7 @@ mkdir -p $PACKAGE_DIR/$NAME/share

# -- Test script function
function test_bin {
if [[ ${ARCH:0:7} != "windows" ]]; then
if false; then
. $WORK_DIR/test/test_bin.sh $1
if [ $? != "0" ]; then
exit 1
Expand Down Expand Up @@ -118,6 +119,11 @@ if [ $COMPILE_DFU_UTIL == "1" ]; then
. $WORK_DIR/scripts/compile_dfu_util.sh
fi

if [ $COMPILE_GHDL == "1" ]; then
print ">> Compile ghdl"
. $WORK_DIR/scripts/compile_ghdl.sh
fi

if [ $COMPILE_YOSYS == "1" ]; then
print ">> Compile yosys"
. $WORK_DIR/scripts/compile_yosys.sh
Expand Down
19 changes: 13 additions & 6 deletions scripts/build_setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@ set -e

export MAKE="make"

if [ $ARCH == "darwin" ]; then
export J=`sysctl -n hw.ncpu`
else
export J=`nproc`
fi
echo nproc=$J

if [ $ARCH == "linux_x86_64" ]; then
export CC="gcc"
export CXX="g++"
Expand Down Expand Up @@ -56,6 +63,8 @@ if [ $ARCH == "windows_amd64" ]; then
# this isn't necessary and takes up ~half the size
rm -rf $PACKAGE_DIR/$NAME/lib/python$EMBEDDED_PY_VER/test
cp /mingw64/bin/{libgcc_s_seh-1.dll,libstdc++-6.dll,libwinpthread-1.dll,libpython$EMBEDDED_PY_VER.dll} $PACKAGE_DIR/$NAME/bin

export J=$(($J*4))
fi

if [ $ARCH == "darwin" ]; then
Expand All @@ -67,18 +76,16 @@ if [ $ARCH == "darwin" ]; then

export LIBFTDI_ROOT=$(brew --cellar libftdi)/$(brew list --versions libftdi | tr ' ' '\n' | tail -1)
export LIBUSB_ROOT=$(brew --cellar libusb)/$(brew list --versions libusb | tr ' ' '\n' | tail -1)
export ZLIB_ROOT=$(brew --cellar zlib)/$(brew list --versions zlib | tr ' ' '\n' | tail -1)
export CONDA_ROOT=/tmp/conda
export EMBEDDED_PY_VER=$($CONDA_ROOT/bin/python -c 'import sys; print(str(sys.version_info[0])+"."+str(sys.version_info[1]))')

mkdir -p $PACKAGE_DIR/$NAME/lib/python$EMBEDDED_PY_VER
cp -L -R $CONDA_ROOT/lib/python$EMBEDDED_PY_VER $PACKAGE_DIR/$NAME/lib
else
export J=`nproc`
fi

# Support for 1cpu machines
if [ $J -gt 1 ]; then
J=$(($J-1))
GNAT_VERSION=9.1.0
GNAT_ARCHIVE=gcc-$GNAT_VERSION-x86_64-apple-darwin15-bin
export GNAT_ROOT=/tmp/gnat/$GNAT_ARCHIVE
fi

echo Running with J=$J
41 changes: 41 additions & 0 deletions scripts/compile_ghdl.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#!/bin/bash

set -e

ghdl=ghdl
commit=master
git_ghdl=https://github.com/ghdl/ghdl.git

cd $UPSTREAM_DIR

# -- Clone the sources from github
test -e $ghdl || git clone $git_ghdl $ghdl
git -C $ghdl pull
git -C $ghdl checkout $commit
git -C $ghdl log -1

# -- Copy the upstream sources into the build directory
rsync -a $ghdl $BUILD_DIR --exclude .git

cd $BUILD_DIR/$ghdl

# add a static libghdl.a target to the Makefile
# remove unwanted -lz linker flag on Darwin (because it causes a dynamic link)
patch -p1 < $WORK_DIR/scripts/libghdl_static.diff

# -- Compile it
if [ $ARCH == "darwin" ]; then
OLD_PATH=$PATH
export PATH="$GNAT_ROOT/bin:$PATH"

./configure --prefix=$PACKAGE_DIR/$NAME

$MAKE -j$J GNAT_LARGS="-static-libgcc $ZLIB_ROOT/lib/libz.a"
$MAKE install

export PATH="$OLD_PATH"
else
./configure --prefix=$PACKAGE_DIR/$NAME
$MAKE -j$J GNAT_BARGS="-bargs -E -static" GNAT_LARGS="-static -lz"
$MAKE install
fi
68 changes: 42 additions & 26 deletions scripts/compile_yosys.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,49 +6,64 @@ set -e
REL=0 # 1: load from release tag. 0: load from source code

VER=master
YOSYS=yosys-yosys-$VER
TAR_YOSYS=yosys-$VER.tar.gz
REL_YOSYS=https://github.com/YosysHQ/yosys/archive/$TAR_YOSYS
YOSYS=yosys
GIT_YOSYS=https://github.com/YosysHQ/yosys.git

cd $UPSTREAM_DIR

if [ $REL -eq 1 ]; then
# -- Check and download the release
test -e $TAR_YOSYS || wget $REL_YOSYS
# -- Unpack the release
tar zxf $TAR_YOSYS
else
# -- Clone the sources from github
VER=$(git ls-remote ${GIT_YOSYS} ${VER} | cut -f 1)
YOSYS=yosys-yosys-$VER
git clone $GIT_YOSYS $YOSYS
git -C $YOSYS pull
VER=$(git -C $YOSYS rev-parse ${VER})
echo ""
git -C $YOSYS reset --hard $VER
git -C $YOSYS log -1
fi
# -- Clone the sources from github
test -e $YOSYS || git clone $GIT_YOSYS $YOSYS
git -C $YOSYS pull
git -C $YOSYS checkout $VER
git -C $YOSYS log -1
VER=$(git -C $YOSYS rev-parse ${VER})

ghdl_yosys_plugin=ghdl_yosys_plugin
commit_gyp=master
git_ghdl_yosys_plugin=https://github.com/ghdl/ghdl-yosys-plugin

# -- Clone the sources from github
test -e $ghdl_yosys_plugin || git clone $git_ghdl_yosys_plugin $ghdl_yosys_plugin
git -C $ghdl_yosys_plugin pull
git -C $ghdl_yosys_plugin checkout $commit_gyp
git -C $ghdl_yosys_plugin log -1

# -- Copy the upstream sources into the build directory
rsync -a $ghdl_yosys_plugin $BUILD_DIR --exclude .git

# -- Copy the upstream sources into the build directory
rsync -a $YOSYS $BUILD_DIR --exclude .git

cd $BUILD_DIR/$YOSYS
# TODO contribute updated patch upstream as it has gone stale
patch < $WORK_DIR/scripts/yosys-ghdl.diff

mkdir -p frontends/ghdl
cp -R ../$ghdl_yosys_plugin/src/* frontends/ghdl
MAKEFILE_CONF_GHDL=$'ENABLE_GHDL := 1\n'
MAKEFILE_CONF_GHDL+="GHDL_DIR := $PACKAGE_DIR/$NAME"

# -- Compile it
if [ $ARCH == "darwin" ]; then
OLDPATH=$PATH
export PATH="/usr/local/opt/bison/bin:/usr/local/opt/flex/bin:$PATH"

$MAKE config-clang
echo "$MAKEFILE_CONF_GHDL" >> Makefile.conf
sed -i "" "s/-Wall -Wextra -ggdb/-w/;" Makefile
CXXFLAGS="-std=c++11 $CXXFLAGS" make \
-j$J YOSYS_VER="$VER (open-tool-forge build)" \
-j$J YOSYS_VER="$VER (open-tool-forge build)" PRETTY=0 \
LDLIBS="-lm $PACKAGE_DIR/$NAME/lib/libghdl.a $(tr -s '\n' ' ' < $PACKAGE_DIR/$NAME/lib/ghdl.link)" \
ENABLE_TCL=0 ENABLE_PLUGINS=0 ENABLE_READLINE=0 ENABLE_COVER=0 ENABLE_ZLIB=0 ENABLE_ABC=1 \
ABCMKARGS="CC=\"$CC\" CXX=\"$CXX\" OPTFLAGS=\"-O\" \
ARCHFLAGS=\"$ABC_ARCHFLAGS\" ABC_USE_NO_READLINE=1"

export PATH=$OLDPATH
elif [ ${ARCH:0:7} == "windows" ]; then
$MAKE config-msys2-64
echo "$MAKEFILE_CONF_GHDL" >> Makefile.conf
$MAKE -j$J YOSYS_VER="$VER (open-tool-forge build)" PRETTY=0 \
LDLIBS="-static -lstdc++ -lm" \
LDLIBS="-static -lstdc++ -lm $(cygpath -m -a $PACKAGE_DIR/$NAME/lib/libghdl.a) $((tr -s '\n' ' ' | tr -s '\\' '/') < $PACKAGE_DIR/$NAME/lib/ghdl.link)" \
ABCMKARGS="CC=\"$CC\" CXX=\"$CXX\" LIBS=\"-static -lm\" OPTFLAGS=\"-O\" \
ARCHFLAGS=\"$ABC_ARCHFLAGS\" \
ABC_USE_NO_READLINE=1 \
Expand All @@ -58,12 +73,13 @@ elif [ ${ARCH:0:7} == "windows" ]; then
else
$MAKE config-gcc
echo "$MAKEFILE_CONF_GHDL" >> Makefile.conf
sed -i "s/-Wall -Wextra -ggdb/-w/;" Makefile
sed -i "s/LD = gcc$/LD = $CC/;" Makefile
sed -i "s/CXX = gcc$/CXX = $CC/;" Makefile
sed -i "s/LDFLAGS += -rdynamic/LDFLAGS +=/;" Makefile
$MAKE -j$J YOSYS_VER="$VER (open-tool-forge build)" \
LDLIBS="-static -lstdc++ -lm" \
# sed -i "s/LD = gcc$/LD = $CC/;" Makefile
# sed -i "s/CXX = gcc$/CXX = $CC/;" Makefile
# sed -i "s/LDFLAGS += -rdynamic/LDFLAGS +=/;" Makefile
$MAKE -j$J YOSYS_VER="$VER (open-tool-forge build)" PRETTY=0 \
LDLIBS="-static -lstdc++ -lm $PACKAGE_DIR/$NAME/lib/libghdl.a $(tr -s '\n' ' ' < $PACKAGE_DIR/$NAME/lib/ghdl.link)" \
ENABLE_TCL=0 ENABLE_PLUGINS=0 ENABLE_READLINE=0 ENABLE_COVER=0 ENABLE_ZLIB=0 ENABLE_ABC=1 \
ABCMKARGS="CC=\"$CC\" CXX=\"$CXX\" LIBS=\"-static -lm -ldl -pthread\" \
OPTFLAGS=\"-O\" \
Expand Down
4 changes: 2 additions & 2 deletions scripts/create_package.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@ if [ $ARCH == "windows_x86" ]; then
elif [ $ARCH == "windows_amd64" ]; then
zip -r $NAME-$ARCH-$VERSION.zip $NAME
else
tar -czvf $NAME-$ARCH-$VERSION.tar.gz $NAME
fi
tar -czf $NAME-$ARCH-$VERSION.tar.gz $NAME
fi
15 changes: 12 additions & 3 deletions scripts/install_dependencies.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ set -e

base_packages="build-essential bison flex libreadline-dev \
gawk tcl-dev libffi-dev git rsync \
pkg-config python3 cmake autotools-dev automake gperf"
pkg-config python3 cmake autotools-dev automake gperf gnat"

cross_x64="libboost-dev libboost-filesystem-dev libboost-thread-dev \
libboost-program-options-dev libboost-python-dev libboost-iostreams-dev \
Expand Down Expand Up @@ -81,7 +81,8 @@ fi

if [ $ARCH == "windows_amd64" ]; then
pacman --noconfirm --needed -S git base-devel mingw-w64-x86_64-toolchain mingw-w64-x86_64-cmake \
mingw-w64-x86_64-boost mingw-w64-x86_64-eigen3 rsync unzip zip mingw-w64-x86_64-libftdi bison flex
mingw-w64-x86_64-boost mingw-w64-x86_64-eigen3 rsync unzip zip mingw-w64-x86_64-libftdi bison flex \
mingw-w64-x86_64-gcc-ada

x86_64-w64-mingw32-gcc --version
x86_64-w64-mingw32-g++ --version
Expand All @@ -91,13 +92,21 @@ if [ $ARCH == "darwin" ]; then
sudo xcode-select -s /Applications/Xcode_11.4.1.app/Contents/Developer
# yosys detects some of these tools if a homebrew version is installed
# so we may not need to add all of them to PATH
brew install automake pkg-config bison flex gawk libffi git graphviz xdot bash cmake boost boost-python3 eigen libftdi libusb
brew install automake pkg-config bison flex gawk libffi git graphviz xdot bash cmake boost boost-python3 eigen \
libftdi libusb zlib

wget --progress=dot https://repo.anaconda.com/miniconda/Miniconda3-4.7.12.1-MacOSX-x86_64.sh -O miniconda.sh
bash miniconda.sh -b -p /tmp/conda
source /tmp/conda/bin/activate base
conda env update -n base -f $WORK_DIR/build-data/darwin/environment.yml
conda deactivate

GNAT_VERSION=9.1.0
GNAT_ARCHIVE=gcc-$GNAT_VERSION-x86_64-apple-darwin15-bin
mkdir -p /tmp/gnat
wget https://sourceforge.net/projects/gnuada/files/GNAT_GCC%20Mac%20OS%20X/$GNAT_VERSION/native/$GNAT_ARCHIVE.tar.bz2
tar jxvf $GNAT_ARCHIVE.tar.bz2 -C /tmp/gnat
export GNAT_ROOT=/tmp/gnat/$GNAT_ARCHIVE
else
cp $WORK_DIR/build-data/lib/$ARCH/libftdi1.a $WORK_DIR/build-data/lib/$ARCH/libftdi.a
fi
Loading

0 comments on commit e72e380

Please sign in to comment.