Skip to content

Commit

Permalink
Merge pull request #658 from dfordivam/wasm-support-1
Browse files Browse the repository at this point in the history
Add wasm cross compilation
  • Loading branch information
3noch authored May 1, 2020
2 parents 9781487 + d3ddf20 commit 71e8726
Show file tree
Hide file tree
Showing 8 changed files with 66 additions and 10 deletions.
15 changes: 15 additions & 0 deletions default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,8 @@ let iosSupport = system == "x86_64-darwin";

inherit (nixpkgs) lib fetchurl fetchgit fetchgitPrivate fetchFromGitHub fetchFromBitbucket;

wasmCross = nixpkgs.hackGet ./wasm-cross;
webGhcSrc = (import (wasmCross + /webghc.nix) { inherit fetchgit; }).ghc865SplicesSrc;
nixpkgsCross = {
android = lib.mapAttrs (_: args: nixpkgsFunc (nixpkgsArgs // args)) rec {
aarch64 = {
Expand Down Expand Up @@ -149,6 +151,9 @@ let iosSupport = system == "x86_64-darwin";
ghcjs = nixpkgsFunc (nixpkgsArgs // {
crossSystem = lib.systems.examples.ghcjs;
});
wasm = nixpkgsFunc (nixpkgsArgs //
(import wasmCross { inherit nixpkgsFunc; }).nixpkgsCrossArgs webGhcSrc "8.6.5"
);
};

haskellLib = nixpkgs.haskell.lib;
Expand Down Expand Up @@ -205,6 +210,14 @@ let iosSupport = system == "x86_64-darwin";
overrides = nixpkgsCross.ghcjs.haskell.overlays.combined;
};

wasm = ghcWasm32-8_6;
ghcWasm32-8_6 = makeRecursivelyOverridableBHPToo ((makeRecursivelyOverridable (nixpkgsCross.wasm.haskell.packages.ghcWasm.override (old: {
# Due to the splices changes the parallel build fails while building the libraries
ghc = old.ghc.overrideAttrs (drv: { enableParallelBuilding = false; });
}))).override {
overrides = nixpkgsCross.wasm.haskell.overlays.combined;
});

ghc = ghc8_6;
ghcHEAD = (makeRecursivelyOverridable nixpkgs.haskell.packages.ghcHEAD).override {
overrides = nixpkgs.haskell.overlays.combined;
Expand Down Expand Up @@ -299,6 +312,8 @@ in let this = rec {
iosAarch32
iosAarch64
iosWithHaskellPackages
wasm
wasmCross
;

# Back compat
Expand Down
6 changes: 5 additions & 1 deletion haskell-overlays/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

let
inherit (nixpkgs.buildPackages) thunkSet runCommand fetchgit fetchFromGitHub fetchFromBitbucket;
inherit (nixpkgs) hackGet;
in

rec {
Expand Down Expand Up @@ -53,6 +54,7 @@ rec {

(optionalExtension (nixpkgs.stdenv.hostPlatform.useAndroidPrebuilt or false) android)
(optionalExtension (nixpkgs.stdenv.hostPlatform.isiOS or false) ios)
(optionalExtension (nixpkgs.stdenv.hostPlatform.isWasm or false) wasm)

user-custom-post
] self super;
Expand Down Expand Up @@ -85,7 +87,7 @@ rec {

reflexPackages = import ./reflex-packages {
inherit
haskellLib lib nixpkgs thunkSet fetchFromGitHub fetchFromBitbucket
haskellLib lib nixpkgs thunkSet fetchFromGitHub fetchFromBitbucket hackGet
useFastWeak useReflexOptimizer enableTraceReflexEvents enableLibraryProfiling __useTemplateHaskell
;
};
Expand Down Expand Up @@ -156,6 +158,8 @@ rec {
inherit thunkSet;
};

wasm = import ./wasm;

user-custom-pre = foldExtensions haskellOverlaysPre;
user-custom-post = foldExtensions haskellOverlaysPost;
}
9 changes: 7 additions & 2 deletions haskell-overlays/reflex-packages/default.nix
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{ haskellLib
, lib, nixpkgs
, thunkSet, fetchFromGitHub, fetchFromBitbucket
, thunkSet, fetchFromGitHub, fetchFromBitbucket, hackGet
, useFastWeak, useReflexOptimizer, enableTraceReflexEvents, enableLibraryProfiling, __useTemplateHaskell
}:

Expand All @@ -13,6 +13,7 @@ let
reflexDomRepo = self._dep.reflex-dom;
jsaddleSrc = self._dep.jsaddle;
gargoylePkgs = self.callPackage self._dep.gargoyle self;
wasmCross = hackGet ../../wasm-cross;

reflexOptimizerFlag = lib.optional (useReflexOptimizer && (self.ghc.cross or null) == null) "-fuse-reflex-optimizer";
useTemplateHaskellFlag = lib.optional (!__useTemplateHaskell) "-f-use-template-haskell";
Expand Down Expand Up @@ -86,8 +87,11 @@ in
])) {})
(drv: {
# Hack until https://github.com/NixOS/cabal2nix/pull/432 lands
libraryHaskellDepends = (drv.libraryHaskellDepends or []) ++ stdenv.lib.optionals (with stdenv.hostPlatform; isAndroid && is32bit) [
libraryHaskellDepends = (drv.libraryHaskellDepends or [])
++ stdenv.lib.optionals (with stdenv.hostPlatform; isAndroid && is32bit) [
self.android-activity
] ++ stdenv.lib.optionals (with stdenv.hostPlatform; isWasm && is32bit) [
self.jsaddle-wasm
];
});

Expand Down Expand Up @@ -129,6 +133,7 @@ in
jsaddle-warp = dontCheck (self.callCabal2nix "jsaddle-warp" (jsaddleSrc + /jsaddle-warp) {});

jsaddle-dom = self.callCabal2nix "jsaddle-dom" self._dep.jsaddle-dom {};
jsaddle-wasm = self.callCabal2nix "jsaddle-wasm" (hackGet (wasmCross + /jsaddle-wasm)) {};
ghcjs-dom = self.callCabal2nix "ghcjs-dom" (self._dep.ghcjs-dom + "/ghcjs-dom") {};
ghcjs-dom-jsaddle = self.callCabal2nix "ghcjs-dom-jsaddle" (self._dep.ghcjs-dom + "/ghcjs-dom-jsaddle") {};
ghcjs-dom-jsffi = self.callCabal2nix "ghcjs-dom-jsffi" (self._dep.ghcjs-dom + "/ghcjs-dom-jsffi") {};
Expand Down
6 changes: 3 additions & 3 deletions haskell-overlays/reflex-packages/dep/reflex-dom/github.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"owner": "reflex-frp",
"repo": "reflex-dom",
"branch": "master",
"rev": "94c26076a71f229b5bd27128cf6fc0dbcba011ac",
"sha256": "00sx5x51jv1j24qlhrbp5sqnqcyz1iy2sgjap0y97c4dkzxi3wd3"
"branch": "develop",
"rev": "e2b846037badee035d0c466173badd1c4c474d5a",
"sha256": "12vj25zzg2xr6mvyw83skr24y30swmg79kmg7lizy3klwpv5dysc"
}
16 changes: 16 additions & 0 deletions haskell-overlays/wasm/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
self: super: {
jsaddle-warp = null;
jsaddle-webkitgtk = null;
jsaddle-webkit2gtk = null;
jsaddle-wkwebview = null;
mkDerivation = args: super.mkDerivation (args // {
dontStrip = true;
enableSharedExecutables = false;
enableSharedLibraries = false;
enableDeadCodeElimination = false;
doHaddock = false;
doCheck = false;
enableLibraryProfiling = false;
});
}

