New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fully encapsulate bitcoinconsensus #2278
Fully encapsulate bitcoinconsensus #2278
Conversation
I tested this using the following script #!/usr/bin/env bash
#
# Checks the public API of crates, exits with non-zero if there are currently
# changes to the public API not already committed to in the various api/*.txt
# files.
set -e
export RUSTDOCFLAGS='-A rustdoc::broken-intra-doc-links'
REPO_DIR=$(git rev-parse --show-toplevel)
API_DIR="$REPO_DIR/api"
CMD="cargo +nightly public-api --simplified"
# cargo public-api uses nightly so the toolchain must be available.
if ! cargo +nightly --version > /dev/null; then
echo "script requires a nightly toolchain to be installed (possibly >= nightly-2023-05-24)" >&2
exit 1
fi
pushd "$REPO_DIR/bitcoin" > /dev/null
$CMD | sort --unique > "$API_DIR/bitcoin/api-default-features.txt"
$CMD --features=all-stable-features | sort --unique > "$API_DIR/bitcoin/api-all-stable-features.txt"
$CMD --all-features | sort --unique > "$API_DIR/bitcoin/api-all-features.txt"
popd > /dev/null
pushd "$REPO_DIR/hashes" > /dev/null
$CMD --no-default-features | sort --unique > "$API_DIR/hashes/api-no-features.txt"
$CMD | sort --unique > "$API_DIR/hashes/api-default-features.txt"
$CMD --no-default-features --features=alloc | sort --unique > "$API_DIR/hashes/api-alloc.txt"
$CMD --all-features | sort --unique > "$API_DIR/hashes/api-all-features.txt"
popd > /dev/null
pushd "$REPO_DIR" > /dev/null
if [[ $(git status --porcelain api) ]]; then
echo "You have introduced changes to the public API, commit the changes to api/ currently in your working directory" >&2
else
echo "No changes to the current public API"
fi
popd > /dev/null Grepping the output files we get:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ACK 135d143
Needs #2279 |
135d143
to
2795b07
Compare
Rebased to pick up #2279, no other changes. |
Looks good to me! Would like @Kixunil's opinion on this feature organization to enable gated |
2795b07
to
50d981a
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ACK 2795b07
Out of curiosity, what are some of the differences between why tokio also requires RUSTFLAGS? (Compared to this PR) |
My guess is so that |
Yeah that was my thought process too. |
They explain it here: https://internals.rust-lang.org/t/feature-request-unstable-opt-in-non-transitive-crate-features/16193#why-not-a-crate-feature-2 Concept ACK having an unstable feature (I had some other ideas too) however, I think the reason for not using cargo features is sound so I'd prefer that way and secondly, I think it's very little value here since people can explicitly depend on a specific version of |
Yeah, I like their reasoning. Let's use a cfg flag rather than a feature. |
The `bitcoinconsensus` crate is not fully under our control because it exposes code from Core, so we cannot guarantee its stability across versions. To make our semver compliance easier we can fully encapsulate the `bitcoinconsensus` crate so it does not appear in our public API. However, it is useful to have the crate itself exported, here we add an "unstable" feature and only publicly export the `bitcoinconsensus` crate if the "unstable" feature is enabled.
50d981a
to
43b1ed1
Compare
Flagging that this PR does not add any feature, cfg or cargo, because it now just does not re-export the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ACK 43b1ed1
/// Bitcoin's libbitcoinconsensus with Rust binding. | ||
pub extern crate bitcoinconsensus; | ||
#[cfg(feature = "bitcoinconsensus")] | ||
extern crate bitcoinconsensus; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this is needed at all now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had the same thought, but didn't check. (In Rust post-2018 non-pub
extern crate
s are no-ops, I believe.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pub
are not no-ops (they are reexports) but non-pub are.
This is fine, though I'd like to revisit it at some point. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ACK 43b1ed1
In rust-bitcoin#2278 I mistakenly left in the `use extern crate` after removing the `pub` from it - while not incorrect it is unnecessary.
0d9c7ad Remove unnecessary private extern crate (Tobin C. Harding) Pull request description: In #2278 I mistakenly left in the `use extern crate` after removing the `pub` from it - while not incorrect it is unnecessary. ACKs for top commit: apoelstra: ACK 0d9c7ad Tree-SHA512: 60a2638feda2ca5aea234de74fc751c8c140a47946f20cac95d804099f0ba7c78d8eef51912446024e2aafa97008bb93334c0fd3e97267a7f91c4ab86ffcd908
The
bitcoinconsensus
crate is not fully under our control because it exposes code from Core, so we cannot guarantee its stability across versions. To make our semver compliance easier we can fully encapsulate thebitcoinconsensus
crate so it does not appear in our public API.Please note that with this applied:
bitcoinconsenus
crate is no longer exported at the crate rootbitcoinconsensus
types appear in our public API