Skip to content

Commit

Permalink
feat: Initial implementation (#1)
Browse files Browse the repository at this point in the history
Release-As: 101.0.0
  • Loading branch information
phated committed Nov 7, 2021
1 parent db3be01 commit 9da8c77
Show file tree
Hide file tree
Showing 73 changed files with 4,449 additions and 1 deletion.
2 changes: 2 additions & 0 deletions .gitattributes
@@ -0,0 +1,2 @@
.github export-ignore
.ocamlformat export-ignore
40 changes: 40 additions & 0 deletions .github/workflows/esy.yml
@@ -0,0 +1,40 @@
name: Esy
on:
- push
- pull_request

jobs:
build:
name: Build and test
runs-on: ${{ matrix.os }}

strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]

steps:
- name: Setup node.js
uses: actions/setup-node@v2.1.2
with:
node-version: '14'
check-latest: true

# Install `esy` to build the project
- name: Setup environment
run: |
npm i -g esy
- name: Checkout project
uses: actions/checkout@v2
with:
submodules: 'recursive'

- name: Esy build
uses: esy/github-action@d859489ca96411749931bceb4d733a2bdea922f9
with:
cache-key: ${{ hashFiles('esy.lock/index.json') }}

- name: Run tests
run: |
esy test
36 changes: 36 additions & 0 deletions .github/workflows/opam.yml
@@ -0,0 +1,36 @@
name: Opam
on:
- push
- pull_request

jobs:
build:
name: Build and test
runs-on: ${{ matrix.os }}

strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
ocaml-compiler: [4.12.0]

steps:
- name: Checkout project
uses: actions/checkout@v2
with:
submodules: 'recursive'

- name: Setup OCaml ${{ matrix.ocaml-compiler }}
uses: ocaml/setup-ocaml@v2
with:
ocaml-compiler: ${{ matrix.ocaml-compiler }}

- name: Install local dependencies
run: opam install . --deps-only --with-test

- name: Build project
run: opam exec -- dune build

- name: Run tests
run: |
opam exec -- dune runtest
113 changes: 113 additions & 0 deletions .github/workflows/release.yml
@@ -0,0 +1,113 @@
name: Release
on:
push:
branches:
- master

jobs:
release-please:
name: Create Release
runs-on: ubuntu-latest
outputs:
release_created: ${{ steps.release.outputs.release_created }}
upload_url: ${{ steps.release.outputs.upload_url }}
tag_name: ${{ steps.release.outputs.tag_name }}
body: ${{ steps.release.outputs.body }}
steps:
- uses: GoogleCloudPlatform/release-please-action@v2.34.0
id: release
with:
token: ${{ secrets.GITHUB_TOKEN }}
release-type: ocaml
package-name: libbinaryen

add-archive:
needs: [release-please]
if: ${{ needs.release-please.outputs.release_created }}
name: Add archive to release
runs-on: macos-latest
outputs:
browser_download_url: ${{ steps.upload.outputs.browser_download_url }}
steps:
- name: Install git-archive-all
run: |
brew install git-archive-all
- name: Checkout code
uses: actions/checkout@v2
with:
submodules: 'recursive'

- name: Build archive
run: |
git-archive-all --force-submodules libbinaryen.tar.gz
- name: Upload Release Asset
id: upload
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ needs.release-please.outputs.upload_url }}
asset_path: ./libbinaryen.tar.gz
asset_name: libbinaryen-${{ needs.release-please.outputs.tag_name }}.tar.gz
asset_content_type: application/gzip

opam-release:
needs: [release-please, add-archive]
name: Publish to opam registry
runs-on: ubuntu-latest
steps:
- name: Setup bot user
run: |
git config --global user.email "bot@grain-lang.org"
git config --global user.name "Grain Bot"
# Some hacks to make sure opam doesn't pull the repo in a way we can't deal with
- name: Setup opam repository
run: |
mkdir -p ~/.opam/plugins/opam-publish/repos/
git clone git://github.com/ocaml/opam-repository ~/.opam/plugins/opam-publish/repos/ocaml%opam-repository
cd ~/.opam/plugins/opam-publish/repos/ocaml%opam-repository
git remote add user https://${{ secrets.OPAM_RELEASE }}@github.com/grainbot/opam-repository
# Set up our token because opam doesn't support env var tokens
- name: Setup token
run: |
mkdir -p ~/.opam/plugins/opam-publish/
echo -n ${{ secrets.OPAM_RELEASE }} > ~/.opam/plugins/opam-publish/libbinaryen.token
- name: Generate CHANGES file
env:
CHANGES: ${{ needs.release-please.outputs.body }}
run: |
echo -n "$CHANGES" > CHANGES.md
- name: Setup OCaml
uses: ocaml/setup-ocaml@v2
with:
ocaml-compiler: 4.12.0

