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

add WebAssembly support #28

Merged
merged 3 commits into from
Nov 27, 2021
Merged

Conversation

williballenthin
Copy link
Contributor

@williballenthin williballenthin commented Nov 26, 2021

This PR makes some minor, non-breaking changes that enable building Rust libraries that depend on zydis-rs to WebAssembly. Its really cool how little was needed to make this happen!

To make use of this PR, zyantific/zycore-c#40 and zyantific/zydis#277 need to be merged. I didn't attempt any of these changes here, since I'm not familiar enough with your release process. However, I have a temporary branch that you can reference from Cargo.toml: nightly/wasm.

In summary, this PR does two things:

  • introduce features for nolibc and wasm, and
  • tweaks a datatype to fit within the wasm32 isize range

Unfortunately, building zydis-rs for WebAssembly is not as trivial as just invoking wasm-pack, but it can be done. Today, the build.rs script invokes the system C/C++ compilers and linker on the zydis-c and zycore libraries, but these tools

  1. usually don't know how to build and link WebAssembly object files, and
  2. the gcc/clang-generated object files may not be ABI-compatible with rustc-generated object files.

However, I found that the trick from here to use the Zig compiler instead of gcc/clang to work perfectly. I've updated my demo project zydis-wasm to show this in action.

@th0rex
Copy link
Collaborator

th0rex commented Nov 27, 2021

Thanks, LGTM. I think I'll merge these changes now, instead of waiting for the zydis/zycore PRs to be merged, they are independent anyways. I think updating zydis-c should be relatively straight forward, there shouldn't have been any breaking changes (yet), but I'll do that in a follow up commit (or feel free to do it if you want to/if your branch already works).

@th0rex th0rex merged commit 5e9da5a into zyantific:master Nov 27, 2021
@williballenthin williballenthin deleted the feature/wasm branch November 27, 2021 18:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants