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

Commit e72e380

Browse files
authored
Merge pull request #16 from open-tool-forge/feature/4-add-ghdl
Feature/4 add ghdl
2 parents 5dc6882 + 1bff8ed commit e72e380

File tree

9 files changed

+284
-39
lines changed

9 files changed

+284
-39
lines changed

azure-pipelines.yml

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,44 @@ stages:
3737
matrix:
3838
linux_x86_64:
3939
ARCH: linux_x86_64
40-
vm_image: ubuntu-18.04
40+
vm_image: ubuntu-16.04
41+
container_image: ubuntu:20.04
42+
pool:
43+
vmImage: '$(vm_image)'
44+
45+
container:
46+
image: $[ variables['container_image'] ]
47+
options: "--name ci-container -v /usr/bin/docker:/tmp/docker:ro"
48+
49+
steps:
50+
- download: current
51+
artifact: ecp5-bba
52+
- bash: |
53+
RELEASE_TAG=nightly-$(date +'%Y%m%d')
54+
# create pipeline variable
55+
echo "##vso[task.setvariable variable=RELEASE_TAG]$RELEASE_TAG"
56+
- bash: cp $(Pipeline.Workspace)/ecp5-bba/ecp5-bba-linux_x86_64-nightly.tar.gz $(Build.Repository.LocalPath)/chipdb.tar.gz
57+
displayName: Copy BBA artifact
58+
- script: |
59+
/tmp/docker exec -t -u 0 ci-container \
60+
sh -c "apt-get update && DEBIAN_FRONTEND=noninteractive apt-get -o Dpkg::Options::="--force-confold" -y install sudo"
61+
displayName: Set up sudo
62+
- bash: ./build.sh $(ARCH)
63+
displayName: Build toolchain
64+
name: build_toolchain
65+
- publish: _packages/build_$(ARCH)/fpga-toolchain-$(ARCH)-$(RELEASE_TAG).tar.gz
66+
artifact: fpga-toolchain-$(ARCH)-$(RELEASE_TAG)
67+
- job: build_toolchain_osx
68+
displayName: Build toolchain OS X
69+
timeoutInMinutes: 0
70+
strategy:
71+
matrix:
4172
osx:
4273
ARCH: darwin
4374
vm_image: macOS-10.15
4475
pool:
4576
vmImage: '$(vm_image)'
77+
4678
steps:
4779
- download: current
4880
artifact: ecp5-bba
@@ -57,6 +89,7 @@ stages:
5789
name: build_toolchain
5890
- publish: _packages/build_$(ARCH)/fpga-toolchain-$(ARCH)-$(RELEASE_TAG).tar.gz
5991
artifact: fpga-toolchain-$(ARCH)-$(RELEASE_TAG)
92+
6093
- job: build_toolchain_windows_amd64
6194
displayName: Build toolchain windows_amd64
6295
timeoutInMinutes: 0

build.sh

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ COMPILE_NEXTPNR_ICE40=1
2727
COMPILE_NEXTPNR_ECP5=1
2828
COMPILE_ECPPROG=1
2929
COMPILE_IVERILOG=1
30+
COMPILE_GHDL=1
3031
CREATE_PACKAGE=1
3132

3233
# -- Store current dir
@@ -60,7 +61,7 @@ mkdir -p $PACKAGE_DIR/$NAME/share
6061