8 changes: 4 additions & 4 deletions nixpkgs/github.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"owner": "nixos",
"owner": "WebGHC",
"repo": "nixpkgs",
"branch": "release-19.09",
"rev": "49550f29cd9d6ed27f4a76ba3c3fe30edf882eb7",
"sha256": "003fpkrcc5mw33q670q4z865zpr430cllbxhyzj8k9p4hbc8yqda"
"branch": "wasm-r-p-1909-integ",
"rev": "423fa4adb6276298cde0c12205efeb7bf1cbe805",
"sha256": "0ssvc5j0p7nip0qsrdbfgc6wihzwyxa23hbr80dmjbfizywz7nzg"
}
8 changes: 8 additions & 0 deletions wasm-cross/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# DO NOT HAND-EDIT THIS FILE
let fetch = { private ? false, fetchSubmodules ? false, owner, repo, rev, sha256, ... }:
if !fetchSubmodules && !private then builtins.fetchTarball {
url = "https://github.com/${owner}/${repo}/archive/${rev}.tar.gz"; inherit sha256;
} else (import <nixpkgs> {}).fetchFromGitHub {
inherit owner repo rev sha256 fetchSubmodules private;
};
in import (fetch (builtins.fromJSON (builtins.readFile ./github.json)))
8 changes: 8 additions & 0 deletions wasm-cross/github.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"owner": "WebGHC",
"repo": "wasm-cross",
"branch": "reflex-platform-integ",
"private": false,
"rev": "98dbc945147ed646724682a2a4f470bc592a5501",
"sha256": "1vnxmxx262h6r0lslidd0fnnrsjz88jfx1dj7v66vl0pjdz7icb4"
}

0 comments on commit 71e8726

Please sign in to comment.