forked from clash-lang/clash-compiler
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsnapcraft.yaml
188 lines (169 loc) · 6.81 KB
/
snapcraft.yaml
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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
# README: To update Clash to a newer version, change the "version" field. Source code will
# README: be pulled from Hackage. To upgrade to a newer GHC, replace all occurrences of
# README: '8.4.3' with some newer version.
#
# To build a snap package locally run the following commands in the directory containing snapcraft.yaml.
#
# If you've never used lxd before:
#
# $ sudo snap install lxd
# $ sudo usermod -a -G lxd $USER
# $ newgrp lxd
# $ sudo lxd init
#
# Then, to build the pacakge:
#
# $ snapcraft cleanbuild --debug
#
# `lxd` ensures the snap is built using the exact (*knock on wood*) environment as is used on snapcraft.io.
#
# Instructions tested on Ubuntu Server 18.04 / Ubuntu Desktop 16.04.
#
name: clash
version: '__BASE_VERSION__.__SUB_VERSION__'
summary: Clash; A Haskell to HDL compiler
architectures: [amd64]
description: |
Clash is a functional hardware description language that borrows both its
syntax and semantics from the functional programming language Haskell.
The Clash compiler transforms these high-level descriptions to low-level
synthesizable VHDL, Verilog, or SystemVerilog.
grade: stable # must be 'stable' to release into candidate/stable channels
confinement: strict # use 'strict' once you have the right plugs and slots
apps:
clash:
command: bin/clash
plugs:
- home
clashi:
command: bin/clashi
plugs:
- home
clash-ghc:
command: bin/ghc-8.4.3
plugs:
- home
clash-ghci:
command: bin/ghci-8.4.3
plugs:
- home
clash-pkg:
command: bin/ghc-pkg-8.4.3
plugs:
- home
parts:
ghc:
source: "https://downloads.haskell.org/~ghc/8.4.3/ghc-8.4.3-x86_64-deb9-linux.tar.xz"
source-checksum: sha256/2e4f53afb872ad9c640f31aea283b3ff4c5028b65808a1920739900aef7d15c9
plugin: nil
override-build: |
if [ "$SNAPCRAFT_ARCH_TRIPLET" = "x86_64-linux-gnu" ]; then
ARCH=x86_64
else
(>&2 echo "Unsupported platform: $SNAPCRAFT_ARCH_TRIPLET. ARM could be supported if the GHC PPA would. i386 could be supported if we get Snap to download a different 'source' pacakge for GHC in the ghc part of this snap.")
exit 1
fi
clash=$SNAPCRAFT_PROJECT_NAME
mkdir -p /snap/$clash/current/opt/ghc
./configure --prefix=/snap/$clash/current/opt/ghc
make install
mkdir -p $SNAPCRAFT_PART_INSTALL/opt
rm -rf $SNAPCRAFT_PART_INSTALL/opt/ghc
mv /snap/$clash/current/opt/ghc $SNAPCRAFT_PART_INSTALL/opt/ghc
build-packages:
- python3
- build-essential
stage-packages:
- libtinfo-dev
- libtinfo5
clash:
source: .
plugin: nil
after: [ghc]
override-build: |
if [ "$SNAPCRAFT_ARCH_TRIPLET" = "x86_64-linux-gnu" ]; then
ARCH=x86_64
else
(>&2 echo "Unsupported platform: $SNAPCRAFT_ARCH_TRIPLET. ARM could be supported if the GHC PPA would. i386 could be supported if we get Snap to download a different 'source' pacakge for GHC in the ghc part of this snap.")
exit 1
fi
# Get submodules
sed -i 's/\.git//g' .gitmodules
git submodule update --init --recursive
# Install iverilog
cd /tmp
wget https://mirror.one.com/ubuntu/pool/main/r/readline/libreadline7_7.0-0ubuntu2_amd64.deb
wget -q https://mirror.one.com/ubuntu/pool/universe/i/iverilog/iverilog_10.1-0.1build1_amd64.deb
dpkg -i libreadline7_7.0-0ubuntu2_amd64.deb iverilog_10.1-0.1build1_amd64.deb
cd -
# For debugging purposes it's nice for this snap to be able to have an arbitrary name
clash=$SNAPCRAFT_PROJECT_NAME
# Install GHC and Cabal from PPA
add-apt-repository ppa:hvr/ghc -yu
apt install ghc-8.4.3 cabal-install-2.4 -y
# Compile in /snap
mkdir -p /snap/$clash/current/opt/clash/src
mount -o bind . /snap/$clash/current/opt/clash/src
cd /snap/$clash/current/opt/clash/src
# Compile Clash and dependencies
HOME=$(realpath ..) /opt/ghc/bin/cabal --http-transport=wget new-update
HOME=$(realpath ..) /opt/ghc/bin/cabal --http-transport=wget new-build --dependencies-only --enable-relocatable --with-compiler=/opt/ghc/bin/ghc all
HOME=$(realpath ..) /opt/ghc/bin/cabal --http-transport=wget new-build --enable-relocatable --with-compiler=/opt/ghc/bin/ghc all
# Move to opt
cd ..
umount /snap/$clash/current/opt/clash/src
mkdir -p $SNAPCRAFT_PART_INSTALL/opt/clash
rm -rf $SNAPCRAFT_PART_INSTALL/opt/clash/.cabal
mv .cabal $SNAPCRAFT_PART_INSTALL/opt/clash/.cabal
mv $SNAPCRAFT_PART_BUILD $SNAPCRAFT_PART_INSTALL/opt/clash/src
mkdir -p $SNAPCRAFT_PART_BUILD
# Create binaries
BINDIR=$SNAPCRAFT_PART_INSTALL/bin
mkdir -p $BINDIR
# Create GHC 8.4.3 links needed for Clash (TODO: patch Clash so it justs tests 'ghc')
echo '#!/bin/bash' >> $BINDIR/ghc-8.4.3
echo "exec /snap/$clash/current/opt/ghc/bin/ghc \$@" >> $BINDIR/ghc-8.4.3
chmod +x $BINDIR/ghc-8.4.3
echo '#!/bin/bash' >> $BINDIR/ghci-8.4.3
echo "exec /snap/$clash/current/opt/ghc/bin/ghci \$@" >> $BINDIR/ghci-8.4.3
chmod +x $BINDIR/ghci-8.4.3
echo '#!/bin/bash' >> $BINDIR/ghc-pkg-8.4.3
echo "exec /snap/$clash/current/opt/ghc/bin/ghc-pkg \$@" >> $BINDIR/ghc-pkg-8.4.3
chmod +x $BINDIR/ghc-pkg-8.4.3
# Create Clash binary
echo "#!/bin/bash" >> $BINDIR/clash
echo "/snap/$clash/current/opt/clash/src/dist-newstyle/build/$ARCH-linux/ghc-8.4.3/clash-ghc-*/x/clash/build/clash/clash -package-env /snap/$clash/current/opt/clash/src/.ghc.environment.$ARCH-linux-8.4.3 \$@" >> $BINDIR/clash
chmod +x $BINDIR/clash
echo "#!/bin/bash" >> $BINDIR/clashi
echo "/snap/$clash/current/opt/clash/src/dist-newstyle/build/$ARCH-linux/ghc-8.4.3/clash-ghc-*/x/clashi/build/clashi/clashi -package-env /snap/$clash/current/opt/clash/src/.ghc.environment.$ARCH-linux-8.4.3 \$@" >> $BINDIR/clashi
chmod +x $BINDIR/clashi
prime:
- -home/*
build-packages:
- sed
- dpkg
- git
- iputils-ping
- wget
- libtinfo5
- libtinfo-dev
- libgcc1
- libnuma1
- libnuma-dev
- libgmp10-dev
- build-essential
- software-properties-common
- tar
- gzip
- libc6-dev
- g++-multilib
stage-packages:
- libgcc1
- libnuma1
- gcc
- libgmp10
- libgmp-dev
- libc6-dev
- libc6
- libtinfo-dev
- libtinfo5