Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Remove library_flags & only specify c_library_flags where needed #41

Merged
merged 2 commits into from Jan 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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)))))