Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add CI to check for banned CLI dynamic deps #10338

Merged
merged 1 commit into from
Oct 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions .github/workflows/cli-external-deps.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: "Check banned CLI dynamic deps"
on:
pull_request:
types: [labeled, opened, synchronize, reopened, auto_merge_enabled]
push:
branches:
- main
workflow_dispatch:

jobs:
check-dynamic-deps:
runs-on: macos-latest
steps:
- uses: actions/checkout@v3
if: ${{ !inputs.SKIP_JOB }}
with:
ref: ${{ inputs.GIT_SHA }}

# This will exit with failure if any of the banned dynamic deps are found.
- run: ./crates/aptos/scripts/check_dynamic_deps.sh
46 changes: 46 additions & 0 deletions crates/aptos/scripts/check_dynamic_deps.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#!/bin/sh

# This script checks if the CLI depends on external deps that it shouldn't. We run this
# in CI to make sure we don't accidentally reintroduce deps that would make the CLI
# unusable on most systems.
#
# While it would be more reliable to actually build the CLI and check what libraries it
# links to, e.g. with otool, it is much cheaper to use cargo tree. As far as I can tell
# the entire Rust ecosystem makes use of these `x-sys` libraries to depend on external
# dynamically linked libraries.
#
# We can almost use cargo deny but it doesn't support checking specific build paths. We
# don't care if openssl-sys for example is used at build time (which it is, indirectly
# by shadow-rs), only at run time. See more here:
# https://github.com/EmbarkStudios/cargo-deny/issues/563
#
# It assumes cargo and friends are available.
#
# Run this from the root of the repo.
Copy link
Contributor

Choose a reason for hiding this comment

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

root of the repo as /aptos-core?


declare -a deps=("pq-sys" "openssl-sys")

for dep in "${deps[@]}"; do
echo "Checking for banned dependency $dep..."

# Check for deps. As you can see, we only check for MacOS right now.
out=`cargo tree -e features,no-build,no-dev --target aarch64-apple-darwin -p aptos -i "$dep"`

# If the exit status was non-zero, great, the dep couldn't be found.
if [ $? -ne 0 ]; then
continue
fi

# If the exit status was zero we have to check the output to see if the dep is in
# use. If it is in the output, it is in use.
if [[ $out != *"$dep"* ]]; then
continue
fi

echo "Banned dependency $dep found!"
exit 1
done

echo
echo "None of the banned dependencies are in use, great!"
exit 0
Loading