Bindings Updates for #681 and more Clones - #749

Merged
TheBlueMatt merged 12 commits into
lightningdevkit:mainfrom
TheBlueMatt:2020-11-bindings-clones
Nov 23, 2020
Merged

Bindings Updates for #681 and more Clones#749
TheBlueMatt merged 12 commits into
lightningdevkit:mainfrom
TheBlueMatt:2020-11-bindings-clones

Conversation

@TheBlueMatt

Copy link
Copy Markdown
Collaborator

There was one trivial bit to fix for #681, but more importantly this adds much better and broader support for calling clone from the C bindings, which we rely on extensively in the Java bindings.

@TheBlueMattTheBlueMatt added this to the 0.0.12 milestone Nov 13, 2020

@jkczyzjkczyz left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Not sure if it is related, but I'm getting an error when running genbindings.sh on macOS:

+ cargo rustc -v --release -- -C lto
Compiling cc v1.0.65
Compiling bitcoin_hashes v0.8.0
Compiling bech32 v0.7.2
Running `rustc --crate-name cc --edition=2018 /Users/jkczyz/.cargo/registry/src/github.com-1ecc6299db9ec823/cc-1.0.65/src/lib.rs --error-format=json --json=diagnostic-rendered-ansi --crate-type lib --emit=dep-info,metadata,link -C opt-level=3 -Cembed-bitcode=no -C metadata=00dcc370fd0f6eb8 -C extra-filename=-00dcc370fd0f6eb8 --out-dir /Users/jkczyz/src/rust-lightning-review/lightning-c-bindings/target/release/deps -L dependency=/Users/jkczyz/src/rust-lightning-review/lightning-c-bindings/target/release/deps --cap-lints allow`
Running `rustc --crate-name bitcoin_hashes /Users/jkczyz/.cargo/registry/src/github.com-1ecc6299db9ec823/bitcoin_hashes-0.8.0/src/lib.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts --crate-type lib --emit=dep-info,metadata,link -C opt-level=3 -Cembed-bitcode=no --cfg 'feature="default"' --cfg 'feature="std"' -C metadata=3f72b8b01c4f2e37 -C extra-filename=-3f72b8b01c4f2e37 --out-dir /Users/jkczyz/src/rust-lightning-review/lightning-c-bindings/target/release/deps -L dependency=/Users/jkczyz/src/rust-lightning-review/lightning-c-bindings/target/release/deps --cap-lints allow`
Running `rustc --crate-name bech32 /Users/jkczyz/.cargo/registry/src/github.com-1ecc6299db9ec823/bech32-0.7.2/src/lib.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts --crate-type lib --emit=dep-info,metadata,link -C opt-level=3 -Cembed-bitcode=no -C metadata=848e3766e44cacd7 -C extra-filename=-848e3766e44cacd7 --out-dir /Users/jkczyz/src/rust-lightning-review/lightning-c-bindings/target/release/deps -L dependency=/Users/jkczyz/src/rust-lightning-review/lightning-c-bindings/target/release/deps --cap-lints allow`
Compiling secp256k1-sys v0.2.0
Running `rustc --crate-name build_script_build /Users/jkczyz/.cargo/registry/src/github.com-1ecc6299db9ec823/secp256k1-sys-0.2.0/build.rs --error-format=json --json=diagnostic-rendered-ansi --crate-type bin --emit=dep-info,link -C opt-level=3 -Cembed-bitcode=no --cfg 'feature="std"' -C metadata=73b76d4b12ae7a7f -C extra-filename=-73b76d4b12ae7a7f --out-dir /Users/jkczyz/src/rust-lightning-review/lightning-c-bindings/target/release/build/secp256k1-sys-73b76d4b12ae7a7f -L dependency=/Users/jkczyz/src/rust-lightning-review/lightning-c-bindings/target/release/deps --extern cc=/Users/jkczyz/src/rust-lightning-review/lightning-c-bindings/target/release/deps/libcc-00dcc370fd0f6eb8.rlib --cap-lints allow`
Running `/Users/jkczyz/src/rust-lightning-review/lightning-c-bindings/target/release/build/secp256k1-sys-73b76d4b12ae7a7f/build-script-build`
Running `rustc --crate-name secp256k1_sys /Users/jkczyz/.cargo/registry/src/github.com-1ecc6299db9ec823/secp256k1-sys-0.2.0/src/lib.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts --crate-type lib --emit=dep-info,metadata,link -C opt-level=3 -Cembed-bitcode=no --cfg 'feature="std"' -C metadata=caf2e22195643b8f -C extra-filename=-caf2e22195643b8f --out-dir /Users/jkczyz/src/rust-lightning-review/lightning-c-bindings/target/release/deps -L dependency=/Users/jkczyz/src/rust-lightning-review/lightning-c-bindings/target/release/deps --cap-lints allow -L native=/Users/jkczyz/src/rust-lightning-review/lightning-c-bindings/target/release/build/secp256k1-sys-6ea31cf4a9c94cb1/out -l static=secp256k1`
Compiling secp256k1 v0.18.0
Running `rustc --crate-name secp256k1 /Users/jkczyz/.cargo/registry/src/github.com-1ecc6299db9ec823/secp256k1-0.18.0/src/lib.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts --crate-type lib --emit=dep-info,metadata,link -C opt-level=3 -Cembed-bitcode=no --cfg 'feature="default"' --cfg 'feature="std"' -C metadata=1eabee0c3285b09c -C extra-filename=-1eabee0c3285b09c --out-dir /Users/jkczyz/src/rust-lightning-review/lightning-c-bindings/target/release/deps -L dependency=/Users/jkczyz/src/rust-lightning-review/lightning-c-bindings/target/release/deps --extern secp256k1_sys=/Users/jkczyz/src/rust-lightning-review/lightning-c-bindings/target/release/deps/libsecp256k1_sys-caf2e22195643b8f.rmeta --cap-lints allow -L native=/Users/jkczyz/src/rust-lightning-review/lightning-c-bindings/target/release/build/secp256k1-sys-6ea31cf4a9c94cb1/out`
Compiling bitcoin v0.24.0
Running `rustc --crate-name bitcoin /Users/jkczyz/.cargo/registry/src/github.com-1ecc6299db9ec823/bitcoin-0.24.0/src/lib.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts --crate-type lib --emit=dep-info,metadata,link -C opt-level=3 -Cembed-bitcode=no -C metadata=e1b66b4ed9a90379 -C extra-filename=-e1b66b4ed9a90379 --out-dir /Users/jkczyz/src/rust-lightning-review/lightning-c-bindings/target/release/deps -L dependency=/Users/jkczyz/src/rust-lightning-review/lightning-c-bindings/target/release/deps --extern bech32=/Users/jkczyz/src/rust-lightning-review/lightning-c-bindings/target/release/deps/libbech32-848e3766e44cacd7.rmeta --extern bitcoin_hashes=/Users/jkczyz/src/rust-lightning-review/lightning-c-bindings/target/release/deps/libbitcoin_hashes-3f72b8b01c4f2e37.rmeta --extern secp256k1=/Users/jkczyz/src/rust-lightning-review/lightning-c-bindings/target/release/deps/libsecp256k1-1eabee0c3285b09c.rmeta --cap-lints allow -L native=/Users/jkczyz/src/rust-lightning-review/lightning-c-bindings/target/release/build/secp256k1-sys-6ea31cf4a9c94cb1/out`
Compiling lightning v0.0.11 (/Users/jkczyz/src/rust-lightning-review/lightning)
Running `rustc --crate-name lightning /Users/jkczyz/src/rust-lightning-review/lightning/src/lib.rs --error-format=json --json=diagnostic-rendered-ansi --crate-type lib --emit=dep-info,metadata,link -C opt-level=3 -Cembed-bitcode=no -C metadata=79da2e4794c19ffc -C extra-filename=-79da2e4794c19ffc --out-dir /Users/jkczyz/src/rust-lightning-review/lightning-c-bindings/target/release/deps -L dependency=/Users/jkczyz/src/rust-lightning-review/lightning-c-bindings/target/release/deps --extern bitcoin=/Users/jkczyz/src/rust-lightning-review/lightning-c-bindings/target/release/deps/libbitcoin-e1b66b4ed9a90379.rmeta -L native=/Users/jkczyz/src/rust-lightning-review/lightning-c-bindings/target/release/build/secp256k1-sys-6ea31cf4a9c94cb1/out`
Compiling lightning-c-bindings v0.0.1 (/Users/jkczyz/src/rust-lightning-review/lightning-c-bindings)
Running `rustc --crate-name ldk --edition=2018 src/lib.rs --error-format=json --json=diagnostic-rendered-ansi --crate-type staticlib --crate-type cdylib --emit=dep-info,link -C opt-level=3 -Cembed-bitcode=no -C lto -C metadata=fe50c7fd2ceda483 --out-dir /Users/jkczyz/src/rust-lightning-review/lightning-c-bindings/target/release/deps -L dependency=/Users/jkczyz/src/rust-lightning-review/lightning-c-bindings/target/release/deps --extern bitcoin=/Users/jkczyz/src/rust-lightning-review/lightning-c-bindings/target/release/deps/libbitcoin-e1b66b4ed9a90379.rlib --extern lightning=/Users/jkczyz/src/rust-lightning-review/lightning-c-bindings/target/release/deps/liblightning-79da2e4794c19ffc.rlib -L native=/Users/jkczyz/src/rust-lightning-review/lightning-c-bindings/target/release/build/secp256k1-sys-6ea31cf4a9c94cb1/out`
error: options `-C embed-bitcode=no` and `-C lto` are incompatible
error: could not compile `lightning-c-bindings`.
Caused by:
process didn't exit successfully: `rustc --crate-name ldk --edition=2018 src/lib.rs --error-format=json --json=diagnostic-rendered-ansi --crate-type staticlib --crate-type cdylib --emit=dep-info,link -C opt-level=3 -Cembed-bitcode=no -C lto -C metadata=fe50c7fd2ceda483 --out-dir /Users/jkczyz/src/rust-lightning-review/lightning-c-bindings/target/release/deps -L dependency=/Users/jkczyz/src/rust-lightning-review/lightning-c-bindings/target/release/deps --extern bitcoin=/Users/jkczyz/src/rust-lightning-review/lightning-c-bindings/target/release/deps/libbitcoin-e1b66b4ed9a90379.rlib --extern lightning=/Users/jkczyz/src/rust-lightning-review/lightning-c-bindings/target/release/deps/liblightning-79da2e4794c19ffc.rlib -L native=/Users/jkczyz/src/rust-lightning-review/lightning-c-bindings/target/release/build/secp256k1-sys-6ea31cf4a9c94cb1/out` (exit code: 1)

Comment threadlightning/src/ln/channelmanager.rs Outdated
@TheBlueMatt
TheBlueMattforce-pushed the 2020-11-bindings-clones branch from 6a3db9c to 674559cCompareNovember 23, 2020 15:29
@TheBlueMatt

Copy link
Copy Markdown
CollaboratorAuthor

No, but Val did note it previously and I wasn't able to reproduce on newer rustc so I forgot about it, sorry about that. I pushed a commit to fix it mostly based on Val's suggested patch at #721 (comment)

@codecov

codecovBot commented Nov 23, 2020

Copy link
Copy Markdown

Codecov Report

Merging #749 (1af6e34) into main (8f10a1d) will decrease coverage by 0.09%.
The diff coverage is 12.50%.

Impacted file tree graph

@@ Coverage Diff @@## main #749 +/- ##
==========================================
- Coverage 91.39% 91.29% -0.10% 
==========================================
Files 37 37 Lines 22249 22274 +25 ==========================================
+ Hits 20334 20335 +1 - Misses 1915 1939 +24 
Impacted FilesCoverage Δ
lightning/src/ln/chan_utils.rs95.66% <0.00%> (-0.31%)⬇️
lightning/src/ln/channelmanager.rs84.95% <0.00%> (-0.41%)⬇️
lightning/src/ln/msgs.rs89.60% <0.00%> (-0.48%)⬇️
lightning/src/routing/router.rs95.71% <0.00%> (-0.96%)⬇️
lightning/src/util/events.rs24.54% <0.00%> (ø)
lightning/src/chain/channelmonitor.rs95.44% <100.00%> (ø)
lightning/src/ln/functional_tests.rs96.96% <0.00%> (+0.01%)⬆️

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 8f10a1d...9fe3124. Read the comment docs.

…gdevkit#681)
Previously we'd ignored generic arguments in traits, leading to
bogus code generation after the Persister trait was added in lightningdevkit#681.
This adds minimal support for it, fixing code generation on latest
upstream.
When the only reference to the transaction bytes is via
Transaction::data, my understanding of the C const rules is that
it would then be invalid to write to it. While its unlikely this
would ever pose an issue, its not hard to simply make it *mut, so
we do that here.
CVecTempl previously called Vec.clone_from_slice() on a
newly-allocated Vec, which immediately panics as
[T].clone_from_slice() requires that the Vec/target slice already
has the same length as the source slice. This should have been
Vec.extend_from_slice() which exhibits the correct behavior.
This somewhat assumes that every public enum implements clone in
some way, but that is currently the case.
There is no reason not to and Clone can be useful especially in the
bindings context.
When a trait is required to implement eq/clone (eg in the case of
`SocketDescriptor`), the generated trait struct contains an
eq/clone function which takes a `this_arg` pointer. Since the trait
object can always be read to get the `this_arg` pointer, there is
no loss of generality to pass the trait object itself, and it
provides a bit more flexibility when the trait could be one of
several implementations (which we use in the Java higher-level
bindings).
Newer versions of cargo broke `cargo rustc -- -Clto` by passing
`-Cembed-bitcode=no` even in `--release`. Its somewhat unclear why
this is still the case on latest cargo given it broke, at least,
compilation of Firefox, as discovered by Val at [1]. We take the
approach they used there, even though they later walked it back [2]
but the issues noted there, especially in [3] don't seem
particularly concerning in our case.
[1] https://bugzilla.mozilla.org/show_bug.cgi?id=1640982
[2] https://bugzilla.mozilla.org/show_bug.cgi?id=1654465
[3] https://bugzilla.mozilla.org/show_bug.cgi?id=1654465#c5
@TheBlueMatt
TheBlueMattforce-pushed the 2020-11-bindings-clones branch from 674559c to 9fe3124CompareNovember 23, 2020 16:12
@TheBlueMatt

Copy link
Copy Markdown
CollaboratorAuthor

Also rebased on upstream git which changed ever so slightly.

@valentinewallacevalentinewallace left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM! Thanks for the fixes on genbindings, that seems to have worked for me (haven't figured out how to get the right clang version so haven't tested out the address-sanitizer parts, but otherwise the headers are generated 💪)

writeln!(w, "#[no_mangle]\npub extern \"C\" fn {}_free(this_ptr: {}) {{ }}", e.ident, e.ident).unwrap();
}
writeln!(w, "#[no_mangle]").unwrap();
writeln!(w, "pub extern \"C\" fn {}_clone(orig: &{}) -> {} {{", e.ident, e.ident, e.ident).unwrap();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Just to confirm, it's fine that some pub(enum)s in RL don't implement Clone?

Copy link
Copy Markdown
CollaboratorAuthor

Choose a reason for hiding this comment

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

Hmm, I mean I guess we should have them match, but its not an issue per se currently - if all the fields support Clone (as they would have to for the bindings crate to not fail to compile), then exposing a Clone to bindings seems fine.

@TheBlueMatt
TheBlueMatt merged commit 52673d4 into lightningdevkit:mainNov 23, 2020
@TheBlueMatt

Copy link
Copy Markdown
CollaboratorAuthor

Taking cause we need to get 0.0.12 out the door.

Sign up for freeto 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.

3 participants

