From 18d911bfb15cd3219e4a4d046f96ca3b1c2e3d5f Mon Sep 17 00:00:00 2001 From: Maddiaa <47148561+Maddiaa0@users.noreply.github.com> Date: Tue, 5 Sep 2023 20:49:46 +0100 Subject: [PATCH] feat(flags): add support for feature flags (#37) --- .github/workflows/ci.yml | 16 +++++++++++++++- noirup | 20 ++++++++++++++++++-- 2 files changed, 33 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c1b2df6..056404f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -115,8 +115,22 @@ jobs: - run: nargo new project - run: nargo check working-directory: ./project - - run: nargo compile test-circuit + - run: | + # Extract the minor version number from the version output + version=$(nargo --version) + version="${version#* }" + version="${version%% (*}" + minor=$(echo $version | cut -d '.' -f 2) + + # The version in which the compile syntax changed + if [ "$minor" -lt 10 ]; then + nargo compile test-circuit + else + nargo compile + fi + name: nargo compile working-directory: ./project + shell: bash - run: nargo test if: matrix.toolchain != '0.1.0' working-directory: ./project diff --git a/noirup b/noirup index 46513c2..c78a3b9 100755 --- a/noirup +++ b/noirup @@ -16,6 +16,7 @@ main() { -r|--repo) shift; NOIRUP_REPO=$1;; -b|--branch) shift; NOIRUP_BRANCH=$1;; -v|--version) shift; NOIRUP_VERSION=$1;; + -f|--features) shift; NOIRUP_FEATURES=$1;; -p|--path) shift; NOIRUP_LOCAL_REPO=$1;; -P|--pr) shift; NOIRUP_PR=$1;; -C|--commit) shift; NOIRUP_COMMIT=$1;; @@ -28,6 +29,16 @@ main() { esac; shift done + # Input string is a space delimited list of features + # Build a string of feature flags to pass to cargo + FEATURES="" + if [ -n "$NOIRUP_FEATURES" ]; then + # "aztec bn254" -> "--features aztec --features bn254" + for feature in $NOIRUP_FEATURES; do + FEATURES+="--features $feature " + done + fi + if [ -n "$NOIRUP_PR" ]; then if [ -z "$NOIRUP_BRANCH" ]; then NOIRUP_BRANCH="refs/pull/$NOIRUP_PR/head" @@ -48,7 +59,7 @@ main() { # Enter local repo and build say "installing from $NOIRUP_LOCAL_REPO" cd $NOIRUP_LOCAL_REPO - RUSTFLAGS="-C target-cpu=native" ensure cargo build --release # need 4 speed + RUSTFLAGS="-C target-cpu=native" ensure cargo build --release $FEATURES # need 4 speed # Remove prior installations if they exist rm -f "$NARGO_BIN_DIR/nargo" @@ -60,6 +71,10 @@ main() { exit 0 fi + if [ -n "${NOIRUP_FEATURES}" ]; then + echo "Warning: [-f | --features] flag has no effect when installing a prebuilt binary" + fi + NOIRUP_REPO=${NOIRUP_REPO-noir-lang/noir} if [[ "$NOIRUP_REPO" == "noir-lang/noir" && -z "$NOIRUP_BRANCH" && -z "$NOIRUP_COMMIT" ]]; then PLATFORM="$(uname -s)" @@ -146,7 +161,7 @@ main() { ensure git checkout ${NOIRUP_COMMIT} fi - RUSTFLAGS="-C target-cpu=native" ensure cargo build --release + RUSTFLAGS="-C target-cpu=native" ensure cargo build --release $FEATURES # Remove prior installations if they exist rm -f "$NARGO_BIN_DIR/nargo" @@ -177,6 +192,7 @@ OPTIONS: -C, --commit Install a specific commit -r, --repo Install from a remote GitHub repo (uses default branch if no other options are set) -p, --path Install a local repository + -f, --features Activates feature flags when building from source: "feature1 feature2" EOF }