Skip to content

Add developer guideline notes for C/C++ bindings generation #688

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

Merged
merged 5 commits into from
Sep 14, 2020

Conversation

TheBlueMatt
Copy link
Collaborator

No description provided.

@codecov
Copy link

codecov bot commented Sep 11, 2020

Codecov Report

Merging #688 into main will increase coverage by 13.44%.
The diff coverage is n/a.

Impacted file tree graph

@@             Coverage Diff             @@
##             main     #688       +/-   ##
===========================================
+ Coverage   78.40%   91.85%   +13.44%     
===========================================
  Files          55       35       -20     
  Lines       27568    19911     -7657     
===========================================
- Hits        21616    18290     -3326     
+ Misses       5952     1621     -4331     
Impacted Files Coverage Δ
lightning/src/util/errors.rs 64.70% <0.00%> (-16.69%) ⬇️
lightning/src/ln/features.rs 89.37% <0.00%> (-7.76%) ⬇️
lightning/src/util/byte_utils.rs 93.75% <0.00%> (-6.25%) ⬇️
lightning/src/util/ser.rs 86.85% <0.00%> (-3.61%) ⬇️
lightning/src/ln/peer_channel_encryptor.rs 93.35% <0.00%> (-1.87%) ⬇️
lightning/src/ln/channelmonitor.rs 94.99% <0.00%> (-1.76%) ⬇️
lightning/src/util/events.rs 27.58% <0.00%> (-1.45%) ⬇️
lightning/src/util/transaction_utils.rs 98.64% <0.00%> (-1.36%) ⬇️
lightning/src/util/enforcing_trait_impls.rs 98.76% <0.00%> (-1.24%) ⬇️
lightning/src/util/test_utils.rs 85.00% <0.00%> (-1.20%) ⬇️
... and 44 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 253af8d...3fa0548. Read the comment docs.

Copy link

@ariard ariard left a comment

Choose a reason for hiding this comment

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

Thanks to add this!

CONTRIBUTING.md Outdated
pull requests keep the bindings up to date (and, thus, pass the bindings_check CI run). If you
wish to ensure your PR passes the bindings generation phase, you should run the `genbindings.sh`
script in the top of the directory tree to generate, build, and test C bindings on your local
system.
Copy link

Choose a reason for hiding this comment

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

How to test C bindings is explained in lightning-c-bindings/README.md, even if is the explanation is still experimental itself ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

genbindings.sh does test the bindings :)

@TheBlueMatt TheBlueMatt force-pushed the 2020-09-dev-docs branch 2 times, most recently from 77b35bb to 83b18e7 Compare September 11, 2020 23:35
@TheBlueMatt
Copy link
Collaborator Author

Also fixed it so that we really dont require bindings to pass pre-merge/cargo test. Especially given ##649, we dont want to have to wait just for new bindings generation.

@TheBlueMatt
Copy link
Collaborator Author

It looks like honggfuzz upstream is broken. Lets see what they say rust-fuzz/honggfuzz-rs#44

@julianknutsen
Copy link

julianknutsen commented Sep 12, 2020

Tested and confirmed that cargo doc works on 450391c. #689

@TheBlueMatt
Copy link
Collaborator Author

honggfuzz got a new release and is working again.

Copy link

@julianknutsen julianknutsen left a comment

Choose a reason for hiding this comment

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

What are your thoughts on genbindings.sh doing the building and testing long-term? Will there be a C test suite as this gets more mature and stable or will that be covered by more of the other language bindings that build on top of this with their own testing?

you likely don't need to worry about them, and during their early experimental phase we are not
requiring that pull requests keep the bindings up to date (and, thus, pass the bindings_check CI
run). If you wish to ensure your PR passes the bindings generation phase, you should run the
`genbindings.sh` script in the top of the directory tree to generate, build, and test C bindings on

Choose a reason for hiding this comment

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

I noticed a lot of the build process uses shell scripts. What does the supported build platform matrix look like? Is all the tooling mostly focused on mac/linux or are there Windows use cases?

