Skip to content

Commit 6ef16c2

Browse files
committed
Address reviews
- Merge cabal.project files remove hie.yaml and update base constraint - Import `project-config` and fix compilation errors and format - Fix for CI errors - Fix type synonym - Split `Cardano.Wasm.JavaScirpt.Bridge` in two and remove obsolete functions - Add `HasCallStack` to `addSimpleTxOutImpl` - Evaluate exceptions eagerly in IO - Reorganise modules Rename build-complete so that it is not required and disable schedule Rename CI action for consistency Co-authored-by: Mateusz Galazyn <[email protected]> Add clarifying comment about disabled cache and generalise authors Move internal modules to `Internal` package Simplify folder creation in README.md Co-authored-by: Mateusz Galazyn <[email protected]> Rename `APIInfo` to `ApiInfo` Use `MonadThrow` in partial functions
1 parent 340be7b commit 6ef16c2

File tree

21 files changed

+396
-407
lines changed

21 files changed

+396
-407
lines changed

.github/bin/check-git-dependencies

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ commits () {
2323
done
2424
}
2525

26-
grep '\(^source-repository-package\|^ *location:\|^ *tag:\)' cabal.project | sed 's|^source-repository-package|-|g' | \
26+
cat cabal.project | sed '/-- WASM compilation specific/q' | grep '\(^source-repository-package\|^ *location:\|^ *tag:\)' - | sed 's|^source-repository-package|-|g' | \
2727
yq eval -P -j \
2828
> tmp/repositories.json
2929

.github/workflows/haskell-wasm.yml

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Compile to WASM
1+
name: Haskell CI (WASM)
22

33
on:
44
merge_group:
@@ -10,8 +10,8 @@ on:
1010
- master
1111
# GH caches are removed when not accessed within 7 days - this schedule runs the job every 6 days making
1212
# sure that we always have some caches on master
13-
schedule:
14-
- cron: '0 0 */6 * *'
13+
# schedule:
14+
# - cron: '0 0 */6 * *'
1515

1616
jobs:
1717
build:
@@ -68,32 +68,35 @@ jobs:
6868

6969
- name: Cabal update
7070
run: |
71-
cd cardano-wasm
7271
wasm32-wasi-cabal update
7372
7473
# A dry run `build all` operation does *NOT* downlaod anything, it just looks at the package
7574
# indices to generate an install plan.
7675
- name: Build dry run
7776
run: |
78-
cd cardano-wasm
79-
wasm32-wasi-cabal build all --dry-run
77+
wasm32-wasi-cabal build cardano-wasm --dry-run
8078
8179
# From the install plan we generate a dependency list.
8280
- name: Record dependencies
8381
id: record-deps
8482
run: |
85-
cd cardano-wasm
8683
cat dist-newstyle/cache/plan.json | jq -r '."install-plan"[] | select(.style != "local") | .id' | sort | uniq > dependencies.txt
8784
8885
- name: Store month number as environment variable used in cache version
8986
run: |
90-
cd cardano-wasm
9187
cat <<EOF >> $GITHUB_ENV
9288
MONTHNUM=$(date -u '+%m')
9389
GHC=$(ghc --numeric-version)
9490
STORE=$(wasm32-wasi-cabal path --store | tail -n 1)
9591
EOF
9692
93+
# Cache is disabled because GHA default builders are not able to build all dependencies
94+
# because they lack RAM, so having the cache expire would break the CI check.
95+
# For this reason, we are providing a build of the dependencies instead in
96+
# the "Restore cached deps" step, and we make the check not required.
97+
# When we are able to make this CI check self-sufficient, we should reenable the
98+
# caching and remove the manual restoring of cached deps.
99+
97100
# From the dependency list we restore the cached dependencies.
98101
# We use the hash of `dependencies.txt` as part of the cache key because that will be stable
99102
# until the `index-state` values in the `cabal.project` file changes.
@@ -103,15 +106,14 @@ jobs:
103106
# with:
104107
# path: |
105108
# ${{ env.STORE }}
106-
# cardano-wasm/dist-newstyle
109+
# dist-newstyle
107110
# key:
108111
# wasm-cache-${{ env.CABAL_CACHE_VERSION }}-${{ runner.os }}-${{ env.GHC }}-${{ hashFiles('cardano-wasm/dependencies.txt') }}
109112
# restore-keys: |
110113
# wasm-cache-${{ env.CABAL_CACHE_VERSION }}-${{ runner.os }}-${{ env.GHC }}-
111114

