Skip to content

Commit

Permalink
fix: Remove library_flags & only specify c_library_flags where needed (
Browse files Browse the repository at this point in the history
…#41)

fix: Run cmake build with -j4 for faster builds
chore: Add the mingw path to the esy buildEnv & exportedEnv
chore: Add OCaml 4.13.1 to the Opam CI matrix
chore: Widen esy ocaml version & update devDeps
chore: Update README to discuss flags
fix: Use double dash before -j4 to always pass through (#39)

Co-authored-by: Eduardo Rafael <theeduardorfs@gmail.com>
  • Loading branch information
phated and EduardoRFS committed Jan 20, 2022
1 parent cf3a72e commit a89fad6
Show file tree
Hide file tree
Showing 30 changed files with 582 additions and 755 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/opam.yml
Expand Up @@ -12,7 +12,7 @@ jobs:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
ocaml-compiler: [4.12.0]
ocaml-compiler: [4.12.0, 4.13.1]

steps:
- name: Checkout project
Expand Down
37 changes: 29 additions & 8 deletions README.md
Expand Up @@ -16,8 +16,7 @@ Inside your dune file, you can depend on `libbinaryen` as such:
(foreign_stubs
(language c)
(names binaryen_stubs)
(flags :standard -O2 -Wall -Wextra))
(c_library_flags :standard -lstdc++ -lpthread))
(flags :standard -O2 -Wall -Wextra)))
```

## Dependencies
Expand All @@ -28,17 +27,39 @@ When installing with opam, both of these dependencies will be checked using `con

When installing with esy, CMake will be built from source, and, on Mac or Linux, Python must be globally installed within a location that esy knows about (those being `/usr/local/bin`, `/usr/bin`, `/bin`, `/usr/sbin`, or `/sbin`). On Windows, a suitable python is already available from esy-bash.

## Library flags
## MacOS C++ Compiler

This package attempts to smooth over configuration frustrations by providing specific `library_flags` when built.
When including this library in your `dune` MacOS executables, you'll need to specify `-cc clang++` in your `(flags)` stanza. This is required because Binaryen will throw errors for itself to catch and using `clang++` is the only way to handle them correctly. You can find more info on this [ocaml issue](https://github.com/ocaml/ocaml/issues/10423).

### MacOS
Your stanza could look something like this:

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.
```diff
(executable
(name example)
(public_name example)
(package example)
+ (flags -cc clang++)
(modules example)
(libraries binaryen))
```

These flags likely won't work on other operating systems, so you'll probably need to use `dune-configurator` to vary the flags per platform. You can see an example of this in our [tests/](./tests/dune).

## Static Linking

### Windows
If you are planning to create portable binaries for Windows, it will try to find Cygwin/MinGW locations in your `PATH`. To avoid this, you probably want to add this to your `(executable)` stanzas:

```diff
(executable
(name example)
(public_name example)
(package example)
+ (flags (:standard -ccopt -- -ccopt -static))
(modules example)
(libraries binaryen))
```

On Windows, this package assumes libbinaryen is built under MinGW and applies the flags `-ccopt -- -ccopt -static` to the built library.
These flags might not work on other operating systems (like MacOS), so you'll probably need to use `dune-configurator` to vary the flags per platform. You can see an example of this in our [tests/](./tests/dune).

## Contributing

Expand Down
8 changes: 0 additions & 8 deletions config/dune

This file was deleted.

10 changes: 4 additions & 6 deletions dune
Expand Up @@ -2,8 +2,6 @@
(name libbinaryen_c)
(public_name libbinaryen.c)
(foreign_archives binaryen)
(library_flags
(:include ./config/library_flags.sexp))
(c_library_flags :standard -lstdc++ -lpthread)
(install_c_headers binaryen-c))

Expand Down Expand Up @@ -43,7 +41,7 @@
-DBUILD_STATIC_LIB=ON
-DCMAKE_BUILD_TYPE=Release
-DCMAKE_INSTALL_PREFIX=binaryen)
(run cmake --build binaryen --config Release)
(run cmake --build binaryen --config Release -- -j4)
(copy binaryen/lib/libbinaryen.a libbinaryen.a)))))

(rule
Expand All @@ -68,7 +66,7 @@
-DBUILD_STATIC_LIB=OFF
-DCMAKE_BUILD_TYPE=Release
-DCMAKE_INSTALL_PREFIX=binaryen)
(run cmake --build binaryen --config Release)
(run cmake --build binaryen --config Release -- -j4)
(copy binaryen/lib/libbinaryen.dylib dllbinaryen.so)))))

(rule
Expand All @@ -95,7 +93,7 @@
-DBUILD_STATIC_LIB=OFF
-DCMAKE_BUILD_TYPE=Release
-DCMAKE_INSTALL_PREFIX=binaryen)
(run cmake --build binaryen --config Release)
(run cmake --build binaryen --config Release -- -j4)
(copy binaryen/lib/libbinaryen.so dllbinaryen.so)))))

(rule
Expand All @@ -121,5 +119,5 @@
-DBUILD_STATIC_LIB=OFF
-DCMAKE_BUILD_TYPE=Release
-DCMAKE_INSTALL_PREFIX=binaryen)
(run cmake --build binaryen --config Release)
(run cmake --build binaryen --config Release -- -j4)
(copy binaryen/bin/libbinaryen.dll dllbinaryen.dll)))))

0 comments on commit a89fad6

Please sign in to comment.