How to build a basic project?
dboreham opened this issue · 5 comments
Apologies if there's a tutorial somewhere I've missed (happy to put one together if that'd help):
I'm attempting to get a basic project working (along the lines of the hilbert article example, or actually it could be exactly the hilbert example).
I've successfully built asterius from source, bootstrapped, and I can compile/run-in-node.js a single source file hello world program, so to a first approximation my environment is working:
david@localhost:~/projects/asterius/example/hello (master)$ stack exec ahc-link -- --input-hs Hello.hs --run
[INFO] Compiling Hello.hs to WebAssembly
[INFO] Converting linked IR to binaryen IR
[INFO] Running binaryen optimization
[INFO] Validating binaryen IR
[INFO] Writing WebAssembly binary to "./Hello.wasm"
[INFO] Writing JavaScript runtime modules to "."
[INFO] Writing JavaScript loader module to "./Hello.wasm.mjs"
[INFO] Writing JavaScript req module to "./Hello.req.mjs"
[INFO] Writing JavaScript entry module to "./Hello.mjs"
[INFO] Running ./Hello.mjs
(node:11770) ExperimentalWarning: The ESM module loader is experimental.
Hello, World.
david@localhost:~/projects/asterius/example/hello (master)$
However, I haven't been able to succeed with the hilbert example and cabal. This may be due to me being clueless about cabal (I have used stack a bit but afaics that's not supported for asterius projects).
Reproduce, attempting to follow the article example:
david@localhost:~/projects/asterius (master)$ mkdir -p example/hilbert
david@localhost:~/projects/asterius (master)$ cd example/hilbert
<Copy Hilbert.cabal
and Hilbert.hs
from article>
david@localhost:~/projects/asterius/example/hilbert (master)$ ls -l
total 8
-rw-r--r-- 1 david david 371 Aug 28 14:43 Hilbert.cabal
-rw-r--r-- 1 david david 1017 Aug 28 14:49 Hilbert.hs
david@localhost:~/projects/asterius/example/hilbert (master)$ stack exec ahc-cabal -- --version
cabal-install version 3.2.0.0
compiled using version 3.2.0.0 of the Cabal library
david@localhost:~/projects/asterius/example/hilbert (master)$ stack exec ahc-cabal -- new-install . --symlink-bindir .
cabal: unrecognized 'new-install' option `--symlink-bindir'
ahc-cabal: callProcess: cabal "new-install" "." "--symlink-bindir" "." (exit 1): failed
Trying without the unsupported --symlink-bindir
flag:
david@localhost:~/projects/asterius/example/hilbert (master)$ stack exec ahc-cabal -- new-install .
cabal: Could not resolve dependencies:
[__0] trying: Hilbert-0.0.1 (user goal)
[__1] unknown package: asterius-prelude (dependency of Hilbert)
[__1] fail (backjumping, conflict set: Hilbert, asterius-prelude)
After searching the rest of the dependency tree exhaustively, these were the
goals I've had most trouble fulfilling: Hilbert, asterius-prelude
ahc-cabal: callProcess: cabal "new-install" "." (exit 1): failed
Any pointers/help appreciated.
Hi, --symlink-bindir
has been replaced by --installdir
in recent cabal
versions. And it looks like you haven't run ahc-boot
after you built asterius?
And it looks like you haven't run ahc-boot after you built asterius?
As noted above, I have run ahc-boot
, evidence as follows:
david@localhost:~/projects/asterius (master)$ stack exec ahc-boot
Configuring ghc-prim-0.5.3...
Preprocessing library for ghc-prim-0.5.3..
Building library for ghc-prim-0.5.3..
[1 of 8] Compiling GHC.Types ( GHC/Types.hs, /home/david/projects/asterius/.stack-work/install/x86_64-linux-custom-asterius/6af5b51bfbafe113c9d45b349e5c7cdf861cae09b9c27cfa60bbe90465089c81/8.8.4/share/x86_64-linux-ghc-8.8.4/asterius-0.0.1/.boot/dist/dist/ghc-prim/build/GHC/Types.o )
[2 of 8] Compiling GHC.IntWord64 ( GHC/IntWord64.hs, /home/david/projects/asterius/.stack-work/install/x86_64-linux-custom-asterius/6af5b51bfbafe113c9d45b349e5c7cdf861cae09b9c27cfa60bbe90465089c81/8.8.4/share/x86_64-linux-ghc-8.8.4/asterius-0.0.1/.boot/dist/dist/ghc-prim/build/GHC/IntWord64.o )
[3 of 8] Compiling GHC.CString ( GHC/CString.hs, /home/david/projects/asterius/.stack-work/install/x86_64-linux-custom-asterius/6af5b51bfbafe113c9d45b349e5c7cdf861cae09b9c27cfa60bbe90465089c81/8.8.4/share/x86_64-linux-ghc-8.8.4/asterius-0.0.1/.boot/dist/dist/ghc-prim/build/GHC/CString.o )
.
.
.
Completed vector-0.12.1.2
Starting aeson-1.4.7.1
Building aeson-1.4.7.1
Completed aeson-1.4.7.1
Configuring asterius-prelude-0.0.1...
Preprocessing library for asterius-prelude-0.0.1..
Building library for asterius-prelude-0.0.1..
[1 of 4] Compiling Asterius.ByteString ( src/Asterius/ByteString.hs, /home/david/projects/asterius/.stack-work/install/x86_64-linux-custom-asterius/6af5b51bfbafe113c9d45b349e5c7cdf861cae09b9c27cfa60bbe90465089c81/8.8.4/share/x86_64-linux-ghc-8.8.4/asterius-0.0.1/.boot/dist/dist/asterius-prelude/build/Asterius/ByteString.o )
[2 of 4] Compiling Asterius.Text ( src/Asterius/Text.hs, /home/david/projects/asterius/.stack-work/install/x86_64-linux-custom-asterius/6af5b51bfbafe113c9d45b349e5c7cdf861cae09b9c27cfa60bbe90465089c81/8.8.4/share/x86_64-linux-ghc-8.8.4/asterius-0.0.1/.boot/dist/dist/asterius-prelude/build/Asterius/Text.o )
[3 of 4] Compiling Asterius.UTF8 ( src/Asterius/UTF8.hs, /home/david/projects/asterius/.stack-work/install/x86_64-linux-custom-asterius/6af5b51bfbafe113c9d45b349e5c7cdf861cae09b9c27cfa60bbe90465089c81/8.8.4/share/x86_64-linux-ghc-8.8.4/asterius-0.0.1/.boot/dist/dist/asterius-prelude/build/Asterius/UTF8.o )
[4 of 4] Compiling Asterius.Aeson ( src/Asterius/Aeson.hs, /home/david/projects/asterius/.stack-work/install/x86_64-linux-custom-asterius/6af5b51bfbafe113c9d45b349e5c7cdf861cae09b9c27cfa60bbe90465089c81/8.8.4/share/x86_64-linux-ghc-8.8.4/asterius-0.0.1/.boot/dist/dist/asterius-prelude/build/Asterius/Aeson.o )
Installing library in /home/david/projects/asterius/.stack-work/install/x86_64-linux-custom-asterius/6af5b51bfbafe113c9d45b349e5c7cdf861cae09b9c27cfa60bbe90465089c81/8.8.4/share/x86_64-linux-ghc-8.8.4/asterius-0.0.1/.boot/asterius_lib/lib/x86_64-linux-ghc-8.8.4/asterius-prelude-0.0.1-2oC92S26NP8HxVQKFgOs4k
Registering library for asterius-prelude-0.0.1..
david@localhost:~/projects/asterius (master)$
I did notice just now in reviewing the build log that this seemingly fatal C compilation error is thrown (however the bootstrap build proceeds and ends with apparent success):
[8 of 8] Compiling GHC.Classes ( GHC/Classes.hs, /home/david/projects/asterius/.stack-work/install/x86_64-linux-custom-asterius/6af5b51bfbafe113c9d45b349e5c7cdf861cae09b9c27cfa60bbe90465089c81/8.8.4/share/x86_64-linux-ghc-8.8.4/asterius-0.0.1/.boot/dist/dist/ghc-prim/build/GHC/Classes.o )
cbits/atomic.c: In function ‘hs_atomic_nand8’:
cbits/atomic.c:182:10: error:
note: ‘__sync_fetch_and_nand’ changed semantics in GCC 4.4
return __sync_fetch_and_nand((volatile StgWord8 *) x, (StgWord8) val);
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
182 | return __sync_fetch_and_nand((volatile StgWord8 *) x, (StgWord8) val);
| ^
Installing library in /home/david/projects/asterius/.stack-work/install/x86_64-linux-custom-asterius/6af5b51bfbafe113c9d45b349e5c7cdf861cae09b9c27cfa60bbe90465089c81/8.8.4/share/x86_64-linux-ghc-8.8.4/asterius-0.0.1/.boot/asterius_lib/lib/x86_64-linux-ghc-8.8.4/ghc-prim-0.5.3-D5yTV0DK5iW2rkul1Hko6R
Registering library for ghc-prim-0.5.3..
note: ‘__sync_fetch_and_nand’ changed semantics in GCC 4.4
Actually, after second cup of coffee, I remember looking at this error before and concluding it wasn't fatal.
Using correct cabal
command line:
david@localhost:~/projects/asterius/example/hilbert (master)$ stack exec ahc-cabal -- new-install . --installdir .
cabal: Could not resolve dependencies:
[__0] trying: Hilbert-0.0.1 (user goal)
[__1] unknown package: asterius-prelude (dependency of Hilbert)
[__1] fail (backjumping, conflict set: Hilbert, asterius-prelude)
After searching the rest of the dependency tree exhaustively, these were the
goals I've had most trouble fulfilling: Hilbert, asterius-prelude
ahc-cabal: callProcess: cabal "new-install" "." "--installdir" "." (exit 1): failed
I suspect the problem must be to do with cabal not picking up the packages from bootstrap. I can probably debug myself. Will report back after some use of strace -f -e
...
After a bit of running the cabal 'new-install' command with strace
, I'm wondering if my problem is something to do with a package cache cabal is referencing. I see it call stat()
on all the package files successfully, including the package is says it can't find. But it never opens the files, suggesting that it thinks the cache files are up to date with the package files. Researching now to clear the cache...
8397 openat(AT_FDCWD, "/home/david/.ahc-cabal/packages/hackage.fpcomplete.com/01-index.cache", O_RDONLY|O_NOCTTY|O_NONBLOCK) = 11
8397 openat(AT_FDCWD, "/home/david/.ahc-cabal/packages/hackage.fpcomplete.com/01-index.tar", O_RDONLY|O_NOCTTY|O_NONBLOCK) = 13
david@localhost:~/projects/asterius/example/hilbert (master)$ grep asterius-prelude tracefile2
8384 stat("/home/david/projects/asterius/ghc-toolkit/boot-libs/asterius-prelude", {st_mode=S_IFDIR|0755, st_size=4096, ...}) = 0
8384 open("/home/david/projects/asterius/ghc-toolkit/boot-libs/asterius-prelude", O_RDONLY|O_CLOEXEC|O_DIRECTORY) = 13
8384 lstat("/home/david/projects/asterius/ghc-toolkit/boot-libs/asterius-prelude/src", {st_mode=S_IFDIR|0755, st_size=4096, ...}) = 0
8384 lstat("/home/david/projects/asterius/ghc-toolkit/boot-libs/asterius-prelude/LICENSE", {st_mode=S_IFREG|0644, st_size=1480, ...}) = 0
8384 lstat("/home/david/projects/asterius/ghc-toolkit/boot-libs/asterius-prelude/README.md", {st_mode=S_IFREG|0644, st_size=21, ...}) = 0
8384 lstat("/home/david/projects/asterius/ghc-toolkit/boot-libs/asterius-prelude/asterius-prelude.cabal", {st_mode=S_IFREG|0644, st_size=812, ...}) = 0
8384 lstat("/home/david/projects/asterius/ghc-toolkit/boot-libs/asterius-prelude/CHANGELOG.md", {st_mode=S_IFREG|0644, st_size=35, ...}) = 0
8384 open("/home/david/projects/asterius/ghc-toolkit/boot-libs/asterius-prelude/src", O_RDONLY|O_CLOEXEC|O_DIRECTORY) = 13
8384 lstat("/home/david/projects/asterius/ghc-toolkit/boot-libs/asterius-prelude/src/Asterius", {st_mode=S_IFDIR|0755, st_size=4096, ...}) = 0
8384 open("/home/david/projects/asterius/ghc-toolkit/boot-libs/asterius-prelude/src/Asterius", O_RDONLY|O_CLOEXEC|O_DIRECTORY) = 13
8384 lstat("/home/david/projects/asterius/ghc-toolkit/boot-libs/asterius-prelude/src/Asterius/Text.hs", {st_mode=S_IFREG|0644, st_size=1552, ...}) = 0
8384 lstat("/home/david/projects/asterius/ghc-toolkit/boot-libs/asterius-prelude/src/Asterius/ByteString.hs", {st_mode=S_IFREG|0644, st_size=1959, ...}) = 0
8384 lstat("/home/david/projects/asterius/ghc-toolkit/boot-libs/asterius-prelude/src/Asterius/Aeson.hs", {st_mode=S_IFREG|0644, st_size=973, ...}) = 0
8384 lstat("/home/david/projects/asterius/ghc-toolkit/boot-libs/asterius-prelude/src/Asterius/UTF8.hs", {st_mode=S_IFREG|0644, st_size=1598, ...}) = 0
8384 stat("/home/david/projects/asterius/ghc-toolkit/boot-libs/asterius-prelude", {st_mode=S_IFDIR|0755, st_size=4096, ...}) = 0
8384 stat("/home/david/projects/asterius/ghc-toolkit/boot-libs/asterius-prelude/CHANGELOG.md", {st_mode=S_IFREG|0644, st_size=35, ...}) = 0
8384 stat("/home/david/projects/asterius/ghc-toolkit/boot-libs/asterius-prelude/asterius-prelude.cabal", {st_mode=S_IFREG|0644, st_size=812, ...}) = 0
8384 stat("/home/david/projects/asterius/ghc-toolkit/boot-libs/asterius-prelude/README.md", {st_mode=S_IFREG|0644, st_size=21, ...}) = 0
8384 stat("/home/david/projects/asterius/ghc-toolkit/boot-libs/asterius-prelude/LICENSE", {st_mode=S_IFREG|0644, st_size=1480, ...}) = 0
8384 stat("/home/david/projects/asterius/ghc-toolkit/boot-libs/asterius-prelude/src", {st_mode=S_IFDIR|0755, st_size=4096, ...}) = 0
8384 stat("/home/david/projects/asterius/ghc-toolkit/boot-libs/asterius-prelude/src/Asterius", {st_mode=S_IFDIR|0755, st_size=4096, ...}) = 0
8384 stat("/home/david/projects/asterius/ghc-toolkit/boot-libs/asterius-prelude/src/Asterius/UTF8.hs", {st_mode=S_IFREG|0644, st_size=1598, ...}) = 0
8384 stat("/home/david/projects/asterius/ghc-toolkit/boot-libs/asterius-prelude/src/Asterius/Aeson.hs", {st_mode=S_IFREG|0644, st_size=973, ...}) = 0
8384 stat("/home/david/projects/asterius/ghc-toolkit/boot-libs/asterius-prelude/src/Asterius/ByteString.hs", {st_mode=S_IFREG|0644, st_size=1959, ...}) = 0
8384 stat("/home/david/projects/asterius/ghc-toolkit/boot-libs/asterius-prelude/src/Asterius/Text.hs", {st_mode=S_IFREG|0644, st_size=1552, ...}) = 0