Issue compiling cabal library to wasm

Yet another wasm question!

I’m trying to compile a cabal project using the ghc-wasm-meta 9.8 compiler, but I’m getting the following error:

wasm-ld: error: unable to find library -lHSrts-1.0.2_thr

my cabal.project and each name.cabal have the following ghc-options:

program options/library
  ghc-options: -no-hs-main -optl-mexec-model=reactor "-optl-Wl"

something I noticed is that if I run build using --verbose , the call to wasm32-wasi-ghc doesn’t have any of the ghc-options I’ve set. Maybe it’s got something to do with the Setup.hs? but that file just has the usual:

import Distribution.Simple
main = defaultMain

Anybody got an idea of what might be happening?

The problem is that singletons-base uses Cabal’s build-type: Custom here. Custom setup is not supported by the WASM backend, as they involve running compiled code during the build process; but Cabal doesn’t know how to run .wasm files. You should be able to proceed by simply changing that line to build-type: Simple.

1 Like

thank you! that was the issue. The explanation makes complete sense.

A quick follow up, If i wanted to import singletons in another project, should the flake be like this?

{
  inputs = {
    nixpkgs.url = "github:nixos/nixpkgs/nixpkgs-unstable";
    flake-parts.url = "github:hercules-ci/flake-parts";
    haskell-flake.url = "github:srid/haskell-flake";
    ghc-wasm.url = "git+https://gitlab.haskell.org/ghc/ghc-wasm-meta"; 
    singletons.url = "github:/initial-mockingbird/singletons/545265e028d8c63b10be0f034a1c2641df831e2c";
    singletons.flake = false;

  };
  outputs = inputs@{ self, nixpkgs, flake-parts, ... }:
    flake-parts.lib.mkFlake { inherit inputs; } {
      systems = nixpkgs.lib.systems.flakeExposed; 
      imports = [ inputs.haskell-flake.flakeModule];

      perSystem = { self', pkgs, config, ... }: 
        {
        haskellProjects.default = {
          basePackages = pkgs.haskell.packages.ghc982;
          packages = {
            singletons.source = inputs.singletons;
          };
          settings = {
             singletons = {
              check = false;
             };
          };
          devShell = {
            hlsCheck.enable = true;
            hoogle = true;

           };
          autoWire = [ "packages" "apps" "checks" ];

        };
        packages.default = self'.packages.ICFP2024;

        devShells.default = pkgs.mkShell {
          name = "haskell-template";
          meta.description = "Haskell development environment";
          inputsFrom = [
            config.haskellProjects.default.outputs.devShell
          ];
          nativeBuildInputs = 
            [ inputs.ghc-wasm.packages.${pkgs.system}.all_9_8
            ];
        };
      };
    };
}

Because whenever my direnv tries to use flake it throws:

cabal2nix: user error (*** Found neither a .cabal file nor package.yaml. Exiting.)

I’ve never used haskell-flake, but you may have a typo in your input:

github:/initial-mockingbird... -> github:initial-mockingbird...