In general, how much of the entire project (lightning/tokio/c-bindings/etc) should be buildable on Mac and Windows? Trying to wrap my head around the supported platform matrix.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yea, I don't think we have anyone working with/spending too much time on Windows, but if you're less interested in testing and only want a shared library build, just running cargo build in c-lightning-bindings should work. Eventually it probably makes sense to spend some time on Windows but it hasn't been a priority.

you likely don't need to worry about them, and during their early experimental phase we are not
requiring that pull requests keep the bindings up to date (and, thus, pass the bindings_check CI
run). If you wish to ensure your PR passes the bindings generation phase, you should run the
`genbindings.sh` script in the top of the directory tree to generate, build, and test C bindings on
Copy link

@julianknutsen julianknutsen Sep 12, 2020

Choose a reason for hiding this comment

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

Running genbindings.sh generates a few files that aren't in the .gitignore. Is it worth adding them?

c-bindings-gen/target/
lightning-c-bindings/target/

Should this end up in target/ or .gitignore?
lightning-c-bindings/include/lightningpp.hpp

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

target should definitely be in .gitignore, but at a high level our goal here is to check in the C bindings that are generated so that users don't theoretically need to run the generation scripts (ie can just cd lightning-c-bindings && cargo test). CI tests that the versions in git are the same as the ones that are auto-generated.

Choose a reason for hiding this comment

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

Ok. That makes sense why lightningpp.hpp is outside of target. Thanks for the background.

Choose a reason for hiding this comment

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

Verified the target files are now ignored in 74cd3c9. Thanks!

@@ -127,6 +120,8 @@ jobs:
apt-get -y install cargo valgrind lld git g++ clang
- name: Checkout source code
uses: actions/checkout@v2
- name: Sanity test bindings

Choose a reason for hiding this comment

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

An alternative could be to also run genbindings.sh with the continue-on-error keyword. That way we could still see the output if it gets out of sync, but it doesn't prevent the job from failing.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Hmm, I'm not sure what the value would be - if the bindings fall out of sync, genbindings.sh isn't going to give you a lot of useful output that cargo check isn't? I added it in part to short-circuit all the /stuff/ if things are stale anyway (because the intent would be one of the full-timers or regular contributors can go fix it later).

Copy link

@julianknutsen julianknutsen Sep 13, 2020

Choose a reason for hiding this comment

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

Understanding the lifecycle for the generated code makes this clearer. I guess you would have to pair genbindings.sh with a git diff or something to show that "hey it's out of sync" since cargo check doesn't always identify mismatches, but that isn't really the goal so it seems fine as-is.

Copy link
Collaborator Author

@TheBlueMatt TheBlueMatt Sep 13, 2020

Choose a reason for hiding this comment

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

The build script a bit further doesn't does do some git diff stuff (though noting that the bindings aren't fully deterministic in terms of ordering, so letting that fluctuate a bit), but cargo check is a much quicker way to get that.

genbindings.sh Outdated
@@ -48,21 +48,21 @@ fi
# Finally, sanity-check the generated C and C++ bindings with demo apps:

# Naively run the C demo app:
gcc -Wall -g -pthread demo.c ../target/debug/liblightning.a -ldl
gcc -Wall -g -pthread demo.c target/debug/liblightning.a -ldl

Choose a reason for hiding this comment

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

What do you think about splitting out the names, and paths into variables? I don't expect this file to change all that much, but it deduplicates a lot of the path names.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Sure, I mean happy to do whatever, not sure its gonna change much independently though.

@ariard
Copy link

ariard commented Sep 14, 2020

ACK 74cd3c9

genbindings.sh is locally working.

Until we get the bindings generation process super stable, let the
bindings get stale with respect to the main repo while still letting
`cargo check` pass.
@TheBlueMatt
Copy link
Collaborator Author

Squashed the one fixup commit.

@TheBlueMatt TheBlueMatt merged commit baa58c1 into lightningdevkit:main Sep 14, 2020
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.

4 participants