112115
- name: Restore cached deps
113116
run: |
114-
cd cardano-wasm
115117
wget "https://agrius.feralhosting.com/palas/wasm-cache/4c200033737be4736cd2a363d64c49a385937d5ea57d8e52773f65d08bbd1342.tar.bz2"
116118
tar -jxf 4c200033737be4736cd2a363d64c49a385937d5ea57d8e52773f65d08bbd1342.tar.bz2
117119
rm -fr ~/.ghc-wasm/.cabal/store/
@@ -122,8 +124,7 @@ jobs:
122124
# cache it for the next step.
123125
- name: Install dependencies
124126
run: |
125-
cd cardano-wasm
126-
wasm32-wasi-cabal build all --only-dependencies --no-semaphore -j1 --ghc-options="-j1"
127+
wasm32-wasi-cabal build cardano-wasm --only-dependencies --no-semaphore -j1 --ghc-options="-j1"
127128
128129
# Always store the cabal cache.
129130
# - name: Cache Cabal store
@@ -132,15 +133,14 @@ jobs:
132133
# with:
133134
# path: |
134135
# ${{ env.STORE }}
135-
# cardano-wasm/dist-newstyle
136+
# dist-newstyle
136137
# key:
137138
# ${{ steps.cache.outputs.cache-primary-key }}
138139

139140
# Now we build.
140141
- name: Build all
141142
run: |
142-
cd cardano-wasm
143-
wasm32-wasi-cabal build all --no-semaphore -j1 --ghc-options="-j1"
143+
wasm32-wasi-cabal build cardano-wasm --no-semaphore -j1 --ghc-options="-j1"
144144
145145
# - name: Run tests
146146
# env:
@@ -166,7 +166,7 @@ jobs:
166166
# with:
167167
# limit-access-to-actor: true
168168

169-
build-complete:
169+
wasm-builds-complete:
170170
needs: [build]
171171
if: ${{ always() }}
172172
runs-on: ubuntu-latest

cabal.project

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ index-state:
1919
packages:
2020
cardano-api
2121
cardano-api-gen
22+
cardano-wasm
2223

2324
extra-packages: Cabal, process
2425

@@ -59,3 +60,94 @@ if impl (ghc >= 9.12)
5960
-- https://github.com/kapralVV/Unique/issues/11
6061
, Unique:hashable
6162

63+
-- WASM compilation specific
64+
65+
if arch(wasm32)
66+
source-repository-package
67+
type: git
68+
location: https://github.com/amesgen/plutus.git
69+
tag: dc1edea4458d6fb794b245a26c730620265645f3
70+
subdir:
71+
plutus-core
72+
plutus-ledger-api
73+
plutus-tx
74+
--sha256: sha256-QBtLmoS54b5QMAKIDOJIM6lmRC+1leBpuGKaFc7QQos=
75+
76+
package plutus-core
77+
flags: +do-not-build-plutus-exec
78+
79+
source-repository-package
80+
type: git
81+
location: https://github.com/haskell-wasm/hs-memory.git
82+
tag: a198a76c584dc2cfdcde6b431968de92a5fed65e
83+
--sha256: sha256-LRC3L+J921+/moZS7F17vCfM/4usYy/eMR+w/mXsjeA=
84+
85+
source-repository-package
86+
type: git
87+
location: https://github.com/palas/ouroboros-network.git
88+
tag: ef3e30603e4e45dac336a085114ee22b7aa8c9ed
89+
subdir:
90+
ouroboros-network
91+
ouroboros-network-framework
92+
--sha256: sha256-+IdAmWJqzRy+erKONywtk+5YLrm63q942nZavoEA4E4=
93+
94+
source-repository-package
95+
type: git
96+
location: https://github.com/palas/criterion.git
97+
tag: dd160d2b5f051e918e72fe1957d77905682b8d6c
98+
subdir:
99+
criterion-measurement
100+
--sha256: sha256-wzEwOUTeFL0C3QnS25/3X1ue2tUuedrLqtT0h1JZW6c=
101+
102+
source-repository-package
103+
type: git
104+
location: https://github.com/palas/haskell-lmdb-mock.git
105+
tag: c8d61e6eee03ee271e7768c0576110da885aec48
106+
--sha256: sha256-+gB1MmM6qRApz1p7tFsdvKoAWDrYB4a+bJ9Djm6ieYI=
107+
108+
source-repository-package
109+
type: git
110+
location: https://github.com/palas/double-conversion.git
111+
tag: b2030245727ee56de76507fe305e3741f6ce3260
112+
--sha256: sha256-kzwHHQzHPfPnIDtnSDAom7YGSzWjr0113x0zsfI/Tb0=
113+
114+
source-repository-package
115+
type: git
116+
location: https://github.com/amesgen/cborg
117+
tag: 2dff24d241d9940c5a7f5e817fcf4c1aa4a8d4bf
118+
subdir: cborg
119+
--sha256: sha256-yuz1apKQ0EB9LtJkc/I1EEtB4oZnURMvCckvdFbT6qM=
120+
121+
source-repository-package
122+
type: git
123+
location: https://github.com/Jimbo4350/foundation.git
124+
tag: b3cb78484fe6f6ce1dfcef59e72ceccc530e86ac
125+
subdir:
126+
basement
127+
foundation
128+
--sha256: sha256-QKKHl/XocxGD7bwAoGe7VaIg9o8x4dA20j3sJOgiTBw=
129+
130+
source-repository-package
131+
type: git
132+
location: https://github.com/palas/mempack.git
133+
tag: 0211addbbbf51011e5348d3696566eb12ccbef07
134+
--sha256: sha256-iLc+foF2AM3vG6deuZ51+faI6buMkubMP75md51hMe8=
135+
136+
source-repository-package
137+
type: git
138+
location: https://github.com/haskell-wasm/network
139+
tag: ab92e48e9fdf3abe214f85fdbe5301c1280e14e9
140+
--sha256: sha256-U+ln/gbXoQZpNjZHydNa0FG/9GdJFgL1+T3+7KTzDWo=
141+
142+
package cardano-crypto-praos
143+
flags: -external-libsodium-vrf
144+
145+
package atomic-counter
146+
flags: +no-cmm
147+
148+
constraints: time installed
149+
allow-newer: time
150+
151+
package crypton
152+
ghc-options: -optc-DARGON2_NO_THREADS
153+