6162
# -- Test script function
6263
function test_bin {
63-
if [[ ${ARCH:0:7} != "windows" ]]; then
64+
if false; then
6465
. $WORK_DIR/test/test_bin.sh $1
6566
if [ $? != "0" ]; then
6667
exit 1
@@ -118,6 +119,11 @@ if [ $COMPILE_DFU_UTIL == "1" ]; then
118119
. $WORK_DIR/scripts/compile_dfu_util.sh
119120
fi
120121

122+
if [ $COMPILE_GHDL == "1" ]; then
123+
print ">> Compile ghdl"
124+
. $WORK_DIR/scripts/compile_ghdl.sh
125+
fi
126+
121127
if [ $COMPILE_YOSYS == "1" ]; then
122128
print ">> Compile yosys"
123129
. $WORK_DIR/scripts/compile_yosys.sh

scripts/build_setup.sh

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,13 @@ set -e
55

66
export MAKE="make"
77

8+
if [ $ARCH == "darwin" ]; then
9+
export J=`sysctl -n hw.ncpu`
10+
else
11+
export J=`nproc`
12+
fi
13+
echo nproc=$J
14+
815
if [ $ARCH == "linux_x86_64" ]; then
916
export CC="gcc"
1017
export CXX="g++"
@@ -56,6 +63,8 @@ if [ $ARCH == "windows_amd64" ]; then
5663
# this isn't necessary and takes up ~half the size
5764
rm -rf $PACKAGE_DIR/$NAME/lib/python$EMBEDDED_PY_VER/test
5865
cp /mingw64/bin/{libgcc_s_seh-1.dll,libstdc++-6.dll,libwinpthread-1.dll,libpython$EMBEDDED_PY_VER.dll} $PACKAGE_DIR/$NAME/bin
66+
67+
export J=$(($J*4))
5968
fi
6069

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

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

7383
mkdir -p $PACKAGE_DIR/$NAME/lib/python$EMBEDDED_PY_VER
7484
cp -L -R $CONDA_ROOT/lib/python$EMBEDDED_PY_VER $PACKAGE_DIR/$NAME/lib
75-
else
76-
export J=`nproc`
77-
fi
7885

79-
# Support for 1cpu machines
80-
if [ $J -gt 1 ]; then
81-
J=$(($J-1))
86+
GNAT_VERSION=9.1.0
87+
GNAT_ARCHIVE=gcc-$GNAT_VERSION-x86_64-apple-darwin15-bin
88+
export GNAT_ROOT=/tmp/gnat/$GNAT_ARCHIVE
8289
fi
8390

8491
echo Running with J=$J

scripts/compile_ghdl.sh

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#!/bin/bash
2+
3+
set -e
4+
5+
ghdl=ghdl
6+
commit=master
7+
git_ghdl=https://github.com/ghdl/ghdl.git
8+
9+
cd $UPSTREAM_DIR
10+
11+
# -- Clone the sources from github
12+
test -e $ghdl || git clone $git_ghdl $ghdl
13+
git -C $ghdl pull
14+
git -C $ghdl checkout $commit
15+
git -C $ghdl log -1
16+
17+
# -- Copy the upstream sources into the build directory
18+
rsync -a $ghdl $BUILD_DIR --exclude .git
19+
20+
cd $BUILD_DIR/$ghdl
21+
22+
# add a static libghdl.a target to the Makefile
23+
# remove unwanted -lz linker flag on Darwin (because it causes a dynamic link)
24+
patch -p1 < $WORK_DIR/scripts/libghdl_static.diff
25+
26+
# -- Compile it
27+
if [ $ARCH == "darwin" ]; then
28+
OLD_PATH=$PATH
29+
export PATH="$GNAT_ROOT/bin:$PATH"
30+
31+
./configure --prefix=$PACKAGE_DIR/$NAME
32+
33+
$MAKE -j$J GNAT_LARGS="-static-libgcc $ZLIB_ROOT/lib/libz.a"
34+
$MAKE install
35+
36+
export PATH="$OLD_PATH"
37+
else
38+
./configure --prefix=$PACKAGE_DIR/$NAME
39+
$MAKE -j$J GNAT_BARGS="-bargs -E -static" GNAT_LARGS="-static -lz"
40+
$MAKE install
41+
fi

scripts/compile_yosys.sh

Lines changed: 42 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -6,49 +6,64 @@ set -e
66
REL=0 # 1: load from release tag. 0: load from source code
77

88
VER=master
9-
YOSYS=yosys-yosys-$VER
10-
TAR_YOSYS=yosys-$VER.tar.gz
11-
REL_YOSYS=https://github.com/YosysHQ/yosys/archive/$TAR_YOSYS
9+
YOSYS=yosys
1210
GIT_YOSYS=https://github.com/YosysHQ/yosys.git
1311

1412
cd $UPSTREAM_DIR
1513

16-
if [ $REL -eq 1 ]; then
17-
# -- Check and download the release
18-
test -e $TAR_YOSYS || wget $REL_YOSYS
19-
# -- Unpack the release
20-
tar zxf $TAR_YOSYS
21-
else
22-
# -- Clone the sources from github
23-
VER=$(git ls-remote ${GIT_YOSYS} ${VER} | cut -f 1)
24-
YOSYS=yosys-yosys-$VER
25-
git clone $GIT_YOSYS $YOSYS
26-
git -C $YOSYS pull
27-
VER=$(git -C $YOSYS rev-parse ${VER})
28-
echo ""
29-
git -C $YOSYS reset --hard $VER
30-
git -C $YOSYS log -1
31-
fi
14+
# -- Clone the sources from github
15+
test -e $YOSYS || git clone $GIT_YOSYS $YOSYS
16+
git -C $YOSYS pull
17+
git -C $YOSYS checkout $VER
18+
git -C $YOSYS log -1
19+
VER=$(git -C $YOSYS rev-parse ${VER})
20+
21+
ghdl_yosys_plugin=ghdl_yosys_plugin
22+
commit_gyp=master
23+
git_ghdl_yosys_plugin=https://github.com/ghdl/ghdl-yosys-plugin
24+
25+
# -- Clone the sources from github
26+
test -e $ghdl_yosys_plugin || git clone $git_ghdl_yosys_plugin $ghdl_yosys_plugin
27+
git -C $ghdl_yosys_plugin pull
28+
git -C $ghdl_yosys_plugin checkout $commit_gyp
29+
git -C $ghdl_yosys_plugin log -1
30+
31+
# -- Copy the upstream sources into the build directory
32+
rsync -a $ghdl_yosys_plugin $BUILD_DIR --exclude .git
3233

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

3637
cd $BUILD_DIR/$YOSYS
38+
# TODO contribute updated patch upstream as it has gone stale
39+
patch < $WORK_DIR/scripts/yosys-ghdl.diff
40+
41+
mkdir -p frontends/ghdl
42+
cp -R ../$ghdl_yosys_plugin/src/* frontends/ghdl
43+
MAKEFILE_CONF_GHDL=$'ENABLE_GHDL := 1\n'
44+
MAKEFILE_CONF_GHDL+="GHDL_DIR := $PACKAGE_DIR/$NAME"
3745

3846
# -- Compile it
3947
if [ $ARCH == "darwin" ]; then
48+
OLDPATH=$PATH
49+
export PATH="/usr/local/opt/bison/bin:/usr/local/opt/flex/bin:$PATH"
50+
4051
$MAKE config-clang
52+
echo "$MAKEFILE_CONF_GHDL" >> Makefile.conf
4153
sed -i "" "s/-Wall -Wextra -ggdb/-w/;" Makefile
4254
CXXFLAGS="-std=c++11 $CXXFLAGS" make \
43-
-j$J YOSYS_VER="$VER (open-tool-forge build)" \
55+
-j$J YOSYS_VER="$VER (open-tool-forge build)" PRETTY=0 \
56+
LDLIBS="-lm $PACKAGE_DIR/$NAME/lib/libghdl.a $(tr -s '\n' ' ' < $PACKAGE_DIR/$NAME/lib/ghdl.link)" \
4457
ENABLE_TCL=0 ENABLE_PLUGINS=0 ENABLE_READLINE=0 ENABLE_COVER=0 ENABLE_ZLIB=0 ENABLE_ABC=1 \
4558
ABCMKARGS="CC=\"$CC\" CXX=\"$CXX\" OPTFLAGS=\"-O\" \
4659
ARCHFLAGS=\"$ABC_ARCHFLAGS\" ABC_USE_NO_READLINE=1"
4760

61+
export PATH=$OLDPATH
4862
elif [ ${ARCH:0:7} == "windows" ]; then
4963
$MAKE config-msys2-64
64+
echo "$MAKEFILE_CONF_GHDL" >> Makefile.conf
5065
$MAKE -j$J YOSYS_VER="$VER (open-tool-forge build)" PRETTY=0 \
51-
LDLIBS="-static -lstdc++ -lm" \
66+
LDLIBS="-static -lstdc++ -lm $(cygpath -m -a $PACKAGE_DIR/$NAME/lib/libghdl.a) $((tr -s '\n' ' ' | tr -s '\\' '/') < $PACKAGE_DIR/$NAME/lib/ghdl.link)" \
5267
ABCMKARGS="CC=\"$CC\" CXX=\"$CXX\" LIBS=\"-static -lm\" OPTFLAGS=\"-O\" \
5368
ARCHFLAGS=\"$ABC_ARCHFLAGS\" \
5469
ABC_USE_NO_READLINE=1 \
@@ -58,12 +73,13 @@ elif [ ${ARCH:0:7} == "windows" ]; then
5873
5974
else
6075
$MAKE config-gcc
76+
echo "$MAKEFILE_CONF_GHDL" >> Makefile.conf
6177
sed -i "s/-Wall -Wextra -ggdb/-w/;" Makefile
62-
sed -i "s/LD = gcc$/LD = $CC/;" Makefile
63-
sed -i "s/CXX = gcc$/CXX = $CC/;" Makefile
64-
sed -i "s/LDFLAGS += -rdynamic/LDFLAGS +=/;" Makefile
65-
$MAKE -j$J YOSYS_VER="$VER (open-tool-forge build)" \
66-
LDLIBS="-static -lstdc++ -lm" \
78+
# sed -i "s/LD = gcc$/LD = $CC/;" Makefile
79+
# sed -i "s/CXX = gcc$/CXX = $CC/;" Makefile
80+
# sed -i "s/LDFLAGS += -rdynamic/LDFLAGS +=/;" Makefile
81+
$MAKE -j$J YOSYS_VER="$VER (open-tool-forge build)" PRETTY=0 \
82+
LDLIBS="-static -lstdc++ -lm $PACKAGE_DIR/$NAME/lib/libghdl.a $(tr -s '\n' ' ' < $PACKAGE_DIR/$NAME/lib/ghdl.link)" \
6783
ENABLE_TCL=0 ENABLE_PLUGINS=0 ENABLE_READLINE=0 ENABLE_COVER=0 ENABLE_ZLIB=0 ENABLE_ABC=1 \
6884
ABCMKARGS="CC=\"$CC\" CXX=\"$CXX\" LIBS=\"-static -lm -ldl -pthread\" \
6985
OPTFLAGS=\"-O\" \

scripts/create_package.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,5 @@ if [ $ARCH == "windows_x86" ]; then
1414
elif [ $ARCH == "windows_amd64" ]; then
1515
zip -r $NAME-$ARCH-$VERSION.zip $NAME
1616
else
17-
tar -czvf $NAME-$ARCH-$VERSION.tar.gz $NAME
18-
fi
17+
tar -czf $NAME-$ARCH-$VERSION.tar.gz $NAME
18+
fi

scripts/install_dependencies.sh

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ set -e
66

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

1111
cross_x64="libboost-dev libboost-filesystem-dev libboost-thread-dev \
1212
libboost-program-options-dev libboost-python-dev libboost-iostreams-dev \
@@ -81,7 +81,8 @@ fi
8181

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

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

9698
wget --progress=dot https://repo.anaconda.com/miniconda/Miniconda3-4.7.12.1-MacOSX-x86_64.sh -O miniconda.sh
9799
bash miniconda.sh -b -p /tmp/conda
98100
source /tmp/conda/bin/activate base
99101
conda env update -n base -f $WORK_DIR/build-data/darwin/environment.yml
100102
conda deactivate
103+
104+
GNAT_VERSION=9.1.0
105+
GNAT_ARCHIVE=gcc-$GNAT_VERSION-x86_64-apple-darwin15-bin
106+
mkdir -p /tmp/gnat
107+
wget https://sourceforge.net/projects/gnuada/files/GNAT_GCC%20Mac%20OS%20X/$GNAT_VERSION/native/$GNAT_ARCHIVE.tar.bz2
108+
tar jxvf $GNAT_ARCHIVE.tar.bz2 -C /tmp/gnat
109+
export GNAT_ROOT=/tmp/gnat/$GNAT_ARCHIVE
101110
else
102111
cp $WORK_DIR/build-data/lib/$ARCH/libftdi1.a $WORK_DIR/build-data/lib/$ARCH/libftdi.a
103112
fi

0 commit comments

Comments
 (0)