Skip to content
This repository was archived by the owner on Nov 13, 2024. It is now read-only.

Commit 8347471

Browse files
authored
Support binaryen version_97 (#14)
1 parent 4b8a70d commit 8347471

File tree

13 files changed

+634
-71
lines changed

13 files changed

+634
-71
lines changed

.github/workflows/pipeline.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ jobs:
2222
run: |
2323
curl \
2424
-o /tmp/binaryen.deb \
25-
http://deb.debian.org/debian/pool/main/b/binaryen/binaryen_96-1_amd64.deb
25+
http://deb.debian.org/debian/pool/main/b/binaryen/binaryen_97-1_amd64.deb
2626
sudo dpkg -i /tmp/binaryen.deb
2727
rm /tmp/binaryen.deb
2828
@@ -48,7 +48,7 @@ jobs:
4848
run: |
4949
curl \
5050
-o /tmp/binaryen.deb \
51-
http://deb.debian.org/debian/pool/main/b/binaryen/binaryen_96-1_amd64.deb
51+
http://deb.debian.org/debian/pool/main/b/binaryen/binaryen_97-1_amd64.deb
5252
sudo dpkg -i /tmp/binaryen.deb
5353
rm /tmp/binaryen.deb
5454
@@ -81,7 +81,7 @@ jobs:
8181
run: |
8282
curl \
8383
-o /tmp/binaryen.deb \
84-
http://deb.debian.org/debian/pool/main/b/binaryen/binaryen_96-1_amd64.deb
84+
http://deb.debian.org/debian/pool/main/b/binaryen/binaryen_97-1_amd64.deb
8585
sudo dpkg -i /tmp/binaryen.deb
8686
rm /tmp/binaryen.deb
8787

README.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
11
# Haskell bindings for [binaryen][binaryen]
22

3-
[![Build status](https://badge.buildkite.com/f96af58baa5635b8cdef87abddc9070765fa4f562cc6cb8f47.svg?branch=master)](https://buildkite.com/tweag-1/haskell-binaryen)
3+
![](https://github.com/tweag/haskell-binaryen/workflows/pipeline/badge.svg?branch=master)
44

5-
[Binaryen][binaryen] is a compiler and toolchain infrastructure
6-
library for WebAssembly, written in C++. This package defines
7-
bindings to the [Binaryen API][binaryen-api].
8-
9-
[binaryen]: https://github.com/WebAssembly/binaryen
10-
[binaryen-api]: https://github.com/WebAssembly/binaryen/blob/master/src/binaryen-c.h
5+
[Binaryen][binaryen] is a compiler and toolchain infrastructure library for
6+
WebAssembly, written in C++. This package defines bindings to the [Binaryen C
7+
API][binaryen-api].
118

129
## Versioning
1310

@@ -20,6 +17,7 @@ it's no less than the minimum version listed below.
2017
| 0.0.1.* | version_91 |
2118
| 0.0.2.* | version_94 |
2219
| 0.0.3.* | version_96 |
20+
| 0.0.4.* | version_97 |
2321

2422

2523
## How to build
@@ -34,5 +32,7 @@ Then,
3432
$ stack --nix build
3533
```
3634

37-
[nix]: https://nixos.org/nix/
38-
[stack]: https://docs.haskellstack.org/en/stable/README/
35+
[binaryen]: https://github.com/WebAssembly/binaryen
36+
[binaryen-api]: https://github.com/WebAssembly/binaryen/blob/master/src/binaryen-c.h
37+
[nix]: https://nixos.org/nix
38+
[stack]: https://docs.haskellstack.org/en/stable/README

binaryen.cabal

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ cabal-version: 1.12
44
--
55
-- see: https://github.com/sol/hpack
66
--
7-
-- hash: c6dda58fc71ff980baacba8cebb211dfae6ba9a6099d849dd9f830555bb86cf2
7+
-- hash: a97a536c6a54def78b714cf926b75e3dc2ede559d014ec6295143c608c11c1c9
88

99
name: binaryen
10-
version: 0.0.3.0
10+
version: 0.0.4.0
1111
synopsis: Haskell bindings to binaryen
1212
description: Haskell bindings to [binaryen](https://github.com/WebAssembly/binaryen). Provides complete bindings to the C API, which can be useful for building WebAssembly toolchains in Haskell.
1313
category: Compiler

nix/sources.json

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
{
2+
"niv": {
3+
"branch": "master",
4+
"description": "Easy dependency management for Nix projects",
5+
"homepage": "https://github.com/nmattia/niv",
6+
"owner": "nmattia",
7+
"repo": "niv",
8+
"rev": "29ddaaf4e099c3ac0647f5b652469dfc79cd3b53",
9+
"sha256": "1va6myp07gkspgxfch8z3rs9nyvys6jmgzkys6a2c4j09qxp1bs0",
10+
"type": "tarball",
11+
"url": "https://github.com/nmattia/niv/archive/29ddaaf4e099c3ac0647f5b652469dfc79cd3b53.tar.gz",
12+
"url_template": "https://github.com/<owner>/<repo>/archive/<rev>.tar.gz"
13+
},
14+
"nixpkgs": {
15+
"branch": "nixpkgs-unstable",
16+
"description": "Nix Packages collection",
17+
"homepage": null,
18+
"owner": "NixOS",
19+
"repo": "nixpkgs-channels",
20+
"rev": "6803bc6882004ec296fca90252d9764a60040abd",
21+
"sha256": "0hg9jrcb01ilpq5qc6bhm5pzip6l1nk51zgcqw1da63lfpbrsbnl",
22+
"type": "tarball",
23+
"url": "https://github.com/NixOS/nixpkgs-channels/archive/6803bc6882004ec296fca90252d9764a60040abd.tar.gz",
24+
"url_template": "https://github.com/<owner>/<repo>/archive/<rev>.tar.gz"
25+
}
26+
}

nix/sources.nix

Lines changed: 171 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,171 @@
1+
# This file has been generated by Niv.
2+
3+
let
4+
5+
#
6+
# The fetchers. fetch_<type> fetches specs of type <type>.
7+
#
8+
9+
fetch_file = pkgs: name: spec:
10+
let
11+
name' = sanitizeName name + "-src";
12+
in
13+
if spec.builtin or true then
14+
builtins_fetchurl { inherit (spec) url sha256; name = name'; }
15+
else
16+
pkgs.fetchurl { inherit (spec) url sha256; name = name'; };
17+
18+
fetch_tarball = pkgs: name: spec:
19+
let
20+
name' = sanitizeName name + "-src";
21+
in
22+
if spec.builtin or true then
23+
builtins_fetchTarball { name = name'; inherit (spec) url sha256; }
24+
else
25+
pkgs.fetchzip { name = name'; inherit (spec) url sha256; };
26+
27+
fetch_git = name: spec:
28+
let
29+
ref =
30+
if spec ? ref then spec.ref else
31+
if spec ? branch then "refs/heads/${spec.branch}" else
32+
if spec ? tag then "refs/tags/${spec.tag}" else
33+
abort "In git source '${name}': Please specify `ref`, `tag` or `branch`!";
34+
in
35+
builtins.fetchGit { url = spec.repo; inherit (spec) rev; inherit ref; };
36+
37+
fetch_local = spec: spec.path;
38+
39+
fetch_builtin-tarball = name: throw
40+
''[${name}] The niv type "builtin-tarball" is deprecated. You should instead use `builtin = true`.
41+
$ niv modify ${name} -a type=tarball -a builtin=true'';
42+
43+
fetch_builtin-url = name: throw
44+
''[${name}] The niv type "builtin-url" will soon be deprecated. You should instead use `builtin = true`.
45+
$ niv modify ${name} -a type=file -a builtin=true'';
46+
47+
#
48+
# Various helpers
49+
#
50+
51+
# https://github.com/NixOS/nixpkgs/pull/83241/files#diff-c6f540a4f3bfa4b0e8b6bafd4cd54e8bR695
52+
sanitizeName = name:
53+
(
54+
concatMapStrings (s: if builtins.isList s then "-" else s)
55+
(
56+
builtins.split "[^[:alnum:]+._?=-]+"
57+
((x: builtins.elemAt (builtins.match "\\.*(.*)" x) 0) name)
58+
)
59+
);
60+
61+
# The set of packages used when specs are fetched using non-builtins.
62+
mkPkgs = sources: system:
63+
let
64+
sourcesNixpkgs =
65+
import (builtins_fetchTarball { inherit (sources.nixpkgs) url sha256; }) { inherit system; };
66+
hasNixpkgsPath = builtins.any (x: x.prefix == "nixpkgs") builtins.nixPath;
67+
hasThisAsNixpkgsPath = <nixpkgs> == ./.;
68+
in
69+
if builtins.hasAttr "nixpkgs" sources
70+
then sourcesNixpkgs
71+
else if hasNixpkgsPath && ! hasThisAsNixpkgsPath then
72+
import <nixpkgs> {}
73+
else
74+
abort
75+
''
76+
Please specify either <nixpkgs> (through -I or NIX_PATH=nixpkgs=...) or
77+
add a package called "nixpkgs" to your sources.json.
78+
'';
79+
80+
# The actual fetching function.
81+
fetch = pkgs: name: spec:
82+
83+
if ! builtins.hasAttr "type" spec then
84+
abort "ERROR: niv spec ${name} does not have a 'type' attribute"
85+
else if spec.type == "file" then fetch_file pkgs name spec
86+
else if spec.type == "tarball" then fetch_tarball pkgs name spec
87+
else if spec.type == "git" then fetch_git name spec
88+
else if spec.type == "local" then fetch_local spec
89+
else if spec.type == "builtin-tarball" then fetch_builtin-tarball name
90+
else if spec.type == "builtin-url" then fetch_builtin-url name
91+
else
92+
abort "ERROR: niv spec ${name} has unknown type ${builtins.toJSON spec.type}";
93+
94+
# If the environment variable NIV_OVERRIDE_${name} is set, then use
95+
# the path directly as opposed to the fetched source.
96+
replace = name: drv:
97+
let
98+
saneName = stringAsChars (c: if isNull (builtins.match "[a-zA-Z0-9]" c) then "_" else c) name;
99+
ersatz = builtins.getEnv "NIV_OVERRIDE_${saneName}";
100+
in
101+
if ersatz == "" then drv else ersatz;
102+
103+
# Ports of functions for older nix versions
104+
105+
# a Nix version of mapAttrs if the built-in doesn't exist
106+
mapAttrs = builtins.mapAttrs or (
107+
f: set: with builtins;
108+
listToAttrs (map (attr: { name = attr; value = f attr set.${attr}; }) (attrNames set))
109+
);
110+
111+
# https://github.com/NixOS/nixpkgs/blob/0258808f5744ca980b9a1f24fe0b1e6f0fecee9c/lib/lists.nix#L295
112+
range = first: last: if first > last then [] else builtins.genList (n: first + n) (last - first + 1);
113+
114+
# https://github.com/NixOS/nixpkgs/blob/0258808f5744ca980b9a1f24fe0b1e6f0fecee9c/lib/strings.nix#L257
115+
stringToCharacters = s: map (p: builtins.substring p 1 s) (range 0 (builtins.stringLength s - 1));
116+
117+
# https://github.com/NixOS/nixpkgs/blob/0258808f5744ca980b9a1f24fe0b1e6f0fecee9c/lib/strings.nix#L269
118+
stringAsChars = f: s: concatStrings (map f (stringToCharacters s));
119+
concatMapStrings = f: list: concatStrings (map f list);
120+
concatStrings = builtins.concatStringsSep "";
121+
122+
# https://github.com/NixOS/nixpkgs/blob/8a9f58a375c401b96da862d969f66429def1d118/lib/attrsets.nix#L331
123+
optionalAttrs = cond: as: if cond then as else {};
124+
125+
# fetchTarball version that is compatible between all the versions of Nix
126+
builtins_fetchTarball = { url, name ? null, sha256 }@attrs:
127+
let
128+
inherit (builtins) lessThan nixVersion fetchTarball;
129+
in
130+
if lessThan nixVersion "1.12" then
131+
fetchTarball ({ inherit url; } // (optionalAttrs (!isNull name) { inherit name; }))
132+
else
133+
fetchTarball attrs;
134+
135+
# fetchurl version that is compatible between all the versions of Nix
136+
builtins_fetchurl = { url, name ? null, sha256 }@attrs:
137+
let
138+
inherit (builtins) lessThan nixVersion fetchurl;
139+
in
140+
if lessThan nixVersion "1.12" then
141+
fetchurl ({ inherit url; } // (optionalAttrs (!isNull name) { inherit name; }))
142+
else
143+
fetchurl attrs;
144+
145+
# Create the final "sources" from the config
146+
mkSources = config:
147+
mapAttrs (
148+
name: spec:
149+
if builtins.hasAttr "outPath" spec
150+
then abort
151+
"The values in sources.json should not have an 'outPath' attribute"
152+
else
153+
spec // { outPath = replace name (fetch config.pkgs name spec); }
154+
) config.sources;
155+
156+
# The "config" used by the fetchers
157+
mkConfig =
158+
{ sourcesFile ? if builtins.pathExists ./sources.json then ./sources.json else null
159+
, sources ? if isNull sourcesFile then {} else builtins.fromJSON (builtins.readFile sourcesFile)
160+
, system ? builtins.currentSystem
161+
, pkgs ? mkPkgs sources system
162+
}: rec {
163+
# The sources, i.e. the attribute set of spec name to spec
164+
inherit sources;
165+
166+
# The "pkgs" (evaluated nixpkgs) to use for e.g. non-builtin fetchers
167+
inherit pkgs;
168+
};
169+
170+
in
171+
mkSources (mkConfig {}) // { __functor = _: settings: mkSources (mkConfig settings); }

nixpkgs.nix

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
11
let
2-
rev = "4855aa62fa13052fb1a3daea68971503ab07a744";
3-
sha256 = "17sk264qw397zzw12x11ry5vj9qidgbmjsyj544ysg857b4qq9sj";
2+
sources = import ./nix/sources.nix { };
43
in
5-
import (fetchTarball {
6-
inherit sha256;
7-
url = "https://github.com/NixOS/nixpkgs/archive/${rev}.tar.gz";
8-
})
4+
import (sources.nixpkgs)

package.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: binaryen
2-
version: 0.0.3.0
2+
version: 0.0.4.0
33
synopsis: Haskell bindings to binaryen
44
description: Haskell bindings to [binaryen](https://github.com/WebAssembly/binaryen). Provides complete bindings to the C API, which can be useful for building WebAssembly toolchains in Haskell.
55
category: Compiler

shell.nix

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
{pkgs ? import ./nixpkgs.nix {} }:
1+
{ pkgs ? import ./nixpkgs.nix { } }:
22

33
with pkgs;
44

@@ -7,7 +7,7 @@ mkShell {
77
buildInputs = [
88
binaryen
99
cabal-install
10-
haskell.compiler.ghc8101
10+
haskell.compiler.ghc884
1111
nix
1212
stack
1313
];

0 commit comments

Comments
 (0)