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

feat: compile to WebAssembly to eliminate native dependencies #8

Merged
merged 39 commits into from
Sep 26, 2022

Conversation

dsanders11
Copy link
Contributor

@dsanders11 dsanders11 commented Sep 9, 2022

Still WIP, but this is a major rewrite of the project to use Emscripten to compile to WebAssembly and ship as an npm package. Roughly I'd say the current state is 80% there.

Needs emsdk to be installed on the system to work. I considered adding it to the vendorpull config, but that repo is over a gigabyte so for now leaving it as an external development dependency.

The basics machinery works, although it has only been tested on macOS so far , and the test is currently failing. I think there may be a LIEF issue causing that, as there are some codepaths which trying to detect the system and use that to determine page size for example, but further investigation needs to be done to determine root cause. (Root cause was in LIEF, patch created and PR opened upstream).

There's a couple of high level goals driving the decisions in this PR:

  • Eliminate Makefiles
  • Eliminate Bash scripts (use zx module instead)
  • Use a JS test framework (mocha in this case) to allow for more detailed test coverage

Still to do:

  • Update README
  • ELF
  • PE

Closes #10, #15, #16, #17.

@dsanders11 dsanders11 marked this pull request as draft September 9, 2022 15:28
@dsanders11 dsanders11 force-pushed the feat/webassembly-cli branch 8 times, most recently from 563f4a7 to 5b95dfe Compare September 10, 2022 03:16
@dsanders11
Copy link
Contributor Author

Some CI jobs are failing for various reasons currently:

  • Tests on Debian - seems to be a Node.js issue, unexpectedly. Might be a version issue.
  • Build on Alpine - an unexpected error about emcc
  • Tests on Windows - an issue with paths

@dsanders11
Copy link
Contributor Author

For testing this PR locally, it's useful to use npm link and then use the CLI directly to get as close to the published package as possible and find any issues there.

Copy link
Contributor

@RaisinTen RaisinTen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this going to enable us to generate a single postject.wasm file that would run on all platforms?

RaisinTen added a commit that referenced this pull request Sep 20, 2022
This change updates lief to
lief-project/LIEF@b183666.

This contains lief-project/LIEF#780, which is
a requirement for #8.

Signed-off-by: Darshan Sen <[email protected]>
@RaisinTen RaisinTen mentioned this pull request Sep 20, 2022
RaisinTen added a commit that referenced this pull request Sep 20, 2022
This change updates lief to
lief-project/LIEF@b183666.

This contains lief-project/LIEF#780, which is
a requirement for #8.

Signed-off-by: Darshan Sen <[email protected]>
RaisinTen added a commit that referenced this pull request Sep 20, 2022
This change updates lief to
lief-project/LIEF@b183666.

This contains lief-project/LIEF#780, which is
a requirement for #8.

Signed-off-by: Darshan Sen <[email protected]>
@dsanders11
Copy link
Contributor Author

Is this going to enable us to generate a single postject.wasm file that would run on all platforms?

See these lines in scripts/build.mjs for the artifacts, or take a look at the CircleCI job artifacts. There's a .wasm file, and two .js files (the CLI interface is easiest to write in JS), and yes it will run on all platforms.

@RaisinTen
Copy link
Contributor

RaisinTen commented Sep 22, 2022

Okay, I was wondering because we were generating separate postject.wasm files for all platforms we run the build step on, so it felt unclear which one of those we were supposed to use. I'm guessing unifying all of these to generate a single postject.wasm artifact is something that would get addressed by this PR?

@dsanders11 dsanders11 force-pushed the feat/webassembly-cli branch 3 times, most recently from 0ddb353 to 22d52cc Compare September 23, 2022 03:10
.circleci/config.yml Outdated Show resolved Hide resolved
Copy link
Contributor

@RaisinTen RaisinTen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

did a light round of review on things that are unlikely to drastically change in further commits

src/main.js Outdated Show resolved Hide resolved
src/postject.cpp Outdated Show resolved Hide resolved
src/postject.cpp Outdated Show resolved Hide resolved
test/cli.mjs Show resolved Hide resolved
test/cli.mjs Show resolved Hide resolved
@dsanders11
Copy link
Contributor Author

Ready for final review.

A couple of things will be done in follow-up PRs:

@dsanders11 dsanders11 marked this pull request as ready for review September 24, 2022 00:17
@dsanders11 dsanders11 linked an issue Sep 24, 2022 that may be closed by this pull request
@dsanders11 dsanders11 changed the title wip: compile to WebAssembly to eliminate native dependencies feat: compile to WebAssembly to eliminate native dependencies Sep 24, 2022
Copy link
Contributor

@RaisinTen RaisinTen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@dsanders11 Can you respond to #8 (comment)?

@RaisinTen
Copy link
Contributor

This would be needed for #14, merging. Maybe my comment will get addressed while resolving that issue?

@RaisinTen RaisinTen merged commit 1fa49dd into main Sep 26, 2022
@RaisinTen RaisinTen deleted the feat/webassembly-cli branch September 26, 2022 06:03
@dsanders11
Copy link
Contributor Author

Okay, I was wondering because we were generating separate postject.wasm files for all platforms we run the build step on, so it felt unclear which one of those we were supposed to use. I'm guessing unifying all of these to generate a single postject.wasm artifact is something that would get addressed by this PR?

@RaisinTen, I'm not sure what the proposed "unifying" would look like - the build jobs are still going to generate the artifacts regardless. I don't think it hurts to publish them for all build jobs, and if there's ever a discrepancy between them it would be easy to compare.

Since the artifacts are the same for all platforms, we should just publish from whichever platform is most convenient.

@RaisinTen
Copy link
Contributor

Since the artifacts are the same for all platforms, we should just publish from whichever platform is most convenient.

@dsanders11 yes, that's exactly what I'm doing in #30. I chose linux. :)

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.

Compile Postject to WebAssembly Run resource injection tests on Windows
2 participants