-
Notifications
You must be signed in to change notification settings - Fork 702
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
Improve bazel example #776
base: master
Are you sure you want to change the base?
Improve bazel example #776
Conversation
@@ -25,13 +25,16 @@ emsdk_emscripten_deps() | |||
|
|||
Put the following lines into your `.bazelrc`: | |||
``` | |||
build:wasm --crosstool_top=//emscripten_toolchain:everything | |||
build:wasm --crosstool_top=@emsdk//emscripten_toolchain:everything |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was a bug.
bazel/test_external/BUILD
Outdated
@@ -3,6 +3,9 @@ load("@emsdk//emscripten_toolchain:wasm_rules.bzl", "wasm_cc_binary") | |||
cc_binary( | |||
name = "hello-world", | |||
srcs = ["hello-world.cc"], | |||
linkopts = [ | |||
"--bind", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Required for embind.
https://emscripten.org/docs/porting/connecting_cpp_and_javascript/embind.html
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this not formatted on one line like srcs
above? Is this the bazel style?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
linkopts = ["--bind"],
works as well. Both comply with buildifier
.
bazel/test_external/.gitignore
Outdated
@@ -0,0 +1,2 @@ | |||
bazel-* | |||
dist/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
missing newline
bazel/test_external/hello-world.cc
Outdated
std::cout << "hello world!" << std::endl; | ||
std::cout << "start main function" << std::endl; | ||
sayHello(); | ||
std::cout << "end main function" << std::endl; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any not include a main function in the program in both cases? This change seem to turn this example from the executable into a library. Any particular reason for doing that?
Don't we actually run the result of building this? (under node?) We probably should.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Both are fine. The example illustrates that we can use EMSCRIPTEN_BINDINGS
optionally.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I updated it so it looks more like what you are looking for.
bazel/test_external/BUILD
Outdated
@@ -3,6 +3,9 @@ load("@emsdk//emscripten_toolchain:wasm_rules.bzl", "wasm_cc_binary") | |||
cc_binary( | |||
name = "hello-world", | |||
srcs = ["hello-world.cc"], | |||
linkopts = [ | |||
"--bind", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this not formatted on one line like srcs
above? Is this the bazel style?
Thanks for the PR! I think the changes to bazel/README.md are wonderful and should be merged. The rest I'm more reluctant to accept. I don't think there's value in adding embind to the hello world example, or in removing the main function when building under emscripten. The addition of bazel/test_external/.bazelrc isn't necessary for the example, and it's already covered by bazel/bazelrc and explained in bazel/README.md. I'd also prefer having a single README instead of multiple in nested directories because there's not so much information that it needs to be split up, and it's easier to maintain with only one. Again, thank you for your contribution. I'm happy to merge the changes to bazel/README.md if you'd like to revert the rest. I'm also happy to have further discussion concerning the other changes. |
Sure. The key addition to the example is that it demonstrates how to pass opt flag to the compiler to bind c functions to javascript. These should be helpful addition to the example for a majority of the users. I highly question that this would make this more difficult to maintain.
|
Remove |
@@ -0,0 +1,3 @@ | |||
build:wasm --crosstool_top=@emsdk//emscripten_toolchain:everything |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
without these, the example would not work for :hello-world
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's ok for the example to not work with --config=wasm
right out of the box; we'd rather promote the use of wasm_cc_binary
as it produces more useful output anyway. Also, the readme covers adding the appropriate lines to your own .bazelrc file, which would enable --config=wasm
builds to function. The big thing here I want to avoid is having this file be identical to bazel/bazelrc and having to keep them both in sync.
What about keeping hello world as is and adding a new test (hello_embind or test_embind?) that adds this more complex stuff? |
7d53b20
to
d496965
Compare
Sure. Removed all changes to the example. |
Passing linkopts using bazel is not unique to this toolchain. This is something bazel documentation covers just fine. Similarly, using embind with and without this toolchain is the same, and emscripten's embind documentation covers how to use this.
The more duplication of documentation there is, the more places that need to be updated when something changes, and the more likely it is that they become out of sync, confusing users. I would be in favor of linking to other documentation instead. |
@walkingeyerobot So you want to keep the example to be broken with respect to with the example |
I already removed all changes to the example. The changes remained:
|
The example is not broken, but I would like to keep it the way it is.. The user can either build the |
The issue under discussions are so minor. Please feel free to push your modifications to the PR as you see necessary. |
…p-llvm-16 Emscripten 3.1.56 (llvm 19.x)
Added emscripten bindings to bazel examples.