- name: Install publish utils
run: |
opam install opam-publish
- name: Publish to opam
run: |
opam publish --no-browser --msg-file=CHANGES.md ${{ needs.add-archive.outputs.browser_download_url }}
npm-release:
needs: [add-archive]
name: Publish to npm registry
runs-on: ubuntu-latest
steps:
- name: Setup NodeJS
uses: actions/setup-node@v2
with:
node-version: "14"
registry-url: "https://registry.npmjs.org"

- name: Publish to npm
run: npm publish ${{ needs.add-archive.outputs.browser_download_url }}
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_RELEASE }}
12 changes: 12 additions & 0 deletions .gitignore
Expand Up @@ -27,3 +27,15 @@ setup.log

# Local OPAM switch
_opam/

# Esy
node_modules/
_esy/

# Other
META
.vscode/
.DS_Store
*.tar.gz
*.install
*.zip
3 changes: 3 additions & 0 deletions .gitmodules
@@ -0,0 +1,3 @@
[submodule "binaryen"]
path = binaryen
url = https://github.com/WebAssembly/binaryen
Empty file added .ocamlformat
Empty file.
50 changes: 49 additions & 1 deletion README.md
@@ -1,2 +1,50 @@
# libbinaryen
libbinaryen packaged for OCaml

Libbinaryen packaged for OCaml.

This is just the low-level C library. If you are looking for OCaml *bindings* to Binaryen, check out [Binaryen.ml](https://github.com/grain-lang/binaryen.ml)!

## Usage

Inside your dune file, you can depend on `libbinaryen` as such:

```
(library
(name binaryen)
(public_name binaryen)
(libraries libbinaryen.c)
(foreign_stubs
(language c)
(names binaryen_stubs)
(flags :standard -O2 -Wall -Wextra))
(c_library_flags :standard -lstdc++ -lpthread))
```

## Library flags

This package attempts to smooth over configuration frustrations by providing specific `library_flags` when built.

### MacOS

In order to support Mac M1, this package assumes you are using `clang++` on MacOS and applies the flags `-cc clang++` to the built library.

### Windows

On Windows, this package assumes libbinaryen is built under MinGW and applies the flags `-ccopt -- -ccopt -static` to the built library.

## Contributing

You'll need Node.js and [`esy`](https://esy.sh/docs/en/getting-started.html#install-esy) to build this project.
You should be able to use Opam if you are more comfortable with it, but the core team does all development using esy.

`dune` will take care of compiling Binaryen, so to build the project you'll only need to run:

```bash
esy
```

This will take a while. Once it's done, you can run the tests:

```bash
esy test
```
1 change: 1 addition & 0 deletions binaryen
Submodule binaryen added at 423cf0
8 changes: 8 additions & 0 deletions config/dune
@@ -0,0 +1,8 @@
(executable
(name library_flags)
(libraries dune.configurator))

(rule
(targets library_flags.sexp)
(action
(run ./library_flags.exe)))
17 changes: 17 additions & 0 deletions config/library_flags.ml
@@ -0,0 +1,17 @@
module C = Configurator.V1

let () =
C.main ~name:"library_flags" (fun c ->
let default = [] in

let library_flags =
match C.ocaml_config_var c "system" with
| Some "macosx" ->
(* These flags preserve the original C++ error behavior. Ref https://github.com/ocaml/ocaml/issues/10423 *)
[ "-cc"; "clang++" ]
| Some "mingw64" -> [ "-ccopt"; "--"; "-ccopt"; "-static" ]
| Some _ -> default
| None -> default
in

C.Flags.write_sexp "library_flags.sexp" library_flags)

0 comments on commit 9da8c77

Please sign in to comment.