cardano-api/cardano-api.cabal

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ common project-config
3838
-Wunused-packages
3939

4040
common maybe-unix
41-
if !os(windows)
41+
if !(os(windows)|| arch(wasm32))
4242
build-depends: unix
4343

4444
common maybe-Win32
@@ -236,6 +236,7 @@ library
236236
Cardano.Api.IO.Internal.Base
237237
Cardano.Api.IO.Internal.Compat
238238
Cardano.Api.IO.Internal.Compat.Posix
239+
Cardano.Api.IO.Internal.Compat.Wasm
239240
Cardano.Api.IO.Internal.Compat.Win32
240241
Cardano.Api.Internal.Orphans
241242
Cardano.Api.Internal.Orphans.Misc

cardano-api/src/Cardano/Api/IO/Internal/Compat.hs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ where
1111
import Cardano.Api.Error
1212
import Cardano.Api.IO.Internal.Base
1313
import Cardano.Api.IO.Internal.Compat.Posix
14+
import Cardano.Api.IO.Internal.Compat.Wasm
1415
import Cardano.Api.IO.Internal.Compat.Win32
1516

1617
import Control.Monad.Except (ExceptT)

cardano-api/src/Cardano/Api/IO/Internal/Compat/Posix.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{-# LANGUAGE CPP #-}
22
{-# LANGUAGE ScopedTypeVariables #-}
33

4-
#if !defined(mingw32_HOST_OS)
4+
#if !defined(mingw32_HOST_OS) && !defined(wasm32_HOST_ARCH)
55
#define UNIX
66
#endif
77

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
{-# LANGUAGE CPP #-}
2+
3+
#if defined(wasm32_HOST_ARCH)
4+
#define WASM
5+
#endif
6+
7+
module Cardano.Api.IO.Internal.Compat.Wasm
8+
(
9+
#ifdef WASM
10+
checkVrfFilePermissionsImpl
11+
, handleFileForWritingWithOwnerPermissionImpl
12+
, writeSecretsImpl
13+
#endif
14+
)
15+
where
16+
17+
#ifdef WASM
18+
19+
import Cardano.Api.Error (FileError (..))
20+
import Cardano.Api.IO.Internal.Base
21+
import Control.Monad.Except (ExceptT)
22+
import Data.ByteString (ByteString)
23+
import System.IO (Handle)
24+
25+
handleFileForWritingWithOwnerPermissionImpl
26+
:: FilePath
27+
-> (Handle -> IO ())
28+
-> IO (Either (FileError e) ())
29+
handleFileForWritingWithOwnerPermissionImpl _path _f = return $ Right () -- Dummy implementation for WASM
30+
31+
writeSecretsImpl :: FilePath -> [Char] -> [Char] -> (a -> ByteString) -> [a] -> IO ()
32+
writeSecretsImpl _outDir _prefix _suffix _secretOp _xs = return () -- Dummy implementation for WASM
33+
34+
-- | Make sure the VRF private key file is readable only
35+
-- by the current process owner the node is running under.
36+
checkVrfFilePermissionsImpl
37+
:: File content direction -> ExceptT VRFPrivateKeyFilePermissionError IO ()
38+
checkVrfFilePermissionsImpl _vrfPrivKeyFile = return () -- Dummy implementation for WASM
39+
40+
#endif

cardano-wasm/README.md

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# cardano-wasm
22

3-
Part of an effort at IOG (@Jimbo4350, @palas, and @amesgen) to build Cardano Haskell libraries to Wasm.
3+
Part of an effort at IOG to build Cardano Haskell libraries to Wasm.
44

55
## Building the wasm module
66

@@ -45,9 +45,7 @@ Then we need to compile three libraries to WASM: `libblst`, `libsodium`, and `li
4545
In order to not interfere with the system library installation, we will create a folder to serve as our prefix:
4646

4747
```console
48-
mkdir ~/prefix
49-
mkdir ~/prefix/{lib,include}
50-
mkdir ~/prefix/lib/pkgconfig
48+
mkdir -p ~/prefix/{lib/pkgconfig,include}
5149
```
5250

5351
#### Installing `libblst`

0 commit comments

Comments
 (0)