@TheBlueMatt@jkczyz@valentinewallace
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Add copy buttons to all
 blocks\n(function() {\n function addCopyButtons() {\n document.querySelectorAll('pre code').forEach(function(codeBlock) {\n if (codeBlock.parentElement.hasAttribute('data-copy-added')) return;\n codeBlock.parentElement.setAttribute('data-copy-added', 'true');\n \n var btn = document.createElement('button');\n btn.textContent = 'Copy';\n btn.style.cssText = 'position:absolute;top:4px;right:4px;padding:2px 8px;font-size:11px;background:#4ecdc4;border:none;border-radius:4px;color:#1a1a2e;cursor:pointer;opacity:0.7;transition:opacity 0.2s;';\n btn.onmouseover = function() { this.style.opacity = '1'; };\n btn.onmouseout = function() { this.style.opacity = '0.7'; };\n btn.onclick = function() {\n navigator.clipboard.writeText(codeBlock.textContent).then(function() {\n btn.textContent = 'Copied!';\n setTimeout(function() { btn.textContent = 'Copy'; }, 1500);\n });\n };\n codeBlock.parentElement.style.position = 'relative';\n codeBlock.parentElement.appendChild(btn);\n });\n }\n \n addCopyButtons();\n \n // Re-run on dynamic content\n var observer = new MutationObserver(addCopyButtons);\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Add Copy Buttons to Code Blocks");
}
} catch(__e) { console.warn('[Userscript:Add Copy Buttons to Code Blocks]', __e); }
})();
(function(){
try {
var __m = "github.com";
var __re = new RegExp('^' + "github\\.com" + '
Skip to content

Bindings Updates for #681 and more Clones - #749

Merged
TheBlueMatt merged 12 commits into
lightningdevkit:mainfrom
TheBlueMatt:2020-11-bindings-clones
Nov 23, 2020
Merged

Bindings Updates for #681 and more Clones#749
TheBlueMatt merged 12 commits into
lightningdevkit:mainfrom
TheBlueMatt:2020-11-bindings-clones

Conversation

@TheBlueMatt

Copy link
Copy Markdown
Collaborator

There was one trivial bit to fix for #681, but more importantly this adds much better and broader support for calling clone from the C bindings, which we rely on extensively in the Java bindings.

@TheBlueMattTheBlueMatt added this to the 0.0.12 milestone Nov 13, 2020

@jkczyzjkczyz left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Not sure if it is related, but I'm getting an error when running genbindings.sh on macOS:

+ cargo rustc -v --release -- -C lto
Compiling cc v1.0.65
Compiling bitcoin_hashes v0.8.0
Compiling bech32 v0.7.2
Running `rustc --crate-name cc --edition=2018 /Users/jkczyz/.cargo/registry/src/github.com-1ecc6299db9ec823/cc-1.0.65/src/lib.rs --error-format=json --json=diagnostic-rendered-ansi --crate-type lib --emit=dep-info,metadata,link -C opt-level=3 -Cembed-bitcode=no -C metadata=00dcc370fd0f6eb8 -C extra-filename=-00dcc370fd0f6eb8 --out-dir /Users/jkczyz/src/rust-lightning-review/lightning-c-bindings/target/release/deps -L dependency=/Users/jkczyz/src/rust-lightning-review/lightning-c-bindings/target/release/deps --cap-lints allow`
Running `rustc --crate-name bitcoin_hashes /Users/jkczyz/.cargo/registry/src/github.com-1ecc6299db9ec823/bitcoin_hashes-0.8.0/src/lib.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts --crate-type lib --emit=dep-info,metadata,link -C opt-level=3 -Cembed-bitcode=no --cfg 'feature="default"' --cfg 'feature="std"' -C metadata=3f72b8b01c4f2e37 -C extra-filename=-3f72b8b01c4f2e37 --out-dir /Users/jkczyz/src/rust-lightning-review/lightning-c-bindings/target/release/deps -L dependency=/Users/jkczyz/src/rust-lightning-review/lightning-c-bindings/target/release/deps --cap-lints allow`
Running `rustc --crate-name bech32 /Users/jkczyz/.cargo/registry/src/github.com-1ecc6299db9ec823/bech32-0.7.2/src/lib.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts --crate-type lib --emit=dep-info,metadata,link -C opt-level=3 -Cembed-bitcode=no -C metadata=848e3766e44cacd7 -C extra-filename=-848e3766e44cacd7 --out-dir /Users/jkczyz/src/rust-lightning-review/lightning-c-bindings/target/release/deps -L dependency=/Users/jkczyz/src/rust-lightning-review/lightning-c-bindings/target/release/deps --cap-lints allow`
Compiling secp256k1-sys v0.2.0
Running `rustc --crate-name build_script_build /Users/jkczyz/.cargo/registry/src/github.com-1ecc6299db9ec823/secp256k1-sys-0.2.0/build.rs --error-format=json --json=diagnostic-rendered-ansi --crate-type bin --emit=dep-info,link -C opt-level=3 -Cembed-bitcode=no --cfg 'feature="std"' -C metadata=73b76d4b12ae7a7f -C extra-filename=-73b76d4b12ae7a7f --out-dir /Users/jkczyz/src/rust-lightning-review/lightning-c-bindings/target/release/build/secp256k1-sys-73b76d4b12ae7a7f -L dependency=/Users/jkczyz/src/rust-lightning-review/lightning-c-bindings/target/release/deps --extern cc=/Users/jkczyz/src/rust-lightning-review/lightning-c-bindings/target/release/deps/libcc-00dcc370fd0f6eb8.rlib --cap-lints allow`
Running `/Users/jkczyz/src/rust-lightning-review/lightning-c-bindings/target/release/build/secp256k1-sys-73b76d4b12ae7a7f/build-script-build`
Running `rustc --crate-name secp256k1_sys /Users/jkczyz/.cargo/registry/src/github.com-1ecc6299db9ec823/secp256k1-sys-0.2.0/src/lib.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts --crate-type lib --emit=dep-info,metadata,link -C opt-level=3 -Cembed-bitcode=no --cfg 'feature="std"' -C metadata=caf2e22195643b8f -C extra-filename=-caf2e22195643b8f --out-dir /Users/jkczyz/src/rust-lightning-review/lightning-c-bindings/target/release/deps -L dependency=/Users/jkczyz/src/rust-lightning-review/lightning-c-bindings/target/release/deps --cap-lints allow -L native=/Users/jkczyz/src/rust-lightning-review/lightning-c-bindings/target/release/build/secp256k1-sys-6ea31cf4a9c94cb1/out -l static=secp256k1`
Compiling secp256k1 v0.18.0
Running `rustc --crate-name secp256k1 /Users/jkczyz/.cargo/registry/src/github.com-1ecc6299db9ec823/secp256k1-0.18.0/src/lib.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts --crate-type lib --emit=dep-info,metadata,link -C opt-level=3 -Cembed-bitcode=no --cfg 'feature="default"' --cfg 'feature="std"' -C metadata=1eabee0c3285b09c -C extra-filename=-1eabee0c3285b09c --out-dir /Users/jkczyz/src/rust-lightning-review/lightning-c-bindings/target/release/deps -L dependency=/Users/jkczyz/src/rust-lightning-review/lightning-c-bindings/target/release/deps --extern secp256k1_sys=/Users/jkczyz/src/rust-lightning-review/lightning-c-bindings/target/release/deps/libsecp256k1_sys-caf2e22195643b8f.rmeta --cap-lints allow -L native=/Users/jkczyz/src/rust-lightning-review/lightning-c-bindings/target/release/build/secp256k1-sys-6ea31cf4a9c94cb1/out`
Compiling bitcoin v0.24.0
Running `rustc --crate-name bitcoin /Users/jkczyz/.cargo/registry/src/github.com-1ecc6299db9ec823/bitcoin-0.24.0/src/lib.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts --crate-type lib --emit=dep-info,metadata,link -C opt-level=3 -Cembed-bitcode=no -C metadata=e1b66b4ed9a90379 -C extra-filename=-e1b66b4ed9a90379 --out-dir /Users/jkczyz/src/rust-lightning-review/lightning-c-bindings/target/release/deps -L dependency=/Users/jkczyz/src/rust-lightning-review/lightning-c-bindings/target/release/deps --extern bech32=/Users/jkczyz/src/rust-lightning-review/lightning-c-bindings/target/release/deps/libbech32-848e3766e44cacd7.rmeta --extern bitcoin_hashes=/Users/jkczyz/src/rust-lightning-review/lightning-c-bindings/target/release/deps/libbitcoin_hashes-3f72b8b01c4f2e37.rmeta --extern secp256k1=/Users/jkczyz/src/rust-lightning-review/lightning-c-bindings/target/release/deps/libsecp256k1-1eabee0c3285b09c.rmeta --cap-lints allow -L native=/Users/jkczyz/src/rust-lightning-review/lightning-c-bindings/target/release/build/secp256k1-sys-6ea31cf4a9c94cb1/out`
Compiling lightning v0.0.11 (/Users/jkczyz/src/rust-lightning-review/lightning)
Running `rustc --crate-name lightning /Users/jkczyz/src/rust-lightning-review/lightning/src/lib.rs --error-format=json --json=diagnostic-rendered-ansi --crate-type lib --emit=dep-info,metadata,link -C opt-level=3 -Cembed-bitcode=no -C metadata=79da2e4794c19ffc -C extra-filename=-79da2e4794c19ffc --out-dir /Users/jkczyz/src/rust-lightning-review/lightning-c-bindings/target/release/deps -L dependency=/Users/jkczyz/src/rust-lightning-review/lightning-c-bindings/target/release/deps --extern bitcoin=/Users/jkczyz/src/rust-lightning-review/lightning-c-bindings/target/release/deps/libbitcoin-e1b66b4ed9a90379.rmeta -L native=/Users/jkczyz/src/rust-lightning-review/lightning-c-bindings/target/release/build/secp256k1-sys-6ea31cf4a9c94cb1/out`
Compiling lightning-c-bindings v0.0.1 (/Users/jkczyz/src/rust-lightning-review/lightning-c-bindings)
Running `rustc --crate-name ldk --edition=2018 src/lib.rs --error-format=json --json=diagnostic-rendered-ansi --crate-type staticlib --crate-type cdylib --emit=dep-info,link -C opt-level=3 -Cembed-bitcode=no -C lto -C metadata=fe50c7fd2ceda483 --out-dir /Users/jkczyz/src/rust-lightning-review/lightning-c-bindings/target/release/deps -L dependency=/Users/jkczyz/src/rust-lightning-review/lightning-c-bindings/target/release/deps --extern bitcoin=/Users/jkczyz/src/rust-lightning-review/lightning-c-bindings/target/release/deps/libbitcoin-e1b66b4ed9a90379.rlib --extern lightning=/Users/jkczyz/src/rust-lightning-review/lightning-c-bindings/target/release/deps/liblightning-79da2e4794c19ffc.rlib -L native=/Users/jkczyz/src/rust-lightning-review/lightning-c-bindings/target/release/build/secp256k1-sys-6ea31cf4a9c94cb1/out`
error: options `-C embed-bitcode=no` and `-C lto` are incompatible
error: could not compile `lightning-c-bindings`.
Caused by:
process didn't exit successfully: `rustc --crate-name ldk --edition=2018 src/lib.rs --error-format=json --json=diagnostic-rendered-ansi --crate-type staticlib --crate-type cdylib --emit=dep-info,link -C opt-level=3 -Cembed-bitcode=no -C lto -C metadata=fe50c7fd2ceda483 --out-dir /Users/jkczyz/src/rust-lightning-review/lightning-c-bindings/target/release/deps -L dependency=/Users/jkczyz/src/rust-lightning-review/lightning-c-bindings/target/release/deps --extern bitcoin=/Users/jkczyz/src/rust-lightning-review/lightning-c-bindings/target/release/deps/libbitcoin-e1b66b4ed9a90379.rlib --extern lightning=/Users/jkczyz/src/rust-lightning-review/lightning-c-bindings/target/release/deps/liblightning-79da2e4794c19ffc.rlib -L native=/Users/jkczyz/src/rust-lightning-review/lightning-c-bindings/target/release/build/secp256k1-sys-6ea31cf4a9c94cb1/out` (exit code: 1)

Comment threadlightning/src/ln/channelmanager.rs Outdated
@TheBlueMatt
TheBlueMattforce-pushed the 2020-11-bindings-clones branch from 6a3db9c to 674559cCompareNovember 23, 2020 15:29
@TheBlueMatt

Copy link
Copy Markdown
CollaboratorAuthor

No, but Val did note it previously and I wasn't able to reproduce on newer rustc so I forgot about it, sorry about that. I pushed a commit to fix it mostly based on Val's suggested patch at #721 (comment)

@codecov

codecovBot commented Nov 23, 2020

Copy link
Copy Markdown

Codecov Report

Merging #749 (1af6e34) into main (8f10a1d) will decrease coverage by 0.09%.
The diff coverage is 12.50%.

Impacted file tree graph

@@ Coverage Diff @@## main #749 +/- ##
==========================================
- Coverage 91.39% 91.29% -0.10% 
==========================================
Files 37 37 Lines 22249 22274 +25 ==========================================
+ Hits 20334 20335 +1 - Misses 1915 1939 +24 
Impacted FilesCoverage Δ
lightning/src/ln/chan_utils.rs95.66% <0.00%> (-0.31%)⬇️
lightning/src/ln/channelmanager.rs84.95% <0.00%> (-0.41%)⬇️
lightning/src/ln/msgs.rs89.60% <0.00%> (-0.48%)⬇️
lightning/src/routing/router.rs95.71% <0.00%> (-0.96%)⬇️
lightning/src/util/events.rs24.54% <0.00%> (ø)
lightning/src/chain/channelmonitor.rs95.44% <100.00%> (ø)
lightning/src/ln/functional_tests.rs96.96% <0.00%> (+0.01%)⬆️

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 8f10a1d...9fe3124. Read the comment docs.

…gdevkit#681)
Previously we'd ignored generic arguments in traits, leading to
bogus code generation after the Persister trait was added in lightningdevkit#681.
This adds minimal support for it, fixing code generation on latest
upstream.
When the only reference to the transaction bytes is via
Transaction::data, my understanding of the C const rules is that
it would then be invalid to write to it. While its unlikely this
would ever pose an issue, its not hard to simply make it *mut, so
we do that here.
CVecTempl previously called Vec.clone_from_slice() on a
newly-allocated Vec, which immediately panics as
[T].clone_from_slice() requires that the Vec/target slice already
has the same length as the source slice. This should have been
Vec.extend_from_slice() which exhibits the correct behavior.
This somewhat assumes that every public enum implements clone in
some way, but that is currently the case.
There is no reason not to and Clone can be useful especially in the
bindings context.
When a trait is required to implement eq/clone (eg in the case of
`SocketDescriptor`), the generated trait struct contains an
eq/clone function which takes a `this_arg` pointer. Since the trait
object can always be read to get the `this_arg` pointer, there is
no loss of generality to pass the trait object itself, and it
provides a bit more flexibility when the trait could be one of
several implementations (which we use in the Java higher-level
bindings).
Newer versions of cargo broke `cargo rustc -- -Clto` by passing
`-Cembed-bitcode=no` even in `--release`. Its somewhat unclear why
this is still the case on latest cargo given it broke, at least,
compilation of Firefox, as discovered by Val at [1]. We take the
approach they used there, even though they later walked it back [2]
but the issues noted there, especially in [3] don't seem
particularly concerning in our case.
[1] https://bugzilla.mozilla.org/show_bug.cgi?id=1640982
[2] https://bugzilla.mozilla.org/show_bug.cgi?id=1654465
[3] https://bugzilla.mozilla.org/show_bug.cgi?id=1654465#c5
@TheBlueMatt
TheBlueMattforce-pushed the 2020-11-bindings-clones branch from 674559c to 9fe3124CompareNovember 23, 2020 16:12
@TheBlueMatt

Copy link
Copy Markdown
CollaboratorAuthor

Also rebased on upstream git which changed ever so slightly.

@valentinewallacevalentinewallace left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM! Thanks for the fixes on genbindings, that seems to have worked for me (haven't figured out how to get the right clang version so haven't tested out the address-sanitizer parts, but otherwise the headers are generated 💪)

writeln!(w, "#[no_mangle]\npub extern \"C\" fn {}_free(this_ptr: {}) {{ }}", e.ident, e.ident).unwrap();
}
writeln!(w, "#[no_mangle]").unwrap();
writeln!(w, "pub extern \"C\" fn {}_clone(orig: &{}) -> {} {{", e.ident, e.ident, e.ident).unwrap();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Just to confirm, it's fine that some pub(enum)s in RL don't implement Clone?

Copy link
Copy Markdown
CollaboratorAuthor

Choose a reason for hiding this comment

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

Hmm, I mean I guess we should have them match, but its not an issue per se currently - if all the fields support Clone (as they would have to for the bindings crate to not fail to compile), then exposing a Clone to bindings seems fine.

@TheBlueMatt
TheBlueMatt merged commit 52673d4 into lightningdevkit:mainNov 23, 2020
@TheBlueMatt

Copy link
Copy Markdown
CollaboratorAuthor

Taking cause we need to get 0.0.12 out the door.

Sign up for freeto 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.

3 participants

@TheBlueMatt@jkczyz@valentinewallace
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Force GitHub README to respect dark mode\n(function() {\n var style = document.createElement('style');\n style.textContent = '\n .markdown-body {\n color-scheme: dark light;\n }\n .markdown-body pre { background: #161b22 !important; }\n .markdown-body code { background: rgba(110, 118, 129, 0.4) !important; }\n .markdown-body table th, .markdown-body table td { border-color: #30363d !important; }\n .markdown-body img { background: #0d1117; }\n .markdown-body blockquote { border-left-color: #8b949e; }\n .markdown-body hr { border-color: #30363d; }\n ';\n document.head.appendChild(style);\n})();", "GitHub Dark Mode README Fix"); } } catch(__e) { console.warn('[Userscript:GitHub Dark Mode README Fix]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content

Bindings Updates for #681 and more Clones - #749

Merged
TheBlueMatt merged 12 commits into
lightningdevkit:mainfrom
TheBlueMatt:2020-11-bindings-clones
Nov 23, 2020
Merged

Bindings Updates for #681 and more Clones#749
TheBlueMatt merged 12 commits into
lightningdevkit:mainfrom
TheBlueMatt:2020-11-bindings-clones

Conversation

@TheBlueMatt

Copy link
Copy Markdown
Collaborator

There was one trivial bit to fix for #681, but more importantly this adds much better and broader support for calling clone from the C bindings, which we rely on extensively in the Java bindings.

@TheBlueMattTheBlueMatt added this to the 0.0.12 milestone Nov 13, 2020

@jkczyzjkczyz left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Not sure if it is related, but I'm getting an error when running genbindings.sh on macOS:

+ cargo rustc -v --release -- -C lto
Compiling cc v1.0.65
Compiling bitcoin_hashes v0.8.0
Compiling bech32 v0.7.2
Running `rustc --crate-name cc --edition=2018 /Users/jkczyz/.cargo/registry/src/github.com-1ecc6299db9ec823/cc-1.0.65/src/lib.rs --error-format=json --json=diagnostic-rendered-ansi --crate-type lib --emit=dep-info,metadata,link -C opt-level=3 -Cembed-bitcode=no -C metadata=00dcc370fd0f6eb8 -C extra-filename=-00dcc370fd0f6eb8 --out-dir /Users/jkczyz/src/rust-lightning-review/lightning-c-bindings/target/release/deps -L dependency=/Users/jkczyz/src/rust-lightning-review/lightning-c-bindings/target/release/deps --cap-lints allow`
Running `rustc --crate-name bitcoin_hashes /Users/jkczyz/.cargo/registry/src/github.com-1ecc6299db9ec823/bitcoin_hashes-0.8.0/src/lib.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts --crate-type lib --emit=dep-info,metadata,link -C opt-level=3 -Cembed-bitcode=no --cfg 'feature="default"' --cfg 'feature="std"' -C metadata=3f72b8b01c4f2e37 -C extra-filename=-3f72b8b01c4f2e37 --out-dir /Users/jkczyz/src/rust-lightning-review/lightning-c-bindings/target/release/deps -L dependency=/Users/jkczyz/src/rust-lightning-review/lightning-c-bindings/target/release/deps --cap-lints allow`
Running `rustc --crate-name bech32 /Users/jkczyz/.cargo/registry/src/github.com-1ecc6299db9ec823/bech32-0.7.2/src/lib.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts --crate-type lib --emit=dep-info,metadata,link -C opt-level=3 -Cembed-bitcode=no -C metadata=848e3766e44cacd7 -C extra-filename=-848e3766e44cacd7 --out-dir /Users/jkczyz/src/rust-lightning-review/lightning-c-bindings/target/release/deps -L dependency=/Users/jkczyz/src/rust-lightning-review/lightning-c-bindings/target/release/deps --cap-lints allow`
Compiling secp256k1-sys v0.2.0
Running `rustc --crate-name build_script_build /Users/jkczyz/.cargo/registry/src/github.com-1ecc6299db9ec823/secp256k1-sys-0.2.0/build.rs --error-format=json --json=diagnostic-rendered-ansi --crate-type bin --emit=dep-info,link -C opt-level=3 -Cembed-bitcode=no --cfg 'feature="std"' -C metadata=73b76d4b12ae7a7f -C extra-filename=-73b76d4b12ae7a7f --out-dir /Users/jkczyz/src/rust-lightning-review/lightning-c-bindings/target/release/build/secp256k1-sys-73b76d4b12ae7a7f -L dependency=/Users/jkczyz/src/rust-lightning-review/lightning-c-bindings/target/release/deps --extern cc=/Users/jkczyz/src/rust-lightning-review/lightning-c-bindings/target/release/deps/libcc-00dcc370fd0f6eb8.rlib --cap-lints allow`
Running `/Users/jkczyz/src/rust-lightning-review/lightning-c-bindings/target/release/build/secp256k1-sys-73b76d4b12ae7a7f/build-script-build`
Running `rustc --crate-name secp256k1_sys /Users/jkczyz/.cargo/registry/src/github.com-1ecc6299db9ec823/secp256k1-sys-0.2.0/src/lib.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts --crate-type lib --emit=dep-info,metadata,link -C opt-level=3 -Cembed-bitcode=no --cfg 'feature="std"' -C metadata=caf2e22195643b8f -C extra-filename=-caf2e22195643b8f --out-dir /Users/jkczyz/src/rust-lightning-review/lightning-c-bindings/target/release/deps -L dependency=/Users/jkczyz/src/rust-lightning-review/lightning-c-bindings/target/release/deps --cap-lints allow -L native=/Users/jkczyz/src/rust-lightning-review/lightning-c-bindings/target/release/build/secp256k1-sys-6ea31cf4a9c94cb1/out -l static=secp256k1`
Compiling secp256k1 v0.18.0
Running `rustc --crate-name secp256k1 /Users/jkczyz/.cargo/registry/src/github.com-1ecc6299db9ec823/secp256k1-0.18.0/src/lib.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts --crate-type lib --emit=dep-info,metadata,link -C opt-level=3 -Cembed-bitcode=no --cfg 'feature="default"' --cfg 'feature="std"' -C metadata=1eabee0c3285b09c -C extra-filename=-1eabee0c3285b09c --out-dir /Users/jkczyz/src/rust-lightning-review/lightning-c-bindings/target/release/deps -L dependency=/Users/jkczyz/src/rust-lightning-review/lightning-c-bindings/target/release/deps --extern secp256k1_sys=/Users/jkczyz/src/rust-lightning-review/lightning-c-bindings/target/release/deps/libsecp256k1_sys-caf2e22195643b8f.rmeta --cap-lints allow -L native=/Users/jkczyz/src/rust-lightning-review/lightning-c-bindings/target/release/build/secp256k1-sys-6ea31cf4a9c94cb1/out`
Compiling bitcoin v0.24.0
Running `rustc --crate-name bitcoin /Users/jkczyz/.cargo/registry/src/github.com-1ecc6299db9ec823/bitcoin-0.24.0/src/lib.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts --crate-type lib --emit=dep-info,metadata,link -C opt-level=3 -Cembed-bitcode=no -C metadata=e1b66b4ed9a90379 -C extra-filename=-e1b66b4ed9a90379 --out-dir /Users/jkczyz/src/rust-lightning-review/lightning-c-bindings/target/release/deps -L dependency=/Users/jkczyz/src/rust-lightning-review/lightning-c-bindings/target/release/deps --extern bech32=/Users/jkczyz/src/rust-lightning-review/lightning-c-bindings/target/release/deps/libbech32-848e3766e44cacd7.rmeta --extern bitcoin_hashes=/Users/jkczyz/src/rust-lightning-review/lightning-c-bindings/target/release/deps/libbitcoin_hashes-3f72b8b01c4f2e37.rmeta --extern secp256k1=/Users/jkczyz/src/rust-lightning-review/lightning-c-bindings/target/release/deps/libsecp256k1-1eabee0c3285b09c.rmeta --cap-lints allow -L native=/Users/jkczyz/src/rust-lightning-review/lightning-c-bindings/target/release/build/secp256k1-sys-6ea31cf4a9c94cb1/out`
Compiling lightning v0.0.11 (/Users/jkczyz/src/rust-lightning-review/lightning)
Running `rustc --crate-name lightning /Users/jkczyz/src/rust-lightning-review/lightning/src/lib.rs --error-format=json --json=diagnostic-rendered-ansi --crate-type lib --emit=dep-info,metadata,link -C opt-level=3 -Cembed-bitcode=no -C metadata=79da2e4794c19ffc -C extra-filename=-79da2e4794c19ffc --out-dir /Users/jkczyz/src/rust-lightning-review/lightning-c-bindings/target/release/deps -L dependency=/Users/jkczyz/src/rust-lightning-review/lightning-c-bindings/target/release/deps --extern bitcoin=/Users/jkczyz/src/rust-lightning-review/lightning-c-bindings/target/release/deps/libbitcoin-e1b66b4ed9a90379.rmeta -L native=/Users/jkczyz/src/rust-lightning-review/lightning-c-bindings/target/release/build/secp256k1-sys-6ea31cf4a9c94cb1/out`
Compiling lightning-c-bindings v0.0.1 (/Users/jkczyz/src/rust-lightning-review/lightning-c-bindings)
Running `rustc --crate-name ldk --edition=2018 src/lib.rs --error-format=json --json=diagnostic-rendered-ansi --crate-type staticlib --crate-type cdylib --emit=dep-info,link -C opt-level=3 -Cembed-bitcode=no -C lto -C metadata=fe50c7fd2ceda483 --out-dir /Users/jkczyz/src/rust-lightning-review/lightning-c-bindings/target/release/deps -L dependency=/Users/jkczyz/src/rust-lightning-review/lightning-c-bindings/target/release/deps --extern bitcoin=/Users/jkczyz/src/rust-lightning-review/lightning-c-bindings/target/release/deps/libbitcoin-e1b66b4ed9a90379.rlib --extern lightning=/Users/jkczyz/src/rust-lightning-review/lightning-c-bindings/target/release/deps/liblightning-79da2e4794c19ffc.rlib -L native=/Users/jkczyz/src/rust-lightning-review/lightning-c-bindings/target/release/build/secp256k1-sys-6ea31cf4a9c94cb1/out`
error: options `-C embed-bitcode=no` and `-C lto` are incompatible
error: could not compile `lightning-c-bindings`.
Caused by:
process didn't exit successfully: `rustc --crate-name ldk --edition=2018 src/lib.rs --error-format=json --json=diagnostic-rendered-ansi --crate-type staticlib --crate-type cdylib --emit=dep-info,link -C opt-level=3 -Cembed-bitcode=no -C lto -C metadata=fe50c7fd2ceda483 --out-dir /Users/jkczyz/src/rust-lightning-review/lightning-c-bindings/target/release/deps -L dependency=/Users/jkczyz/src/rust-lightning-review/lightning-c-bindings/target/release/deps --extern bitcoin=/Users/jkczyz/src/rust-lightning-review/lightning-c-bindings/target/release/deps/libbitcoin-e1b66b4ed9a90379.rlib --extern lightning=/Users/jkczyz/src/rust-lightning-review/lightning-c-bindings/target/release/deps/liblightning-79da2e4794c19ffc.rlib -L native=/Users/jkczyz/src/rust-lightning-review/lightning-c-bindings/target/release/build/secp256k1-sys-6ea31cf4a9c94cb1/out` (exit code: 1)

Comment threadlightning/src/ln/channelmanager.rs Outdated
@TheBlueMatt
TheBlueMattforce-pushed the 2020-11-bindings-clones branch from 6a3db9c to 674559cCompareNovember 23, 2020 15:29
@TheBlueMatt

Copy link
Copy Markdown
CollaboratorAuthor

No, but Val did note it previously and I wasn't able to reproduce on newer rustc so I forgot about it, sorry about that. I pushed a commit to fix it mostly based on Val's suggested patch at #721 (comment)

@codecov

codecovBot commented Nov 23, 2020

Copy link
Copy Markdown

Codecov Report

Merging #749 (1af6e34) into main (8f10a1d) will decrease coverage by 0.09%.
The diff coverage is 12.50%.

Impacted file tree graph

@@ Coverage Diff @@## main #749 +/- ##
==========================================
- Coverage 91.39% 91.29% -0.10% 
==========================================
Files 37 37 Lines 22249 22274 +25 ==========================================
+ Hits 20334 20335 +1 - Misses 1915 1939 +24 
Impacted FilesCoverage Δ
lightning/src/ln/chan_utils.rs95.66% <0.00%> (-0.31%)⬇️
lightning/src/ln/channelmanager.rs84.95% <0.00%> (-0.41%)⬇️
lightning/src/ln/msgs.rs89.60% <0.00%> (-0.48%)⬇️
lightning/src/routing/router.rs95.71% <0.00%> (-0.96%)⬇️
lightning/src/util/events.rs24.54% <0.00%> (ø)
lightning/src/chain/channelmonitor.rs95.44% <100.00%> (ø)
lightning/src/ln/functional_tests.rs96.96% <0.00%> (+0.01%)⬆️

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 8f10a1d...9fe3124. Read the comment docs.

…gdevkit#681)
Previously we'd ignored generic arguments in traits, leading to
bogus code generation after the Persister trait was added in lightningdevkit#681.
This adds minimal support for it, fixing code generation on latest
upstream.
When the only reference to the transaction bytes is via
Transaction::data, my understanding of the C const rules is that
it would then be invalid to write to it. While its unlikely this
would ever pose an issue, its not hard to simply make it *mut, so
we do that here.
CVecTempl previously called Vec.clone_from_slice() on a
newly-allocated Vec, which immediately panics as
[T].clone_from_slice() requires that the Vec/target slice already
has the same length as the source slice. This should have been
Vec.extend_from_slice() which exhibits the correct behavior.
This somewhat assumes that every public enum implements clone in
some way, but that is currently the case.
There is no reason not to and Clone can be useful especially in the
bindings context.
When a trait is required to implement eq/clone (eg in the case of
`SocketDescriptor`), the generated trait struct contains an
eq/clone function which takes a `this_arg` pointer. Since the trait
object can always be read to get the `this_arg` pointer, there is
no loss of generality to pass the trait object itself, and it
provides a bit more flexibility when the trait could be one of
several implementations (which we use in the Java higher-level
bindings).
Newer versions of cargo broke `cargo rustc -- -Clto` by passing
`-Cembed-bitcode=no` even in `--release`. Its somewhat unclear why
this is still the case on latest cargo given it broke, at least,
compilation of Firefox, as discovered by Val at [1]. We take the
approach they used there, even though they later walked it back [2]
but the issues noted there, especially in [3] don't seem
particularly concerning in our case.
[1] https://bugzilla.mozilla.org/show_bug.cgi?id=1640982
[2] https://bugzilla.mozilla.org/show_bug.cgi?id=1654465
[3] https://bugzilla.mozilla.org/show_bug.cgi?id=1654465#c5
@TheBlueMatt
TheBlueMattforce-pushed the 2020-11-bindings-clones branch from 674559c to 9fe3124CompareNovember 23, 2020 16:12
@TheBlueMatt

Copy link
Copy Markdown
CollaboratorAuthor

Also rebased on upstream git which changed ever so slightly.

@valentinewallacevalentinewallace left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM! Thanks for the fixes on genbindings, that seems to have worked for me (haven't figured out how to get the right clang version so haven't tested out the address-sanitizer parts, but otherwise the headers are generated 💪)

writeln!(w, "#[no_mangle]\npub extern \"C\" fn {}_free(this_ptr: {}) {{ }}", e.ident, e.ident).unwrap();
}
writeln!(w, "#[no_mangle]").unwrap();
writeln!(w, "pub extern \"C\" fn {}_clone(orig: &{}) -> {} {{", e.ident, e.ident, e.ident).unwrap();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Just to confirm, it's fine that some pub(enum)s in RL don't implement Clone?

Copy link
Copy Markdown
CollaboratorAuthor

Choose a reason for hiding this comment

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

Hmm, I mean I guess we should have them match, but its not an issue per se currently - if all the fields support Clone (as they would have to for the bindings crate to not fail to compile), then exposing a Clone to bindings seems fine.

@TheBlueMatt
TheBlueMatt merged commit 52673d4 into lightningdevkit:mainNov 23, 2020
@TheBlueMatt

Copy link
Copy Markdown
CollaboratorAuthor

Taking cause we need to get 0.0.12 out the door.

Sign up for freeto 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.

3 participants

@TheBlueMatt@jkczyz@valentinewallace
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Highlight search terms from Google/DuckDuckGo/Bing referrer\n(function() {\n var ref = document.referrer;\n var terms = [];\n \n if (ref.includes('google.com') || ref.includes('duckduckgo.com') || ref.includes('bing.com')) {\n var url = new URL(ref);\n var q = url.searchParams.get('q') || url.searchParams.get('p');\n if (q) {\n terms = q.split(/\\s+/).filter(function(t) { return t.length > 2; });\n }\n }\n \n if (terms.length === 0) return;\n \n var style = document.createElement('style');\n style.textContent = '.userscript-highlight { background: #fbbf24; color: #1a1a2e; padding: 1px 3px; border-radius: 2px; }';\n document.head.appendChild(style);\n \n function highlight(node) {\n if (node.nodeType === 3) { // text node\n var text = node.textContent;\n var found = false;\n terms.forEach(function(term) {\n var regex = new RegExp('(' + term.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\') + ')', 'gi');\n if (regex.test(text)) {\n found = true;\n var frag = document.createDocumentFragment();\n var parts = text.split(regex);\n parts.forEach(function(part, i) {\n if (i % 2 === 0) {\n frag.appendChild(document.createTextNode(part));\n } else {\n var span = document.createElement('span');\n span.className = 'userscript-highlight';\n span.textContent = part;\n frag.appendChild(span);\n }\n });\n node.parentNode.replaceChild(frag, node);\n }\n });\n } else if (node.nodeType === 1 && node.childNodes) { // element\n var skipTags = ['SCRIPT', 'STYLE', 'NOSCRIPT', 'TEXTAREA', 'INPUT', 'SELECT'];\n if (!skipTags.includes(node.tagName)) {\n Array.from(node.childNodes).forEach(highlight);\n }\n }\n }\n \n highlight(document.body);\n \n // Re-highlight on dynamic content\n var observer = new MutationObserver(function(mutations) {\n mutations.forEach(function(m) {\n m.addedNodes.forEach(function(node) {\n if (node.nodeType === 1 || node.nodeType === 3) highlight(node);\n });\n });\n });\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Highlight Search Terms"); } } catch(__e) { console.warn('[Userscript:Highlight Search Terms]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content

Bindings Updates for #681 and more Clones - #749

Merged
TheBlueMatt merged 12 commits into
lightningdevkit:mainfrom
TheBlueMatt:2020-11-bindings-clones
Nov 23, 2020
Merged

Bindings Updates for #681 and more Clones#749
TheBlueMatt merged 12 commits into
lightningdevkit:mainfrom
TheBlueMatt:2020-11-bindings-clones

Conversation

@TheBlueMatt

Copy link
Copy Markdown
Collaborator

There was one trivial bit to fix for #681, but more importantly this adds much better and broader support for calling clone from the C bindings, which we rely on extensively in the Java bindings.

@TheBlueMattTheBlueMatt added this to the 0.0.12 milestone Nov 13, 2020

@jkczyzjkczyz left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Not sure if it is related, but I'm getting an error when running genbindings.sh on macOS:

+ cargo rustc -v --release -- -C lto
Compiling cc v1.0.65
Compiling bitcoin_hashes v0.8.0
Compiling bech32 v0.7.2
Running `rustc --crate-name cc --edition=2018 /Users/jkczyz/.cargo/registry/src/github.com-1ecc6299db9ec823/cc-1.0.65/src/lib.rs --error-format=json --json=diagnostic-rendered-ansi --crate-type lib --emit=dep-info,metadata,link -C opt-level=3 -Cembed-bitcode=no -C metadata=00dcc370fd0f6eb8 -C extra-filename=-00dcc370fd0f6eb8 --out-dir /Users/jkczyz/src/rust-lightning-review/lightning-c-bindings/target/release/deps -L dependency=/Users/jkczyz/src/rust-lightning-review/lightning-c-bindings/target/release/deps --cap-lints allow`
Running `rustc --crate-name bitcoin_hashes /Users/jkczyz/.cargo/registry/src/github.com-1ecc6299db9ec823/bitcoin_hashes-0.8.0/src/lib.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts --crate-type lib --emit=dep-info,metadata,link -C opt-level=3 -Cembed-bitcode=no --cfg 'feature="default"' --cfg 'feature="std"' -C metadata=3f72b8b01c4f2e37 -C extra-filename=-3f72b8b01c4f2e37 --out-dir /Users/jkczyz/src/rust-lightning-review/lightning-c-bindings/target/release/deps -L dependency=/Users/jkczyz/src/rust-lightning-review/lightning-c-bindings/target/release/deps --cap-lints allow`
Running `rustc --crate-name bech32 /Users/jkczyz/.cargo/registry/src/github.com-1ecc6299db9ec823/bech32-0.7.2/src/lib.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts --crate-type lib --emit=dep-info,metadata,link -C opt-level=3 -Cembed-bitcode=no -C metadata=848e3766e44cacd7 -C extra-filename=-848e3766e44cacd7 --out-dir /Users/jkczyz/src/rust-lightning-review/lightning-c-bindings/target/release/deps -L dependency=/Users/jkczyz/src/rust-lightning-review/lightning-c-bindings/target/release/deps --cap-lints allow`
Compiling secp256k1-sys v0.2.0
Running `rustc --crate-name build_script_build /Users/jkczyz/.cargo/registry/src/github.com-1ecc6299db9ec823/secp256k1-sys-0.2.0/build.rs --error-format=json --json=diagnostic-rendered-ansi --crate-type bin --emit=dep-info,link -C opt-level=3 -Cembed-bitcode=no --cfg 'feature="std"' -C metadata=73b76d4b12ae7a7f -C extra-filename=-73b76d4b12ae7a7f --out-dir /Users/jkczyz/src/rust-lightning-review/lightning-c-bindings/target/release/build/secp256k1-sys-73b76d4b12ae7a7f -L dependency=/Users/jkczyz/src/rust-lightning-review/lightning-c-bindings/target/release/deps --extern cc=/Users/jkczyz/src/rust-lightning-review/lightning-c-bindings/target/release/deps/libcc-00dcc370fd0f6eb8.rlib --cap-lints allow`
Running `/Users/jkczyz/src/rust-lightning-review/lightning-c-bindings/target/release/build/secp256k1-sys-73b76d4b12ae7a7f/build-script-build`
Running `rustc --crate-name secp256k1_sys /Users/jkczyz/.cargo/registry/src/github.com-1ecc6299db9ec823/secp256k1-sys-0.2.0/src/lib.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts --crate-type lib --emit=dep-info,metadata,link -C opt-level=3 -Cembed-bitcode=no --cfg 'feature="std"' -C metadata=caf2e22195643b8f -C extra-filename=-caf2e22195643b8f --out-dir /Users/jkczyz/src/rust-lightning-review/lightning-c-bindings/target/release/deps -L dependency=/Users/jkczyz/src/rust-lightning-review/lightning-c-bindings/target/release/deps --cap-lints allow -L native=/Users/jkczyz/src/rust-lightning-review/lightning-c-bindings/target/release/build/secp256k1-sys-6ea31cf4a9c94cb1/out -l static=secp256k1`
Compiling secp256k1 v0.18.0
Running `rustc --crate-name secp256k1 /Users/jkczyz/.cargo/registry/src/github.com-1ecc6299db9ec823/secp256k1-0.18.0/src/lib.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts --crate-type lib --emit=dep-info,metadata,link -C opt-level=3 -Cembed-bitcode=no --cfg 'feature="default"' --cfg 'feature="std"' -C metadata=1eabee0c3285b09c -C extra-filename=-1eabee0c3285b09c --out-dir /Users/jkczyz/src/rust-lightning-review/lightning-c-bindings/target/release/deps -L dependency=/Users/jkczyz/src/rust-lightning-review/lightning-c-bindings/target/release/deps --extern secp256k1_sys=/Users/jkczyz/src/rust-lightning-review/lightning-c-bindings/target/release/deps/libsecp256k1_sys-caf2e22195643b8f.rmeta --cap-lints allow -L native=/Users/jkczyz/src/rust-lightning-review/lightning-c-bindings/target/release/build/secp256k1-sys-6ea31cf4a9c94cb1/out`
Compiling bitcoin v0.24.0
Running `rustc --crate-name bitcoin /Users/jkczyz/.cargo/registry/src/github.com-1ecc6299db9ec823/bitcoin-0.24.0/src/lib.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts --crate-type lib --emit=dep-info,metadata,link -C opt-level=3 -Cembed-bitcode=no -C metadata=e1b66b4ed9a90379 -C extra-filename=-e1b66b4ed9a90379 --out-dir /Users/jkczyz/src/rust-lightning-review/lightning-c-bindings/target/release/deps -L dependency=/Users/jkczyz/src/rust-lightning-review/lightning-c-bindings/target/release/deps --extern bech32=/Users/jkczyz/src/rust-lightning-review/lightning-c-bindings/target/release/deps/libbech32-848e3766e44cacd7.rmeta --extern bitcoin_hashes=/Users/jkczyz/src/rust-lightning-review/lightning-c-bindings/target/release/deps/libbitcoin_hashes-3f72b8b01c4f2e37.rmeta --extern secp256k1=/Users/jkczyz/src/rust-lightning-review/lightning-c-bindings/target/release/deps/libsecp256k1-1eabee0c3285b09c.rmeta --cap-lints allow -L native=/Users/jkczyz/src/rust-lightning-review/lightning-c-bindings/target/release/build/secp256k1-sys-6ea31cf4a9c94cb1/out`
Compiling lightning v0.0.11 (/Users/jkczyz/src/rust-lightning-review/lightning)
Running `rustc --crate-name lightning /Users/jkczyz/src/rust-lightning-review/lightning/src/lib.rs --error-format=json --json=diagnostic-rendered-ansi --crate-type lib --emit=dep-info,metadata,link -C opt-level=3 -Cembed-bitcode=no -C metadata=79da2e4794c19ffc -C extra-filename=-79da2e4794c19ffc --out-dir /Users/jkczyz/src/rust-lightning-review/lightning-c-bindings/target/release/deps -L dependency=/Users/jkczyz/src/rust-lightning-review/lightning-c-bindings/target/release/deps --extern bitcoin=/Users/jkczyz/src/rust-lightning-review/lightning-c-bindings/target/release/deps/libbitcoin-e1b66b4ed9a90379.rmeta -L native=/Users/jkczyz/src/rust-lightning-review/lightning-c-bindings/target/release/build/secp256k1-sys-6ea31cf4a9c94cb1/out`
Compiling lightning-c-bindings v0.0.1 (/Users/jkczyz/src/rust-lightning-review/lightning-c-bindings)
Running `rustc --crate-name ldk --edition=2018 src/lib.rs --error-format=json --json=diagnostic-rendered-ansi --crate-type staticlib --crate-type cdylib --emit=dep-info,link -C opt-level=3 -Cembed-bitcode=no -C lto -C metadata=fe50c7fd2ceda483 --out-dir /Users/jkczyz/src/rust-lightning-review/lightning-c-bindings/target/release/deps -L dependency=/Users/jkczyz/src/rust-lightning-review/lightning-c-bindings/target/release/deps --extern bitcoin=/Users/jkczyz/src/rust-lightning-review/lightning-c-bindings/target/release/deps/libbitcoin-e1b66b4ed9a90379.rlib --extern lightning=/Users/jkczyz/src/rust-lightning-review/lightning-c-bindings/target/release/deps/liblightning-79da2e4794c19ffc.rlib -L native=/Users/jkczyz/src/rust-lightning-review/lightning-c-bindings/target/release/build/secp256k1-sys-6ea31cf4a9c94cb1/out`
error: options `-C embed-bitcode=no` and `-C lto` are incompatible
error: could not compile `lightning-c-bindings`.
Caused by:
process didn't exit successfully: `rustc --crate-name ldk --edition=2018 src/lib.rs --error-format=json --json=diagnostic-rendered-ansi --crate-type staticlib --crate-type cdylib --emit=dep-info,link -C opt-level=3 -Cembed-bitcode=no -C lto -C metadata=fe50c7fd2ceda483 --out-dir /Users/jkczyz/src/rust-lightning-review/lightning-c-bindings/target/release/deps -L dependency=/Users/jkczyz/src/rust-lightning-review/lightning-c-bindings/target/release/deps --extern bitcoin=/Users/jkczyz/src/rust-lightning-review/lightning-c-bindings/target/release/deps/libbitcoin-e1b66b4ed9a90379.rlib --extern lightning=/Users/jkczyz/src/rust-lightning-review/lightning-c-bindings/target/release/deps/liblightning-79da2e4794c19ffc.rlib -L native=/Users/jkczyz/src/rust-lightning-review/lightning-c-bindings/target/release/build/secp256k1-sys-6ea31cf4a9c94cb1/out` (exit code: 1)

Comment threadlightning/src/ln/channelmanager.rs Outdated
@TheBlueMatt
TheBlueMattforce-pushed the 2020-11-bindings-clones branch from 6a3db9c to 674559cCompareNovember 23, 2020 15:29
@TheBlueMatt

Copy link
Copy Markdown
CollaboratorAuthor

No, but Val did note it previously and I wasn't able to reproduce on newer rustc so I forgot about it, sorry about that. I pushed a commit to fix it mostly based on Val's suggested patch at #721 (comment)

@codecov

codecovBot commented Nov 23, 2020

Copy link
Copy Markdown

Codecov Report

Merging #749 (1af6e34) into main (8f10a1d) will decrease coverage by 0.09%.
The diff coverage is 12.50%.

Impacted file tree graph

@@ Coverage Diff @@## main #749 +/- ##
==========================================
- Coverage 91.39% 91.29% -0.10% 
==========================================
Files 37 37 Lines 22249 22274 +25 ==========================================
+ Hits 20334 20335 +1 - Misses 1915 1939 +24 
Impacted FilesCoverage Δ
lightning/src/ln/chan_utils.rs95.66% <0.00%> (-0.31%)⬇️
lightning/src/ln/channelmanager.rs84.95% <0.00%> (-0.41%)⬇️
lightning/src/ln/msgs.rs89.60% <0.00%> (-0.48%)⬇️
lightning/src/routing/router.rs95.71% <0.00%> (-0.96%)⬇️
lightning/src/util/events.rs24.54% <0.00%> (ø)
lightning/src/chain/channelmonitor.rs95.44% <100.00%> (ø)
lightning/src/ln/functional_tests.rs96.96% <0.00%> (+0.01%)⬆️

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 8f10a1d...9fe3124. Read the comment docs.

…gdevkit#681)
Previously we'd ignored generic arguments in traits, leading to
bogus code generation after the Persister trait was added in lightningdevkit#681.
This adds minimal support for it, fixing code generation on latest
upstream.
When the only reference to the transaction bytes is via
Transaction::data, my understanding of the C const rules is that
it would then be invalid to write to it. While its unlikely this
would ever pose an issue, its not hard to simply make it *mut, so
we do that here.
CVecTempl previously called Vec.clone_from_slice() on a
newly-allocated Vec, which immediately panics as
[T].clone_from_slice() requires that the Vec/target slice already
has the same length as the source slice. This should have been
Vec.extend_from_slice() which exhibits the correct behavior.
This somewhat assumes that every public enum implements clone in
some way, but that is currently the case.
There is no reason not to and Clone can be useful especially in the
bindings context.
When a trait is required to implement eq/clone (eg in the case of
`SocketDescriptor`), the generated trait struct contains an
eq/clone function which takes a `this_arg` pointer. Since the trait
object can always be read to get the `this_arg` pointer, there is
no loss of generality to pass the trait object itself, and it
provides a bit more flexibility when the trait could be one of
several implementations (which we use in the Java higher-level
bindings).
Newer versions of cargo broke `cargo rustc -- -Clto` by passing
`-Cembed-bitcode=no` even in `--release`. Its somewhat unclear why
this is still the case on latest cargo given it broke, at least,
compilation of Firefox, as discovered by Val at [1]. We take the
approach they used there, even though they later walked it back [2]
but the issues noted there, especially in [3] don't seem
particularly concerning in our case.
[1] https://bugzilla.mozilla.org/show_bug.cgi?id=1640982
[2] https://bugzilla.mozilla.org/show_bug.cgi?id=1654465
[3] https://bugzilla.mozilla.org/show_bug.cgi?id=1654465#c5
@TheBlueMatt
TheBlueMattforce-pushed the 2020-11-bindings-clones branch from 674559c to 9fe3124CompareNovember 23, 2020 16:12
@TheBlueMatt

Copy link
Copy Markdown
CollaboratorAuthor

Also rebased on upstream git which changed ever so slightly.

@valentinewallacevalentinewallace left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM! Thanks for the fixes on genbindings, that seems to have worked for me (haven't figured out how to get the right clang version so haven't tested out the address-sanitizer parts, but otherwise the headers are generated 💪)

writeln!(w, "#[no_mangle]\npub extern \"C\" fn {}_free(this_ptr: {}) {{ }}", e.ident, e.ident).unwrap();
}
writeln!(w, "#[no_mangle]").unwrap();
writeln!(w, "pub extern \"C\" fn {}_clone(orig: &{}) -> {} {{", e.ident, e.ident, e.ident).unwrap();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Just to confirm, it's fine that some pub(enum)s in RL don't implement Clone?

Copy link
Copy Markdown
CollaboratorAuthor

Choose a reason for hiding this comment

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

Hmm, I mean I guess we should have them match, but its not an issue per se currently - if all the fields support Clone (as they would have to for the bindings crate to not fail to compile), then exposing a Clone to bindings seems fine.

@TheBlueMatt
TheBlueMatt merged commit 52673d4 into lightningdevkit:mainNov 23, 2020
@TheBlueMatt

Copy link
Copy Markdown
CollaboratorAuthor

Taking cause we need to get 0.0.12 out the door.

Sign up for freeto 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.

3 participants

@TheBlueMatt@jkczyz@valentinewallace
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Strip utm_, fbclid, gclid, etc. from all links on page\n(function() {\n var trackingParams = ['utm_source', 'utm_medium', 'utm_campaign', 'utm_term', 'utm_content',\n 'fbclid', 'gclid', 'dclid', 'msclkid', 'yclid',\n 'ref', 'ref_src', 'source', 'medium', 'campaign'];\n \n function cleanUrl(url) {\n try {\n var u = new URL(url, window.location.origin);\n var changed = false;\n trackingParams.forEach(function(p) {\n if (u.searchParams.has(p)) {\n u.searchParams.delete(p);\n changed = true;\n }\n });\n return changed ? u.toString() : url;\n } catch (e) {\n return url;\n }\n }\n \n function cleanLinks() {\n document.querySelectorAll('a[href]').forEach(function(a) {\n var clean = cleanUrl(a.href);\n if (clean !== a.href) a.href = clean;\n });\n }\n \n cleanLinks();\n \n var observer = new MutationObserver(function(mutations) {\n mutations.forEach(function(m) {\n m.addedNodes.forEach(function(node) {\n if (node.nodeType === 1) {\n if (node.tagName === 'A') cleanLinks();\n node.querySelectorAll('a[href]').forEach(function(a) {\n var clean = cleanUrl(a.href);\n if (clean !== a.href) a.href = clean;\n });\n }\n });\n });\n });\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Remove Tracking Parameters from Links"); } } catch(__e) { console.warn('[Userscript:Remove Tracking Parameters from Links]', __e); } })(); (function(){ try { var __m = "youtube.com"; var __re = new RegExp('^' + "youtube\\.com" + '
Skip to content

Bindings Updates for #681 and more Clones - #749

Merged
TheBlueMatt merged 12 commits into
lightningdevkit:mainfrom
TheBlueMatt:2020-11-bindings-clones
Nov 23, 2020
Merged

Bindings Updates for #681 and more Clones#749
TheBlueMatt merged 12 commits into
lightningdevkit:mainfrom
TheBlueMatt:2020-11-bindings-clones

Conversation

@TheBlueMatt

Copy link
Copy Markdown
Collaborator

There was one trivial bit to fix for #681, but more importantly this adds much better and broader support for calling clone from the C bindings, which we rely on extensively in the Java bindings.

@TheBlueMattTheBlueMatt added this to the 0.0.12 milestone Nov 13, 2020

@jkczyzjkczyz left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Not sure if it is related, but I'm getting an error when running genbindings.sh on macOS:

+ cargo rustc -v --release -- -C lto
Compiling cc v1.0.65
Compiling bitcoin_hashes v0.8.0
Compiling bech32 v0.7.2
Running `rustc --crate-name cc --edition=2018 /Users/jkczyz/.cargo/registry/src/github.com-1ecc6299db9ec823/cc-1.0.65/src/lib.rs --error-format=json --json=diagnostic-rendered-ansi --crate-type lib --emit=dep-info,metadata,link -C opt-level=3 -Cembed-bitcode=no -C metadata=00dcc370fd0f6eb8 -C extra-filename=-00dcc370fd0f6eb8 --out-dir /Users/jkczyz/src/rust-lightning-review/lightning-c-bindings/target/release/deps -L dependency=/Users/jkczyz/src/rust-lightning-review/lightning-c-bindings/target/release/deps --cap-lints allow`
Running `rustc --crate-name bitcoin_hashes /Users/jkczyz/.cargo/registry/src/github.com-1ecc6299db9ec823/bitcoin_hashes-0.8.0/src/lib.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts --crate-type lib --emit=dep-info,metadata,link -C opt-level=3 -Cembed-bitcode=no --cfg 'feature="default"' --cfg 'feature="std"' -C metadata=3f72b8b01c4f2e37 -C extra-filename=-3f72b8b01c4f2e37 --out-dir /Users/jkczyz/src/rust-lightning-review/lightning-c-bindings/target/release/deps -L dependency=/Users/jkczyz/src/rust-lightning-review/lightning-c-bindings/target/release/deps --cap-lints allow`
Running `rustc --crate-name bech32 /Users/jkczyz/.cargo/registry/src/github.com-1ecc6299db9ec823/bech32-0.7.2/src/lib.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts --crate-type lib --emit=dep-info,metadata,link -C opt-level=3 -Cembed-bitcode=no -C metadata=848e3766e44cacd7 -C extra-filename=-848e3766e44cacd7 --out-dir /Users/jkczyz/src/rust-lightning-review/lightning-c-bindings/target/release/deps -L dependency=/Users/jkczyz/src/rust-lightning-review/lightning-c-bindings/target/release/deps --cap-lints allow`
Compiling secp256k1-sys v0.2.0
Running `rustc --crate-name build_script_build /Users/jkczyz/.cargo/registry/src/github.com-1ecc6299db9ec823/secp256k1-sys-0.2.0/build.rs --error-format=json --json=diagnostic-rendered-ansi --crate-type bin --emit=dep-info,link -C opt-level=3 -Cembed-bitcode=no --cfg 'feature="std"' -C metadata=73b76d4b12ae7a7f -C extra-filename=-73b76d4b12ae7a7f --out-dir /Users/jkczyz/src/rust-lightning-review/lightning-c-bindings/target/release/build/secp256k1-sys-73b76d4b12ae7a7f -L dependency=/Users/jkczyz/src/rust-lightning-review/lightning-c-bindings/target/release/deps --extern cc=/Users/jkczyz/src/rust-lightning-review/lightning-c-bindings/target/release/deps/libcc-00dcc370fd0f6eb8.rlib --cap-lints allow`
Running `/Users/jkczyz/src/rust-lightning-review/lightning-c-bindings/target/release/build/secp256k1-sys-73b76d4b12ae7a7f/build-script-build`
Running `rustc --crate-name secp256k1_sys /Users/jkczyz/.cargo/registry/src/github.com-1ecc6299db9ec823/secp256k1-sys-0.2.0/src/lib.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts --crate-type lib --emit=dep-info,metadata,link -C opt-level=3 -Cembed-bitcode=no --cfg 'feature="std"' -C metadata=caf2e22195643b8f -C extra-filename=-caf2e22195643b8f --out-dir /Users/jkczyz/src/rust-lightning-review/lightning-c-bindings/target/release/deps -L dependency=/Users/jkczyz/src/rust-lightning-review/lightning-c-bindings/target/release/deps --cap-lints allow -L native=/Users/jkczyz/src/rust-lightning-review/lightning-c-bindings/target/release/build/secp256k1-sys-6ea31cf4a9c94cb1/out -l static=secp256k1`
Compiling secp256k1 v0.18.0
Running `rustc --crate-name secp256k1 /Users/jkczyz/.cargo/registry/src/github.com-1ecc6299db9ec823/secp256k1-0.18.0/src/lib.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts --crate-type lib --emit=dep-info,metadata,link -C opt-level=3 -Cembed-bitcode=no --cfg 'feature="default"' --cfg 'feature="std"' -C metadata=1eabee0c3285b09c -C extra-filename=-1eabee0c3285b09c --out-dir /Users/jkczyz/src/rust-lightning-review/lightning-c-bindings/target/release/deps -L dependency=/Users/jkczyz/src/rust-lightning-review/lightning-c-bindings/target/release/deps --extern secp256k1_sys=/Users/jkczyz/src/rust-lightning-review/lightning-c-bindings/target/release/deps/libsecp256k1_sys-caf2e22195643b8f.rmeta --cap-lints allow -L native=/Users/jkczyz/src/rust-lightning-review/lightning-c-bindings/target/release/build/secp256k1-sys-6ea31cf4a9c94cb1/out`
Compiling bitcoin v0.24.0
Running `rustc --crate-name bitcoin /Users/jkczyz/.cargo/registry/src/github.com-1ecc6299db9ec823/bitcoin-0.24.0/src/lib.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts --crate-type lib --emit=dep-info,metadata,link -C opt-level=3 -Cembed-bitcode=no -C metadata=e1b66b4ed9a90379 -C extra-filename=-e1b66b4ed9a90379 --out-dir /Users/jkczyz/src/rust-lightning-review/lightning-c-bindings/target/release/deps -L dependency=/Users/jkczyz/src/rust-lightning-review/lightning-c-bindings/target/release/deps --extern bech32=/Users/jkczyz/src/rust-lightning-review/lightning-c-bindings/target/release/deps/libbech32-848e3766e44cacd7.rmeta --extern bitcoin_hashes=/Users/jkczyz/src/rust-lightning-review/lightning-c-bindings/target/release/deps/libbitcoin_hashes-3f72b8b01c4f2e37.rmeta --extern secp256k1=/Users/jkczyz/src/rust-lightning-review/lightning-c-bindings/target/release/deps/libsecp256k1-1eabee0c3285b09c.rmeta --cap-lints allow -L native=/Users/jkczyz/src/rust-lightning-review/lightning-c-bindings/target/release/build/secp256k1-sys-6ea31cf4a9c94cb1/out`
Compiling lightning v0.0.11 (/Users/jkczyz/src/rust-lightning-review/lightning)
Running `rustc --crate-name lightning /Users/jkczyz/src/rust-lightning-review/lightning/src/lib.rs --error-format=json --json=diagnostic-rendered-ansi --crate-type lib --emit=dep-info,metadata,link -C opt-level=3 -Cembed-bitcode=no -C metadata=79da2e4794c19ffc -C extra-filename=-79da2e4794c19ffc --out-dir /Users/jkczyz/src/rust-lightning-review/lightning-c-bindings/target/release/deps -L dependency=/Users/jkczyz/src/rust-lightning-review/lightning-c-bindings/target/release/deps --extern bitcoin=/Users/jkczyz/src/rust-lightning-review/lightning-c-bindings/target/release/deps/libbitcoin-e1b66b4ed9a90379.rmeta -L native=/Users/jkczyz/src/rust-lightning-review/lightning-c-bindings/target/release/build/secp256k1-sys-6ea31cf4a9c94cb1/out`
Compiling lightning-c-bindings v0.0.1 (/Users/jkczyz/src/rust-lightning-review/lightning-c-bindings)
Running `rustc --crate-name ldk --edition=2018 src/lib.rs --error-format=json --json=diagnostic-rendered-ansi --crate-type staticlib --crate-type cdylib --emit=dep-info,link -C opt-level=3 -Cembed-bitcode=no -C lto -C metadata=fe50c7fd2ceda483 --out-dir /Users/jkczyz/src/rust-lightning-review/lightning-c-bindings/target/release/deps -L dependency=/Users/jkczyz/src/rust-lightning-review/lightning-c-bindings/target/release/deps --extern bitcoin=/Users/jkczyz/src/rust-lightning-review/lightning-c-bindings/target/release/deps/libbitcoin-e1b66b4ed9a90379.rlib --extern lightning=/Users/jkczyz/src/rust-lightning-review/lightning-c-bindings/target/release/deps/liblightning-79da2e4794c19ffc.rlib -L native=/Users/jkczyz/src/rust-lightning-review/lightning-c-bindings/target/release/build/secp256k1-sys-6ea31cf4a9c94cb1/out`
error: options `-C embed-bitcode=no` and `-C lto` are incompatible
error: could not compile `lightning-c-bindings`.
Caused by:
process didn't exit successfully: `rustc --crate-name ldk --edition=2018 src/lib.rs --error-format=json --json=diagnostic-rendered-ansi --crate-type staticlib --crate-type cdylib --emit=dep-info,link -C opt-level=3 -Cembed-bitcode=no -C lto -C metadata=fe50c7fd2ceda483 --out-dir /Users/jkczyz/src/rust-lightning-review/lightning-c-bindings/target/release/deps -L dependency=/Users/jkczyz/src/rust-lightning-review/lightning-c-bindings/target/release/deps --extern bitcoin=/Users/jkczyz/src/rust-lightning-review/lightning-c-bindings/target/release/deps/libbitcoin-e1b66b4ed9a90379.rlib --extern lightning=/Users/jkczyz/src/rust-lightning-review/lightning-c-bindings/target/release/deps/liblightning-79da2e4794c19ffc.rlib -L native=/Users/jkczyz/src/rust-lightning-review/lightning-c-bindings/target/release/build/secp256k1-sys-6ea31cf4a9c94cb1/out` (exit code: 1)

Comment threadlightning/src/ln/channelmanager.rs Outdated
@TheBlueMatt
TheBlueMattforce-pushed the 2020-11-bindings-clones branch from 6a3db9c to 674559cCompareNovember 23, 2020 15:29
@TheBlueMatt

Copy link
Copy Markdown
CollaboratorAuthor

No, but Val did note it previously and I wasn't able to reproduce on newer rustc so I forgot about it, sorry about that. I pushed a commit to fix it mostly based on Val's suggested patch at #721 (comment)

@codecov

codecovBot commented Nov 23, 2020

Copy link
Copy Markdown

Codecov Report

Merging #749 (1af6e34) into main (8f10a1d) will decrease coverage by 0.09%.
The diff coverage is 12.50%.

Impacted file tree graph

@@ Coverage Diff @@## main #749 +/- ##
==========================================
- Coverage 91.39% 91.29% -0.10% 
==========================================
Files 37 37 Lines 22249 22274 +25 ==========================================
+ Hits 20334 20335 +1 - Misses 1915 1939 +24 
Impacted FilesCoverage Δ
lightning/src/ln/chan_utils.rs95.66% <0.00%> (-0.31%)⬇️
lightning/src/ln/channelmanager.rs84.95% <0.00%> (-0.41%)⬇️
lightning/src/ln/msgs.rs89.60% <0.00%> (-0.48%)⬇️
lightning/src/routing/router.rs95.71% <0.00%> (-0.96%)⬇️
lightning/src/util/events.rs24.54% <0.00%> (ø)
lightning/src/chain/channelmonitor.rs95.44% <100.00%> (ø)
lightning/src/ln/functional_tests.rs96.96% <0.00%> (+0.01%)⬆️

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 8f10a1d...9fe3124. Read the comment docs.

…gdevkit#681)
Previously we'd ignored generic arguments in traits, leading to
bogus code generation after the Persister trait was added in lightningdevkit#681.
This adds minimal support for it, fixing code generation on latest
upstream.
When the only reference to the transaction bytes is via
Transaction::data, my understanding of the C const rules is that
it would then be invalid to write to it. While its unlikely this
would ever pose an issue, its not hard to simply make it *mut, so
we do that here.
CVecTempl previously called Vec.clone_from_slice() on a
newly-allocated Vec, which immediately panics as
[T].clone_from_slice() requires that the Vec/target slice already
has the same length as the source slice. This should have been
Vec.extend_from_slice() which exhibits the correct behavior.
This somewhat assumes that every public enum implements clone in
some way, but that is currently the case.
There is no reason not to and Clone can be useful especially in the
bindings context.
When a trait is required to implement eq/clone (eg in the case of
`SocketDescriptor`), the generated trait struct contains an
eq/clone function which takes a `this_arg` pointer. Since the trait
object can always be read to get the `this_arg` pointer, there is
no loss of generality to pass the trait object itself, and it
provides a bit more flexibility when the trait could be one of
several implementations (which we use in the Java higher-level
bindings).
Newer versions of cargo broke `cargo rustc -- -Clto` by passing
`-Cembed-bitcode=no` even in `--release`. Its somewhat unclear why
this is still the case on latest cargo given it broke, at least,
compilation of Firefox, as discovered by Val at [1]. We take the
approach they used there, even though they later walked it back [2]
but the issues noted there, especially in [3] don't seem
particularly concerning in our case.
[1] https://bugzilla.mozilla.org/show_bug.cgi?id=1640982
[2] https://bugzilla.mozilla.org/show_bug.cgi?id=1654465
[3] https://bugzilla.mozilla.org/show_bug.cgi?id=1654465#c5
@TheBlueMatt
TheBlueMattforce-pushed the 2020-11-bindings-clones branch from 674559c to 9fe3124CompareNovember 23, 2020 16:12
@TheBlueMatt

Copy link
Copy Markdown
CollaboratorAuthor

Also rebased on upstream git which changed ever so slightly.

@valentinewallacevalentinewallace left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM! Thanks for the fixes on genbindings, that seems to have worked for me (haven't figured out how to get the right clang version so haven't tested out the address-sanitizer parts, but otherwise the headers are generated 💪)

writeln!(w, "#[no_mangle]\npub extern \"C\" fn {}_free(this_ptr: {}) {{ }}", e.ident, e.ident).unwrap();
}
writeln!(w, "#[no_mangle]").unwrap();
writeln!(w, "pub extern \"C\" fn {}_clone(orig: &{}) -> {} {{", e.ident, e.ident, e.ident).unwrap();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Just to confirm, it's fine that some pub(enum)s in RL don't implement Clone?

Copy link
Copy Markdown
CollaboratorAuthor

Choose a reason for hiding this comment

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

Hmm, I mean I guess we should have them match, but its not an issue per se currently - if all the fields support Clone (as they would have to for the bindings crate to not fail to compile), then exposing a Clone to bindings seems fine.

@TheBlueMatt
TheBlueMatt merged commit 52673d4 into lightningdevkit:mainNov 23, 2020
@TheBlueMatt

Copy link
Copy Markdown
CollaboratorAuthor

Taking cause we need to get 0.0.12 out the door.

Sign up for freeto 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.

3 participants

@TheBlueMatt@jkczyz@valentinewallace
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Auto-enable theater mode on YouTube\n(function() {\n function tryTheater() {\n var btn = document.querySelector('button[aria-label=\"Theater mode\"], ytd-player #player button[title=\"Theater mode\"]');\n if (btn && !btn.classList.contains('activated')) {\n btn.click();\n }\n }\n \n // Try immediately\n tryTheater();\n \n // Try after navigation (SPA)\n var lastUrl = location.href;\n setInterval(function() {\n if (location.href !== lastUrl) {\n lastUrl = location.href;\n setTimeout(tryTheater, 500);\n }\n }, 1000);\n \n // Also try on player load\n var observer = new MutationObserver(tryTheater);\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "YouTube Theater Mode Default"); } } catch(__e) { console.warn('[Userscript:YouTube Theater Mode Default]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content

Bindings Updates for #681 and more Clones - #749

Merged
TheBlueMatt merged 12 commits into
lightningdevkit:mainfrom
TheBlueMatt:2020-11-bindings-clones
Nov 23, 2020
Merged

Bindings Updates for #681 and more Clones#749
TheBlueMatt merged 12 commits into
lightningdevkit:mainfrom
TheBlueMatt:2020-11-bindings-clones

Conversation

@TheBlueMatt

Copy link
Copy Markdown
Collaborator

There was one trivial bit to fix for #681, but more importantly this adds much better and broader support for calling clone from the C bindings, which we rely on extensively in the Java bindings.

@TheBlueMattTheBlueMatt added this to the 0.0.12 milestone Nov 13, 2020

@jkczyzjkczyz left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Not sure if it is related, but I'm getting an error when running genbindings.sh on macOS:

+ cargo rustc -v --release -- -C lto
Compiling cc v1.0.65
Compiling bitcoin_hashes v0.8.0
Compiling bech32 v0.7.2
Running `rustc --crate-name cc --edition=2018 /Users/jkczyz/.cargo/registry/src/github.com-1ecc6299db9ec823/cc-1.0.65/src/lib.rs --error-format=json --json=diagnostic-rendered-ansi --crate-type lib --emit=dep-info,metadata,link -C opt-level=3 -Cembed-bitcode=no -C metadata=00dcc370fd0f6eb8 -C extra-filename=-00dcc370fd0f6eb8 --out-dir /Users/jkczyz/src/rust-lightning-review/lightning-c-bindings/target/release/deps -L dependency=/Users/jkczyz/src/rust-lightning-review/lightning-c-bindings/target/release/deps --cap-lints allow`
Running `rustc --crate-name bitcoin_hashes /Users/jkczyz/.cargo/registry/src/github.com-1ecc6299db9ec823/bitcoin_hashes-0.8.0/src/lib.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts --crate-type lib --emit=dep-info,metadata,link -C opt-level=3 -Cembed-bitcode=no --cfg 'feature="default"' --cfg 'feature="std"' -C metadata=3f72b8b01c4f2e37 -C extra-filename=-3f72b8b01c4f2e37 --out-dir /Users/jkczyz/src/rust-lightning-review/lightning-c-bindings/target/release/deps -L dependency=/Users/jkczyz/src/rust-lightning-review/lightning-c-bindings/target/release/deps --cap-lints allow`
Running `rustc --crate-name bech32 /Users/jkczyz/.cargo/registry/src/github.com-1ecc6299db9ec823/bech32-0.7.2/src/lib.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts --crate-type lib --emit=dep-info,metadata,link -C opt-level=3 -Cembed-bitcode=no -C metadata=848e3766e44cacd7 -C extra-filename=-848e3766e44cacd7 --out-dir /Users/jkczyz/src/rust-lightning-review/lightning-c-bindings/target/release/deps -L dependency=/Users/jkczyz/src/rust-lightning-review/lightning-c-bindings/target/release/deps --cap-lints allow`
Compiling secp256k1-sys v0.2.0
Running `rustc --crate-name build_script_build /Users/jkczyz/.cargo/registry/src/github.com-1ecc6299db9ec823/secp256k1-sys-0.2.0/build.rs --error-format=json --json=diagnostic-rendered-ansi --crate-type bin --emit=dep-info,link -C opt-level=3 -Cembed-bitcode=no --cfg 'feature="std"' -C metadata=73b76d4b12ae7a7f -C extra-filename=-73b76d4b12ae7a7f --out-dir /Users/jkczyz/src/rust-lightning-review/lightning-c-bindings/target/release/build/secp256k1-sys-73b76d4b12ae7a7f -L dependency=/Users/jkczyz/src/rust-lightning-review/lightning-c-bindings/target/release/deps --extern cc=/Users/jkczyz/src/rust-lightning-review/lightning-c-bindings/target/release/deps/libcc-00dcc370fd0f6eb8.rlib --cap-lints allow`
Running `/Users/jkczyz/src/rust-lightning-review/lightning-c-bindings/target/release/build/secp256k1-sys-73b76d4b12ae7a7f/build-script-build`
Running `rustc --crate-name secp256k1_sys /Users/jkczyz/.cargo/registry/src/github.com-1ecc6299db9ec823/secp256k1-sys-0.2.0/src/lib.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts --crate-type lib --emit=dep-info,metadata,link -C opt-level=3 -Cembed-bitcode=no --cfg 'feature="std"' -C metadata=caf2e22195643b8f -C extra-filename=-caf2e22195643b8f --out-dir /Users/jkczyz/src/rust-lightning-review/lightning-c-bindings/target/release/deps -L dependency=/Users/jkczyz/src/rust-lightning-review/lightning-c-bindings/target/release/deps --cap-lints allow -L native=/Users/jkczyz/src/rust-lightning-review/lightning-c-bindings/target/release/build/secp256k1-sys-6ea31cf4a9c94cb1/out -l static=secp256k1`
Compiling secp256k1 v0.18.0
Running `rustc --crate-name secp256k1 /Users/jkczyz/.cargo/registry/src/github.com-1ecc6299db9ec823/secp256k1-0.18.0/src/lib.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts --crate-type lib --emit=dep-info,metadata,link -C opt-level=3 -Cembed-bitcode=no --cfg 'feature="default"' --cfg 'feature="std"' -C metadata=1eabee0c3285b09c -C extra-filename=-1eabee0c3285b09c --out-dir /Users/jkczyz/src/rust-lightning-review/lightning-c-bindings/target/release/deps -L dependency=/Users/jkczyz/src/rust-lightning-review/lightning-c-bindings/target/release/deps --extern secp256k1_sys=/Users/jkczyz/src/rust-lightning-review/lightning-c-bindings/target/release/deps/libsecp256k1_sys-caf2e22195643b8f.rmeta --cap-lints allow -L native=/Users/jkczyz/src/rust-lightning-review/lightning-c-bindings/target/release/build/secp256k1-sys-6ea31cf4a9c94cb1/out`
Compiling bitcoin v0.24.0
Running `rustc --crate-name bitcoin /Users/jkczyz/.cargo/registry/src/github.com-1ecc6299db9ec823/bitcoin-0.24.0/src/lib.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts --crate-type lib --emit=dep-info,metadata,link -C opt-level=3 -Cembed-bitcode=no -C metadata=e1b66b4ed9a90379 -C extra-filename=-e1b66b4ed9a90379 --out-dir /Users/jkczyz/src/rust-lightning-review/lightning-c-bindings/target/release/deps -L dependency=/Users/jkczyz/src/rust-lightning-review/lightning-c-bindings/target/release/deps --extern bech32=/Users/jkczyz/src/rust-lightning-review/lightning-c-bindings/target/release/deps/libbech32-848e3766e44cacd7.rmeta --extern bitcoin_hashes=/Users/jkczyz/src/rust-lightning-review/lightning-c-bindings/target/release/deps/libbitcoin_hashes-3f72b8b01c4f2e37.rmeta --extern secp256k1=/Users/jkczyz/src/rust-lightning-review/lightning-c-bindings/target/release/deps/libsecp256k1-1eabee0c3285b09c.rmeta --cap-lints allow -L native=/Users/jkczyz/src/rust-lightning-review/lightning-c-bindings/target/release/build/secp256k1-sys-6ea31cf4a9c94cb1/out`
Compiling lightning v0.0.11 (/Users/jkczyz/src/rust-lightning-review/lightning)
Running `rustc --crate-name lightning /Users/jkczyz/src/rust-lightning-review/lightning/src/lib.rs --error-format=json --json=diagnostic-rendered-ansi --crate-type lib --emit=dep-info,metadata,link -C opt-level=3 -Cembed-bitcode=no -C metadata=79da2e4794c19ffc -C extra-filename=-79da2e4794c19ffc --out-dir /Users/jkczyz/src/rust-lightning-review/lightning-c-bindings/target/release/deps -L dependency=/Users/jkczyz/src/rust-lightning-review/lightning-c-bindings/target/release/deps --extern bitcoin=/Users/jkczyz/src/rust-lightning-review/lightning-c-bindings/target/release/deps/libbitcoin-e1b66b4ed9a90379.rmeta -L native=/Users/jkczyz/src/rust-lightning-review/lightning-c-bindings/target/release/build/secp256k1-sys-6ea31cf4a9c94cb1/out`
Compiling lightning-c-bindings v0.0.1 (/Users/jkczyz/src/rust-lightning-review/lightning-c-bindings)
Running `rustc --crate-name ldk --edition=2018 src/lib.rs --error-format=json --json=diagnostic-rendered-ansi --crate-type staticlib --crate-type cdylib --emit=dep-info,link -C opt-level=3 -Cembed-bitcode=no -C lto -C metadata=fe50c7fd2ceda483 --out-dir /Users/jkczyz/src/rust-lightning-review/lightning-c-bindings/target/release/deps -L dependency=/Users/jkczyz/src/rust-lightning-review/lightning-c-bindings/target/release/deps --extern bitcoin=/Users/jkczyz/src/rust-lightning-review/lightning-c-bindings/target/release/deps/libbitcoin-e1b66b4ed9a90379.rlib --extern lightning=/Users/jkczyz/src/rust-lightning-review/lightning-c-bindings/target/release/deps/liblightning-79da2e4794c19ffc.rlib -L native=/Users/jkczyz/src/rust-lightning-review/lightning-c-bindings/target/release/build/secp256k1-sys-6ea31cf4a9c94cb1/out`
error: options `-C embed-bitcode=no` and `-C lto` are incompatible
error: could not compile `lightning-c-bindings`.
Caused by:
process didn't exit successfully: `rustc --crate-name ldk --edition=2018 src/lib.rs --error-format=json --json=diagnostic-rendered-ansi --crate-type staticlib --crate-type cdylib --emit=dep-info,link -C opt-level=3 -Cembed-bitcode=no -C lto -C metadata=fe50c7fd2ceda483 --out-dir /Users/jkczyz/src/rust-lightning-review/lightning-c-bindings/target/release/deps -L dependency=/Users/jkczyz/src/rust-lightning-review/lightning-c-bindings/target/release/deps --extern bitcoin=/Users/jkczyz/src/rust-lightning-review/lightning-c-bindings/target/release/deps/libbitcoin-e1b66b4ed9a90379.rlib --extern lightning=/Users/jkczyz/src/rust-lightning-review/lightning-c-bindings/target/release/deps/liblightning-79da2e4794c19ffc.rlib -L native=/Users/jkczyz/src/rust-lightning-review/lightning-c-bindings/target/release/build/secp256k1-sys-6ea31cf4a9c94cb1/out` (exit code: 1)

Comment threadlightning/src/ln/channelmanager.rs Outdated
@TheBlueMatt
TheBlueMattforce-pushed the 2020-11-bindings-clones branch from 6a3db9c to 674559cCompareNovember 23, 2020 15:29
@TheBlueMatt

Copy link
Copy Markdown
CollaboratorAuthor

No, but Val did note it previously and I wasn't able to reproduce on newer rustc so I forgot about it, sorry about that. I pushed a commit to fix it mostly based on Val's suggested patch at #721 (comment)

@codecov

codecovBot commented Nov 23, 2020

Copy link
Copy Markdown

Codecov Report

Merging #749 (1af6e34) into main (8f10a1d) will decrease coverage by 0.09%.
The diff coverage is 12.50%.

Impacted file tree graph

@@ Coverage Diff @@## main #749 +/- ##
==========================================
- Coverage 91.39% 91.29% -0.10% 
==========================================
Files 37 37 Lines 22249 22274 +25 ==========================================
+ Hits 20334 20335 +1 - Misses 1915 1939 +24 
Impacted FilesCoverage Δ
lightning/src/ln/chan_utils.rs95.66% <0.00%> (-0.31%)⬇️
lightning/src/ln/channelmanager.rs84.95% <0.00%> (-0.41%)⬇️
lightning/src/ln/msgs.rs89.60% <0.00%> (-0.48%)⬇️
lightning/src/routing/router.rs95.71% <0.00%> (-0.96%)⬇️
lightning/src/util/events.rs24.54% <0.00%> (ø)
lightning/src/chain/channelmonitor.rs95.44% <100.00%> (ø)
lightning/src/ln/functional_tests.rs96.96% <0.00%> (+0.01%)⬆️

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 8f10a1d...9fe3124. Read the comment docs.

…gdevkit#681)
Previously we'd ignored generic arguments in traits, leading to
bogus code generation after the Persister trait was added in lightningdevkit#681.
This adds minimal support for it, fixing code generation on latest
upstream.
When the only reference to the transaction bytes is via
Transaction::data, my understanding of the C const rules is that
it would then be invalid to write to it. While its unlikely this
would ever pose an issue, its not hard to simply make it *mut, so
we do that here.
CVecTempl previously called Vec.clone_from_slice() on a
newly-allocated Vec, which immediately panics as
[T].clone_from_slice() requires that the Vec/target slice already
has the same length as the source slice. This should have been
Vec.extend_from_slice() which exhibits the correct behavior.
This somewhat assumes that every public enum implements clone in
some way, but that is currently the case.
There is no reason not to and Clone can be useful especially in the
bindings context.
When a trait is required to implement eq/clone (eg in the case of
`SocketDescriptor`), the generated trait struct contains an
eq/clone function which takes a `this_arg` pointer. Since the trait
object can always be read to get the `this_arg` pointer, there is
no loss of generality to pass the trait object itself, and it
provides a bit more flexibility when the trait could be one of
several implementations (which we use in the Java higher-level
bindings).
Newer versions of cargo broke `cargo rustc -- -Clto` by passing
`-Cembed-bitcode=no` even in `--release`. Its somewhat unclear why
this is still the case on latest cargo given it broke, at least,
compilation of Firefox, as discovered by Val at [1]. We take the
approach they used there, even though they later walked it back [2]
but the issues noted there, especially in [3] don't seem
particularly concerning in our case.
[1] https://bugzilla.mozilla.org/show_bug.cgi?id=1640982
[2] https://bugzilla.mozilla.org/show_bug.cgi?id=1654465
[3] https://bugzilla.mozilla.org/show_bug.cgi?id=1654465#c5
@TheBlueMatt
TheBlueMattforce-pushed the 2020-11-bindings-clones branch from 674559c to 9fe3124CompareNovember 23, 2020 16:12
@TheBlueMatt

Copy link
Copy Markdown
CollaboratorAuthor

Also rebased on upstream git which changed ever so slightly.

@valentinewallacevalentinewallace left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM! Thanks for the fixes on genbindings, that seems to have worked for me (haven't figured out how to get the right clang version so haven't tested out the address-sanitizer parts, but otherwise the headers are generated 💪)

writeln!(w, "#[no_mangle]\npub extern \"C\" fn {}_free(this_ptr: {}) {{ }}", e.ident, e.ident).unwrap();
}
writeln!(w, "#[no_mangle]").unwrap();
writeln!(w, "pub extern \"C\" fn {}_clone(orig: &{}) -> {} {{", e.ident, e.ident, e.ident).unwrap();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Just to confirm, it's fine that some pub(enum)s in RL don't implement Clone?

Copy link
Copy Markdown
CollaboratorAuthor

Choose a reason for hiding this comment

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

Hmm, I mean I guess we should have them match, but its not an issue per se currently - if all the fields support Clone (as they would have to for the bindings crate to not fail to compile), then exposing a Clone to bindings seems fine.

@TheBlueMatt
TheBlueMatt merged commit 52673d4 into lightningdevkit:mainNov 23, 2020
@TheBlueMatt

Copy link
Copy Markdown
CollaboratorAuthor

Taking cause we need to get 0.0.12 out the door.

Sign up for freeto 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.

3 participants

@TheBlueMatt@jkczyz@valentinewallace
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Remove or un-stick sticky/fixed headers that block content\n(function() {\n function unstick() {\n document.querySelectorAll('header, nav, [role=\"banner\"], .header, .navbar, .sticky, .fixed-top, [style*=\"position: fixed\"], [style*=\"position:sticky\"]').forEach(function(el) {\n if (el.style.position === 'fixed' || el.style.position === 'sticky' || \n getComputedStyle(el).position === 'fixed' || getComputedStyle(el).position === 'sticky') {\n el.style.position = 'static';\n el.style.top = 'auto';\n el.style.zIndex = 'auto';\n }\n });\n }\n \n unstick();\n \n var observer = new MutationObserver(unstick);\n observer.observe(document.body, { childList: true, subtree: true, attributes: true, attributeFilter: ['style', 'class'] });\n})();", "Kill Sticky Headers"); } } catch(__e) { console.warn('[Userscript:Kill Sticky Headers]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content

Bindings Updates for #681 and more Clones - #749

Merged
TheBlueMatt merged 12 commits into
lightningdevkit:mainfrom
TheBlueMatt:2020-11-bindings-clones
Nov 23, 2020
Merged

Bindings Updates for #681 and more Clones#749
TheBlueMatt merged 12 commits into
lightningdevkit:mainfrom
TheBlueMatt:2020-11-bindings-clones

Conversation

@TheBlueMatt

Copy link
Copy Markdown
Collaborator

There was one trivial bit to fix for #681, but more importantly this adds much better and broader support for calling clone from the C bindings, which we rely on extensively in the Java bindings.

@TheBlueMattTheBlueMatt added this to the 0.0.12 milestone Nov 13, 2020

@jkczyzjkczyz left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Not sure if it is related, but I'm getting an error when running genbindings.sh on macOS:

+ cargo rustc -v --release -- -C lto
Compiling cc v1.0.65
Compiling bitcoin_hashes v0.8.0
Compiling bech32 v0.7.2
Running `rustc --crate-name cc --edition=2018 /Users/jkczyz/.cargo/registry/src/github.com-1ecc6299db9ec823/cc-1.0.65/src/lib.rs --error-format=json --json=diagnostic-rendered-ansi --crate-type lib --emit=dep-info,metadata,link -C opt-level=3 -Cembed-bitcode=no -C metadata=00dcc370fd0f6eb8 -C extra-filename=-00dcc370fd0f6eb8 --out-dir /Users/jkczyz/src/rust-lightning-review/lightning-c-bindings/target/release/deps -L dependency=/Users/jkczyz/src/rust-lightning-review/lightning-c-bindings/target/release/deps --cap-lints allow`
Running `rustc --crate-name bitcoin_hashes /Users/jkczyz/.cargo/registry/src/github.com-1ecc6299db9ec823/bitcoin_hashes-0.8.0/src/lib.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts --crate-type lib --emit=dep-info,metadata,link -C opt-level=3 -Cembed-bitcode=no --cfg 'feature="default"' --cfg 'feature="std"' -C metadata=3f72b8b01c4f2e37 -C extra-filename=-3f72b8b01c4f2e37 --out-dir /Users/jkczyz/src/rust-lightning-review/lightning-c-bindings/target/release/deps -L dependency=/Users/jkczyz/src/rust-lightning-review/lightning-c-bindings/target/release/deps --cap-lints allow`
Running `rustc --crate-name bech32 /Users/jkczyz/.cargo/registry/src/github.com-1ecc6299db9ec823/bech32-0.7.2/src/lib.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts --crate-type lib --emit=dep-info,metadata,link -C opt-level=3 -Cembed-bitcode=no -C metadata=848e3766e44cacd7 -C extra-filename=-848e3766e44cacd7 --out-dir /Users/jkczyz/src/rust-lightning-review/lightning-c-bindings/target/release/deps -L dependency=/Users/jkczyz/src/rust-lightning-review/lightning-c-bindings/target/release/deps --cap-lints allow`
Compiling secp256k1-sys v0.2.0
Running `rustc --crate-name build_script_build /Users/jkczyz/.cargo/registry/src/github.com-1ecc6299db9ec823/secp256k1-sys-0.2.0/build.rs --error-format=json --json=diagnostic-rendered-ansi --crate-type bin --emit=dep-info,link -C opt-level=3 -Cembed-bitcode=no --cfg 'feature="std"' -C metadata=73b76d4b12ae7a7f -C extra-filename=-73b76d4b12ae7a7f --out-dir /Users/jkczyz/src/rust-lightning-review/lightning-c-bindings/target/release/build/secp256k1-sys-73b76d4b12ae7a7f -L dependency=/Users/jkczyz/src/rust-lightning-review/lightning-c-bindings/target/release/deps --extern cc=/Users/jkczyz/src/rust-lightning-review/lightning-c-bindings/target/release/deps/libcc-00dcc370fd0f6eb8.rlib --cap-lints allow`
Running `/Users/jkczyz/src/rust-lightning-review/lightning-c-bindings/target/release/build/secp256k1-sys-73b76d4b12ae7a7f/build-script-build`
Running `rustc --crate-name secp256k1_sys /Users/jkczyz/.cargo/registry/src/github.com-1ecc6299db9ec823/secp256k1-sys-0.2.0/src/lib.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts --crate-type lib --emit=dep-info,metadata,link -C opt-level=3 -Cembed-bitcode=no --cfg 'feature="std"' -C metadata=caf2e22195643b8f -C extra-filename=-caf2e22195643b8f --out-dir /Users/jkczyz/src/rust-lightning-review/lightning-c-bindings/target/release/deps -L dependency=/Users/jkczyz/src/rust-lightning-review/lightning-c-bindings/target/release/deps --cap-lints allow -L native=/Users/jkczyz/src/rust-lightning-review/lightning-c-bindings/target/release/build/secp256k1-sys-6ea31cf4a9c94cb1/out -l static=secp256k1`
Compiling secp256k1 v0.18.0
Running `rustc --crate-name secp256k1 /Users/jkczyz/.cargo/registry/src/github.com-1ecc6299db9ec823/secp256k1-0.18.0/src/lib.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts --crate-type lib --emit=dep-info,metadata,link -C opt-level=3 -Cembed-bitcode=no --cfg 'feature="default"' --cfg 'feature="std"' -C metadata=1eabee0c3285b09c -C extra-filename=-1eabee0c3285b09c --out-dir /Users/jkczyz/src/rust-lightning-review/lightning-c-bindings/target/release/deps -L dependency=/Users/jkczyz/src/rust-lightning-review/lightning-c-bindings/target/release/deps --extern secp256k1_sys=/Users/jkczyz/src/rust-lightning-review/lightning-c-bindings/target/release/deps/libsecp256k1_sys-caf2e22195643b8f.rmeta --cap-lints allow -L native=/Users/jkczyz/src/rust-lightning-review/lightning-c-bindings/target/release/build/secp256k1-sys-6ea31cf4a9c94cb1/out`
Compiling bitcoin v0.24.0
Running `rustc --crate-name bitcoin /Users/jkczyz/.cargo/registry/src/github.com-1ecc6299db9ec823/bitcoin-0.24.0/src/lib.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts --crate-type lib --emit=dep-info,metadata,link -C opt-level=3 -Cembed-bitcode=no -C metadata=e1b66b4ed9a90379 -C extra-filename=-e1b66b4ed9a90379 --out-dir /Users/jkczyz/src/rust-lightning-review/lightning-c-bindings/target/release/deps -L dependency=/Users/jkczyz/src/rust-lightning-review/lightning-c-bindings/target/release/deps --extern bech32=/Users/jkczyz/src/rust-lightning-review/lightning-c-bindings/target/release/deps/libbech32-848e3766e44cacd7.rmeta --extern bitcoin_hashes=/Users/jkczyz/src/rust-lightning-review/lightning-c-bindings/target/release/deps/libbitcoin_hashes-3f72b8b01c4f2e37.rmeta --extern secp256k1=/Users/jkczyz/src/rust-lightning-review/lightning-c-bindings/target/release/deps/libsecp256k1-1eabee0c3285b09c.rmeta --cap-lints allow -L native=/Users/jkczyz/src/rust-lightning-review/lightning-c-bindings/target/release/build/secp256k1-sys-6ea31cf4a9c94cb1/out`
Compiling lightning v0.0.11 (/Users/jkczyz/src/rust-lightning-review/lightning)
Running `rustc --crate-name lightning /Users/jkczyz/src/rust-lightning-review/lightning/src/lib.rs --error-format=json --json=diagnostic-rendered-ansi --crate-type lib --emit=dep-info,metadata,link -C opt-level=3 -Cembed-bitcode=no -C metadata=79da2e4794c19ffc -C extra-filename=-79da2e4794c19ffc --out-dir /Users/jkczyz/src/rust-lightning-review/lightning-c-bindings/target/release/deps -L dependency=/Users/jkczyz/src/rust-lightning-review/lightning-c-bindings/target/release/deps --extern bitcoin=/Users/jkczyz/src/rust-lightning-review/lightning-c-bindings/target/release/deps/libbitcoin-e1b66b4ed9a90379.rmeta -L native=/Users/jkczyz/src/rust-lightning-review/lightning-c-bindings/target/release/build/secp256k1-sys-6ea31cf4a9c94cb1/out`
Compiling lightning-c-bindings v0.0.1 (/Users/jkczyz/src/rust-lightning-review/lightning-c-bindings)
Running `rustc --crate-name ldk --edition=2018 src/lib.rs --error-format=json --json=diagnostic-rendered-ansi --crate-type staticlib --crate-type cdylib --emit=dep-info,link -C opt-level=3 -Cembed-bitcode=no -C lto -C metadata=fe50c7fd2ceda483 --out-dir /Users/jkczyz/src/rust-lightning-review/lightning-c-bindings/target/release/deps -L dependency=/Users/jkczyz/src/rust-lightning-review/lightning-c-bindings/target/release/deps --extern bitcoin=/Users/jkczyz/src/rust-lightning-review/lightning-c-bindings/target/release/deps/libbitcoin-e1b66b4ed9a90379.rlib --extern lightning=/Users/jkczyz/src/rust-lightning-review/lightning-c-bindings/target/release/deps/liblightning-79da2e4794c19ffc.rlib -L native=/Users/jkczyz/src/rust-lightning-review/lightning-c-bindings/target/release/build/secp256k1-sys-6ea31cf4a9c94cb1/out`
error: options `-C embed-bitcode=no` and `-C lto` are incompatible
error: could not compile `lightning-c-bindings`.
Caused by:
process didn't exit successfully: `rustc --crate-name ldk --edition=2018 src/lib.rs --error-format=json --json=diagnostic-rendered-ansi --crate-type staticlib --crate-type cdylib --emit=dep-info,link -C opt-level=3 -Cembed-bitcode=no -C lto -C metadata=fe50c7fd2ceda483 --out-dir /Users/jkczyz/src/rust-lightning-review/lightning-c-bindings/target/release/deps -L dependency=/Users/jkczyz/src/rust-lightning-review/lightning-c-bindings/target/release/deps --extern bitcoin=/Users/jkczyz/src/rust-lightning-review/lightning-c-bindings/target/release/deps/libbitcoin-e1b66b4ed9a90379.rlib --extern lightning=/Users/jkczyz/src/rust-lightning-review/lightning-c-bindings/target/release/deps/liblightning-79da2e4794c19ffc.rlib -L native=/Users/jkczyz/src/rust-lightning-review/lightning-c-bindings/target/release/build/secp256k1-sys-6ea31cf4a9c94cb1/out` (exit code: 1)

Comment threadlightning/src/ln/channelmanager.rs Outdated
@TheBlueMatt
TheBlueMattforce-pushed the 2020-11-bindings-clones branch from 6a3db9c to 674559cCompareNovember 23, 2020 15:29
@TheBlueMatt

Copy link
Copy Markdown
CollaboratorAuthor

No, but Val did note it previously and I wasn't able to reproduce on newer rustc so I forgot about it, sorry about that. I pushed a commit to fix it mostly based on Val's suggested patch at #721 (comment)

@codecov

codecovBot commented Nov 23, 2020

Copy link
Copy Markdown

Codecov Report

Merging #749 (1af6e34) into main (8f10a1d) will decrease coverage by 0.09%.
The diff coverage is 12.50%.

Impacted file tree graph

@@ Coverage Diff @@## main #749 +/- ##
==========================================
- Coverage 91.39% 91.29% -0.10% 
==========================================
Files 37 37 Lines 22249 22274 +25 ==========================================
+ Hits 20334 20335 +1 - Misses 1915 1939 +24 
Impacted FilesCoverage Δ
lightning/src/ln/chan_utils.rs95.66% <0.00%> (-0.31%)⬇️
lightning/src/ln/channelmanager.rs84.95% <0.00%> (-0.41%)⬇️
lightning/src/ln/msgs.rs89.60% <0.00%> (-0.48%)⬇️
lightning/src/routing/router.rs95.71% <0.00%> (-0.96%)⬇️
lightning/src/util/events.rs24.54% <0.00%> (ø)
lightning/src/chain/channelmonitor.rs95.44% <100.00%> (ø)
lightning/src/ln/functional_tests.rs96.96% <0.00%> (+0.01%)⬆️

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 8f10a1d...9fe3124. Read the comment docs.

…gdevkit#681)
Previously we'd ignored generic arguments in traits, leading to
bogus code generation after the Persister trait was added in lightningdevkit#681.
This adds minimal support for it, fixing code generation on latest
upstream.
When the only reference to the transaction bytes is via
Transaction::data, my understanding of the C const rules is that
it would then be invalid to write to it. While its unlikely this
would ever pose an issue, its not hard to simply make it *mut, so
we do that here.
CVecTempl previously called Vec.clone_from_slice() on a
newly-allocated Vec, which immediately panics as
[T].clone_from_slice() requires that the Vec/target slice already
has the same length as the source slice. This should have been
Vec.extend_from_slice() which exhibits the correct behavior.
This somewhat assumes that every public enum implements clone in
some way, but that is currently the case.
There is no reason not to and Clone can be useful especially in the
bindings context.
When a trait is required to implement eq/clone (eg in the case of
`SocketDescriptor`), the generated trait struct contains an
eq/clone function which takes a `this_arg` pointer. Since the trait
object can always be read to get the `this_arg` pointer, there is
no loss of generality to pass the trait object itself, and it
provides a bit more flexibility when the trait could be one of
several implementations (which we use in the Java higher-level
bindings).
Newer versions of cargo broke `cargo rustc -- -Clto` by passing
`-Cembed-bitcode=no` even in `--release`. Its somewhat unclear why
this is still the case on latest cargo given it broke, at least,
compilation of Firefox, as discovered by Val at [1]. We take the
approach they used there, even though they later walked it back [2]
but the issues noted there, especially in [3] don't seem
particularly concerning in our case.
[1] https://bugzilla.mozilla.org/show_bug.cgi?id=1640982
[2] https://bugzilla.mozilla.org/show_bug.cgi?id=1654465
[3] https://bugzilla.mozilla.org/show_bug.cgi?id=1654465#c5
@TheBlueMatt
TheBlueMattforce-pushed the 2020-11-bindings-clones branch from 674559c to 9fe3124CompareNovember 23, 2020 16:12
@TheBlueMatt

Copy link
Copy Markdown
CollaboratorAuthor

Also rebased on upstream git which changed ever so slightly.

@valentinewallacevalentinewallace left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM! Thanks for the fixes on genbindings, that seems to have worked for me (haven't figured out how to get the right clang version so haven't tested out the address-sanitizer parts, but otherwise the headers are generated 💪)

writeln!(w, "#[no_mangle]\npub extern \"C\" fn {}_free(this_ptr: {}) {{ }}", e.ident, e.ident).unwrap();
}
writeln!(w, "#[no_mangle]").unwrap();
writeln!(w, "pub extern \"C\" fn {}_clone(orig: &{}) -> {} {{", e.ident, e.ident, e.ident).unwrap();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Just to confirm, it's fine that some pub(enum)s in RL don't implement Clone?

Copy link
Copy Markdown
CollaboratorAuthor

Choose a reason for hiding this comment

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

Hmm, I mean I guess we should have them match, but its not an issue per se currently - if all the fields support Clone (as they would have to for the bindings crate to not fail to compile), then exposing a Clone to bindings seems fine.

@TheBlueMatt
TheBlueMatt merged commit 52673d4 into lightningdevkit:mainNov 23, 2020
@TheBlueMatt

Copy link
Copy Markdown
CollaboratorAuthor

Taking cause we need to get 0.0.12 out the door.

Sign up for freeto 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.

3 participants

@TheBlueMatt@jkczyz@valentinewallace
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Universal Dark Mode - works on any site\n(function() {\n var enabled = true;\n \n function applyDarkMode() {\n if (!enabled) return;\n \n // Create style element if it doesn't exist\n var style = document.getElementById('universal-dark-mode-style');\n if (!style) {\n style = document.createElement('style');\n style.id = 'universal-dark-mode-style';\n document.head.appendChild(style);\n }\n \n // Dark mode CSS - inverts colors but preserves images/video\n style.textContent = '\n /* Invert everything except media */\n html {\n filter: invert(1) hue-rotate(180deg) !important;\n background: #1a1a2e !important;\n }\n \n /* Restore images, videos, iframes, canvas */\n img, video, iframe, canvas, svg, picture, [style*=\"background-image\"] {\n filter: invert(1) hue-rotate(180deg) !important;\n }\n \n /* Preserve specific elements that should not be inverted */\n .no-dark-mode, .no-dark-mode *,\n [data-theme=\"light\"], [data-theme=\"light\"],\n .ace_editor, .ace_editor *,\n .CodeMirror, .CodeMirror *,\n .monaco-editor, .monaco-editor *,\n .markdown-body pre, .markdown-body pre *,\n .highlight, .highlight *,\n pre code, pre code * {\n filter: none !important;\n }\n \n /* Fix common UI elements */\n .modal, .popup, .dropdown-menu, .tooltip, .popover {\n filter: invert(1) hue-rotate(180deg) !important;\n background: #2d2d44 !important;\n border-color: #444 !important;\n }\n \n /* Scrollbars */\n ::-webkit-scrollbar { background: #1a1a2e !important; }\n ::-webkit-scrollbar-thumb { background: #444 !important; }\n ::-webkit-scrollbar-thumb:hover { background: #555 !important; }\n \n /* Selection */\n ::selection { background: #4ecdc4 !important; color: #1a1a2e !important; }\n ::-moz-selection { background: #4ecdc4 !important; color: #1a1a2e !important; }\n ';\n }\n \n function removeDarkMode() {\n var style = document.getElementById('universal-dark-mode-style');\n if (style) style.remove();\n }\n \n // Toggle with Alt+Shift+D\n document.addEventListener('keydown', function(e) {\n if (e.altKey && e.shiftKey && e.key === 'D') {\n e.preventDefault();\n enabled = !enabled;\n if (enabled) {\n applyDarkMode();\n console.log('[Universal Dark Mode] Enabled');\n } else {\n removeDarkMode();\n console.log('[Universal Dark Mode] Disabled');\n }\n }\n });\n \n // Apply on load\n applyDarkMode();\n \n // Re-apply on dynamic content\n var observer = new MutationObserver(function(mutations) {\n if (enabled && !document.getElementById('universal-dark-mode-style')) {\n applyDarkMode();\n }\n });\n observer.observe(document.head, { childList: true });\n \n console.log('[Universal Dark Mode] Loaded - Press Alt+Shift+D to toggle');\n})();", "Universal Dark Mode"); } } catch(__e) { console.warn('[Userscript:Universal Dark Mode]', __e); } })(); })();
Skip to content

Bindings Updates for #681 and more Clones - #749

Merged
TheBlueMatt merged 12 commits into
lightningdevkit:mainfrom
TheBlueMatt:2020-11-bindings-clones
Nov 23, 2020
Merged

Bindings Updates for #681 and more Clones#749
TheBlueMatt merged 12 commits into
lightningdevkit:mainfrom
TheBlueMatt:2020-11-bindings-clones

Conversation

@TheBlueMatt

Copy link
Copy Markdown
Collaborator

There was one trivial bit to fix for #681, but more importantly this adds much better and broader support for calling clone from the C bindings, which we rely on extensively in the Java bindings.

@TheBlueMattTheBlueMatt added this to the 0.0.12 milestone Nov 13, 2020

@jkczyzjkczyz left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Not sure if it is related, but I'm getting an error when running genbindings.sh on macOS:

+ cargo rustc -v --release -- -C lto
Compiling cc v1.0.65
Compiling bitcoin_hashes v0.8.0
Compiling bech32 v0.7.2
Running `rustc --crate-name cc --edition=2018 /Users/jkczyz/.cargo/registry/src/github.com-1ecc6299db9ec823/cc-1.0.65/src/lib.rs --error-format=json --json=diagnostic-rendered-ansi --crate-type lib --emit=dep-info,metadata,link -C opt-level=3 -Cembed-bitcode=no -C metadata=00dcc370fd0f6eb8 -C extra-filename=-00dcc370fd0f6eb8 --out-dir /Users/jkczyz/src/rust-lightning-review/lightning-c-bindings/target/release/deps -L dependency=/Users/jkczyz/src/rust-lightning-review/lightning-c-bindings/target/release/deps --cap-lints allow`
Running `rustc --crate-name bitcoin_hashes /Users/jkczyz/.cargo/registry/src/github.com-1ecc6299db9ec823/bitcoin_hashes-0.8.0/src/lib.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts --crate-type lib --emit=dep-info,metadata,link -C opt-level=3 -Cembed-bitcode=no --cfg 'feature="default"' --cfg 'feature="std"' -C metadata=3f72b8b01c4f2e37 -C extra-filename=-3f72b8b01c4f2e37 --out-dir /Users/jkczyz/src/rust-lightning-review/lightning-c-bindings/target/release/deps -L dependency=/Users/jkczyz/src/rust-lightning-review/lightning-c-bindings/target/release/deps --cap-lints allow`
Running `rustc --crate-name bech32 /Users/jkczyz/.cargo/registry/src/github.com-1ecc6299db9ec823/bech32-0.7.2/src/lib.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts --crate-type lib --emit=dep-info,metadata,link -C opt-level=3 -Cembed-bitcode=no -C metadata=848e3766e44cacd7 -C extra-filename=-848e3766e44cacd7 --out-dir /Users/jkczyz/src/rust-lightning-review/lightning-c-bindings/target/release/deps -L dependency=/Users/jkczyz/src/rust-lightning-review/lightning-c-bindings/target/release/deps --cap-lints allow`
Compiling secp256k1-sys v0.2.0
Running `rustc --crate-name build_script_build /Users/jkczyz/.cargo/registry/src/github.com-1ecc6299db9ec823/secp256k1-sys-0.2.0/build.rs --error-format=json --json=diagnostic-rendered-ansi --crate-type bin --emit=dep-info,link -C opt-level=3 -Cembed-bitcode=no --cfg 'feature="std"' -C metadata=73b76d4b12ae7a7f -C extra-filename=-73b76d4b12ae7a7f --out-dir /Users/jkczyz/src/rust-lightning-review/lightning-c-bindings/target/release/build/secp256k1-sys-73b76d4b12ae7a7f -L dependency=/Users/jkczyz/src/rust-lightning-review/lightning-c-bindings/target/release/deps --extern cc=/Users/jkczyz/src/rust-lightning-review/lightning-c-bindings/target/release/deps/libcc-00dcc370fd0f6eb8.rlib --cap-lints allow`
Running `/Users/jkczyz/src/rust-lightning-review/lightning-c-bindings/target/release/build/secp256k1-sys-73b76d4b12ae7a7f/build-script-build`
Running `rustc --crate-name secp256k1_sys /Users/jkczyz/.cargo/registry/src/github.com-1ecc6299db9ec823/secp256k1-sys-0.2.0/src/lib.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts --crate-type lib --emit=dep-info,metadata,link -C opt-level=3 -Cembed-bitcode=no --cfg 'feature="std"' -C metadata=caf2e22195643b8f -C extra-filename=-caf2e22195643b8f --out-dir /Users/jkczyz/src/rust-lightning-review/lightning-c-bindings/target/release/deps -L dependency=/Users/jkczyz/src/rust-lightning-review/lightning-c-bindings/target/release/deps --cap-lints allow -L native=/Users/jkczyz/src/rust-lightning-review/lightning-c-bindings/target/release/build/secp256k1-sys-6ea31cf4a9c94cb1/out -l static=secp256k1`
Compiling secp256k1 v0.18.0
Running `rustc --crate-name secp256k1 /Users/jkczyz/.cargo/registry/src/github.com-1ecc6299db9ec823/secp256k1-0.18.0/src/lib.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts --crate-type lib --emit=dep-info,metadata,link -C opt-level=3 -Cembed-bitcode=no --cfg 'feature="default"' --cfg 'feature="std"' -C metadata=1eabee0c3285b09c -C extra-filename=-1eabee0c3285b09c --out-dir /Users/jkczyz/src/rust-lightning-review/lightning-c-bindings/target/release/deps -L dependency=/Users/jkczyz/src/rust-lightning-review/lightning-c-bindings/target/release/deps --extern secp256k1_sys=/Users/jkczyz/src/rust-lightning-review/lightning-c-bindings/target/release/deps/libsecp256k1_sys-caf2e22195643b8f.rmeta --cap-lints allow -L native=/Users/jkczyz/src/rust-lightning-review/lightning-c-bindings/target/release/build/secp256k1-sys-6ea31cf4a9c94cb1/out`
Compiling bitcoin v0.24.0
Running `rustc --crate-name bitcoin /Users/jkczyz/.cargo/registry/src/github.com-1ecc6299db9ec823/bitcoin-0.24.0/src/lib.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts --crate-type lib --emit=dep-info,metadata,link -C opt-level=3 -Cembed-bitcode=no -C metadata=e1b66b4ed9a90379 -C extra-filename=-e1b66b4ed9a90379 --out-dir /Users/jkczyz/src/rust-lightning-review/lightning-c-bindings/target/release/deps -L dependency=/Users/jkczyz/src/rust-lightning-review/lightning-c-bindings/target/release/deps --extern bech32=/Users/jkczyz/src/rust-lightning-review/lightning-c-bindings/target/release/deps/libbech32-848e3766e44cacd7.rmeta --extern bitcoin_hashes=/Users/jkczyz/src/rust-lightning-review/lightning-c-bindings/target/release/deps/libbitcoin_hashes-3f72b8b01c4f2e37.rmeta --extern secp256k1=/Users/jkczyz/src/rust-lightning-review/lightning-c-bindings/target/release/deps/libsecp256k1-1eabee0c3285b09c.rmeta --cap-lints allow -L native=/Users/jkczyz/src/rust-lightning-review/lightning-c-bindings/target/release/build/secp256k1-sys-6ea31cf4a9c94cb1/out`
Compiling lightning v0.0.11 (/Users/jkczyz/src/rust-lightning-review/lightning)
Running `rustc --crate-name lightning /Users/jkczyz/src/rust-lightning-review/lightning/src/lib.rs --error-format=json --json=diagnostic-rendered-ansi --crate-type lib --emit=dep-info,metadata,link -C opt-level=3 -Cembed-bitcode=no -C metadata=79da2e4794c19ffc -C extra-filename=-79da2e4794c19ffc --out-dir /Users/jkczyz/src/rust-lightning-review/lightning-c-bindings/target/release/deps -L dependency=/Users/jkczyz/src/rust-lightning-review/lightning-c-bindings/target/release/deps --extern bitcoin=/Users/jkczyz/src/rust-lightning-review/lightning-c-bindings/target/release/deps/libbitcoin-e1b66b4ed9a90379.rmeta -L native=/Users/jkczyz/src/rust-lightning-review/lightning-c-bindings/target/release/build/secp256k1-sys-6ea31cf4a9c94cb1/out`
Compiling lightning-c-bindings v0.0.1 (/Users/jkczyz/src/rust-lightning-review/lightning-c-bindings)
Running `rustc --crate-name ldk --edition=2018 src/lib.rs --error-format=json --json=diagnostic-rendered-ansi --crate-type staticlib --crate-type cdylib --emit=dep-info,link -C opt-level=3 -Cembed-bitcode=no -C lto -C metadata=fe50c7fd2ceda483 --out-dir /Users/jkczyz/src/rust-lightning-review/lightning-c-bindings/target/release/deps -L dependency=/Users/jkczyz/src/rust-lightning-review/lightning-c-bindings/target/release/deps --extern bitcoin=/Users/jkczyz/src/rust-lightning-review/lightning-c-bindings/target/release/deps/libbitcoin-e1b66b4ed9a90379.rlib --extern lightning=/Users/jkczyz/src/rust-lightning-review/lightning-c-bindings/target/release/deps/liblightning-79da2e4794c19ffc.rlib -L native=/Users/jkczyz/src/rust-lightning-review/lightning-c-bindings/target/release/build/secp256k1-sys-6ea31cf4a9c94cb1/out`
error: options `-C embed-bitcode=no` and `-C lto` are incompatible
error: could not compile `lightning-c-bindings`.
Caused by:
process didn't exit successfully: `rustc --crate-name ldk --edition=2018 src/lib.rs --error-format=json --json=diagnostic-rendered-ansi --crate-type staticlib --crate-type cdylib --emit=dep-info,link -C opt-level=3 -Cembed-bitcode=no -C lto -C metadata=fe50c7fd2ceda483 --out-dir /Users/jkczyz/src/rust-lightning-review/lightning-c-bindings/target/release/deps -L dependency=/Users/jkczyz/src/rust-lightning-review/lightning-c-bindings/target/release/deps --extern bitcoin=/Users/jkczyz/src/rust-lightning-review/lightning-c-bindings/target/release/deps/libbitcoin-e1b66b4ed9a90379.rlib --extern lightning=/Users/jkczyz/src/rust-lightning-review/lightning-c-bindings/target/release/deps/liblightning-79da2e4794c19ffc.rlib -L native=/Users/jkczyz/src/rust-lightning-review/lightning-c-bindings/target/release/build/secp256k1-sys-6ea31cf4a9c94cb1/out` (exit code: 1)

Comment threadlightning/src/ln/channelmanager.rs Outdated
@TheBlueMatt
TheBlueMattforce-pushed the 2020-11-bindings-clones branch from 6a3db9c to 674559cCompareNovember 23, 2020 15:29
@TheBlueMatt

Copy link
Copy Markdown
CollaboratorAuthor

No, but Val did note it previously and I wasn't able to reproduce on newer rustc so I forgot about it, sorry about that. I pushed a commit to fix it mostly based on Val's suggested patch at #721 (comment)

@codecov

codecovBot commented Nov 23, 2020

Copy link
Copy Markdown

Codecov Report

Merging #749 (1af6e34) into main (8f10a1d) will decrease coverage by 0.09%.
The diff coverage is 12.50%.

Impacted file tree graph

@@ Coverage Diff @@## main #749 +/- ##
==========================================
- Coverage 91.39% 91.29% -0.10% 
==========================================
Files 37 37 Lines 22249 22274 +25 ==========================================
+ Hits 20334 20335 +1 - Misses 1915 1939 +24 
Impacted FilesCoverage Δ
lightning/src/ln/chan_utils.rs95.66% <0.00%> (-0.31%)⬇️
lightning/src/ln/channelmanager.rs84.95% <0.00%> (-0.41%)⬇️
lightning/src/ln/msgs.rs89.60% <0.00%> (-0.48%)⬇️
lightning/src/routing/router.rs95.71% <0.00%> (-0.96%)⬇️
lightning/src/util/events.rs24.54% <0.00%> (ø)
lightning/src/chain/channelmonitor.rs95.44% <100.00%> (ø)
lightning/src/ln/functional_tests.rs96.96% <0.00%> (+0.01%)⬆️

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 8f10a1d...9fe3124. Read the comment docs.

…gdevkit#681)
Previously we'd ignored generic arguments in traits, leading to
bogus code generation after the Persister trait was added in lightningdevkit#681.
This adds minimal support for it, fixing code generation on latest
upstream.
When the only reference to the transaction bytes is via
Transaction::data, my understanding of the C const rules is that
it would then be invalid to write to it. While its unlikely this
would ever pose an issue, its not hard to simply make it *mut, so
we do that here.
CVecTempl previously called Vec.clone_from_slice() on a
newly-allocated Vec, which immediately panics as
[T].clone_from_slice() requires that the Vec/target slice already
has the same length as the source slice. This should have been
Vec.extend_from_slice() which exhibits the correct behavior.
This somewhat assumes that every public enum implements clone in
some way, but that is currently the case.
There is no reason not to and Clone can be useful especially in the
bindings context.
When a trait is required to implement eq/clone (eg in the case of
`SocketDescriptor`), the generated trait struct contains an
eq/clone function which takes a `this_arg` pointer. Since the trait
object can always be read to get the `this_arg` pointer, there is
no loss of generality to pass the trait object itself, and it
provides a bit more flexibility when the trait could be one of
several implementations (which we use in the Java higher-level
bindings).
Newer versions of cargo broke `cargo rustc -- -Clto` by passing
`-Cembed-bitcode=no` even in `--release`. Its somewhat unclear why
this is still the case on latest cargo given it broke, at least,
compilation of Firefox, as discovered by Val at [1]. We take the
approach they used there, even though they later walked it back [2]
but the issues noted there, especially in [3] don't seem
particularly concerning in our case.
[1] https://bugzilla.mozilla.org/show_bug.cgi?id=1640982
[2] https://bugzilla.mozilla.org/show_bug.cgi?id=1654465
[3] https://bugzilla.mozilla.org/show_bug.cgi?id=1654465#c5
@TheBlueMatt
TheBlueMattforce-pushed the 2020-11-bindings-clones branch from 674559c to 9fe3124CompareNovember 23, 2020 16:12
@TheBlueMatt

Copy link
Copy Markdown
CollaboratorAuthor

Also rebased on upstream git which changed ever so slightly.

@valentinewallacevalentinewallace left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM! Thanks for the fixes on genbindings, that seems to have worked for me (haven't figured out how to get the right clang version so haven't tested out the address-sanitizer parts, but otherwise the headers are generated 💪)

writeln!(w, "#[no_mangle]\npub extern \"C\" fn {}_free(this_ptr: {}) {{ }}", e.ident, e.ident).unwrap();
}
writeln!(w, "#[no_mangle]").unwrap();
writeln!(w, "pub extern \"C\" fn {}_clone(orig: &{}) -> {} {{", e.ident, e.ident, e.ident).unwrap();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Just to confirm, it's fine that some pub(enum)s in RL don't implement Clone?

Copy link
Copy Markdown
CollaboratorAuthor

Choose a reason for hiding this comment

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

Hmm, I mean I guess we should have them match, but its not an issue per se currently - if all the fields support Clone (as they would have to for the bindings crate to not fail to compile), then exposing a Clone to bindings seems fine.

@TheBlueMatt
TheBlueMatt merged commit 52673d4 into lightningdevkit:mainNov 23, 2020
@TheBlueMatt

Copy link
Copy Markdown
CollaboratorAuthor

Taking cause we need to get 0.0.12 out the door.

Sign up for freeto 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.

3 participants

@TheBlueMatt@jkczyz@valentinewallace