Skip to content

Support building onig on wasm32-unknown-unknown target#115

Closed
lopopolo wants to merge 3 commits intorust-onig:masterfrom
artichoke:wasm3
Closed

Support building onig on wasm32-unknown-unknown target#115
lopopolo wants to merge 3 commits intorust-onig:masterfrom
artichoke:wasm3

Conversation

@lopopolo
Copy link
Copy Markdown
Contributor

This PR adds support for the wasm32-unknown-unknown target to onig and onig_sys crates.

This currently does not produce a useful artifact due to rust-lang/rust#63629, but it builds successfully when supplying C stdlib headers that support the target. For example, using the emscipten headers and clang-9:

artichoke@a2ab9c0410ee:/app$ clang --version
clang version 9.0.0-svn366197-1~exp1+0~20190716095603.167~1.gbp7d3830 (trunk)
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/local/bin
artichoke@a2ab9c0410ee:/app$ rustc --version --verbose
rustc 1.38.0-nightly (6e310f2ab 2019-07-07)
binary: rustc
commit-hash: 6e310f2abae97323ca1d5469657b83aa1a9407e0
commit-date: 2019-07-07
host: x86_64-unknown-linux-gnu
release: 1.38.0-nightly
LLVM version: 8.0
artichoke@a2ab9c0410ee:/app$ env CFLAGS="-I/app/libc" cargo build --target wasm32-unknown-unknown
warning: couldn't execute `llvm-config --prefix` (error: No such file or directory (os error 2))
warning: set the LLVM_CONFIG_PATH environment variable to a valid `llvm-config` executable
    Finished dev [unoptimized + debuginfo] target(s) in 3.22s

To achieve this goal, this PR pulls in a new version of oniguruma that has this PR kkos/oniguruma#150 which introduces a macro to disable computed gotos which clang-8 cannot compile for wasm32-unknown-unknown.

This PR also refactors build.rs to be more robust to "non-exotic targets".

Setting this define enables oniguruma to build for wasm32-unknown-unknown target
under clang-8.
- Unwrap env variables only when required.
- Handle cases where `CARGO_CFG_TARGET_FAMILY` is not set. There is no
  need to unwrap this env var since we are only using it to optionally
  set some compiler flags.
- For wasm builds, define `ONIG_DISABLE_DIRECT_THREADING`. This is a new
  macro in oniguruma which disables computed gotos, which are unsupported
  by clang-8 when compiling to wasm targets.
- Override `ONIG_EXTERN` to set function visibility for wasm builds. By
  default, functions are not exported under wasm targets. This flag
  ensures all functions in the static onig library are marked exported.
Building a cdylib enables generating a wasm bundle for wasm targets
@lopopolo
Copy link
Copy Markdown
Contributor Author

This is the followup to GH-106.

@lopopolo
Copy link
Copy Markdown
Contributor Author

The only failing build is Rust 1.32.0

This PR uses an if let pattern in build.rs which requires Rust 1.33.0. I based my ability to use this feature on d843449 which says the minimum Rust version is 1.33.0.

@lopopolo
Copy link
Copy Markdown
Contributor Author

Oh, the minimum supported Rust version varies by OS. I find that confusing.

@lopopolo
Copy link
Copy Markdown
Contributor Author

I'll maintain this branch on my fork. If you are interested in merging this, please reopen this issue.

@lopopolo lopopolo closed this Sep 16, 2019
@iwillspeak
Copy link
Copy Markdown
Collaborator

Sorry for ignoring this PR. I've been busy for quite some time with other life things. I'll re-open this and merge it after other refactorings of bindgen useage are merged.

@iwillspeak iwillspeak self-assigned this Oct 2, 2019
@iwillspeak iwillspeak mentioned this pull request Oct 2, 2019
@iwillspeak
Copy link
Copy Markdown
Collaborator

I've had to create a new PR for this. Apparently you can't re-open a PR if it is force-pushed when closed. :-/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants