From 728a79ca16c962462090b25959d1eab0f1e9f47f Mon Sep 17 00:00:00 2001 From: Tom French <15848336+TomAFrench@users.noreply.github.com> Date: Wed, 13 Sep 2023 10:45:23 +0100 Subject: [PATCH] chore: add a Nargo workspace in `noir-contracts` (#2083) This PR creates a Nargo workspace for the `noir-contracts` package. This is useful for a mystery project. # Checklist: Remove the checklist to signal you've completed it. Enable auto-merge if the PR is ready to merge. - [ ] If the pull request requires a cryptography review (e.g. cryptographic algorithm implementations) I have added the 'crypto' tag. - [x] I have reviewed my diff in github, line by line and removed unexpected formatting changes, testing logs, or commented-out code. - [x] Every change is related to the PR description. - [ ] I have [linked](https://docs.github.com/en/issues/tracking-your-work-with-issues/linking-a-pull-request-to-an-issue) this pull request to relevant issues (if any exist). --- yarn-project/noir-contracts/Nargo.toml | 27 +++++++++++++++++++ .../noir-contracts/scripts/compile.sh | 6 ++--- .../noir-contracts/src/scripts/copy_output.ts | 6 ++--- yarn-project/yarn-project-base/Dockerfile | 1 + 4 files changed, 34 insertions(+), 6 deletions(-) create mode 100644 yarn-project/noir-contracts/Nargo.toml diff --git a/yarn-project/noir-contracts/Nargo.toml b/yarn-project/noir-contracts/Nargo.toml new file mode 100644 index 00000000000..d3300102923 --- /dev/null +++ b/yarn-project/noir-contracts/Nargo.toml @@ -0,0 +1,27 @@ +[workspace] +members = [ + "src/contracts/card_game_contract", + "src/contracts/child_contract", + "src/contracts/docs_example_contract", + "src/contracts/easy_private_token_contract", + "src/contracts/ecdsa_account_contract", + "src/contracts/escrow_contract", + "src/contracts/import_test_contract", + "src/contracts/lending_contract", + "src/contracts/multi_transfer_contract", + "src/contracts/native_token_contract", + "src/contracts/non_native_token_contract", + "src/contracts/parent_contract", + "src/contracts/pending_commitments_contract", + "src/contracts/pokeable_token_contract", + "src/contracts/price_feed_contract", + "src/contracts/private_token_airdrop_contract", + "src/contracts/private_token_contract", + "src/contracts/public_token_contract", + "src/contracts/schnorr_account_contract", + "src/contracts/schnorr_auth_witness_account_contract", + "src/contracts/schnorr_hardcoded_account_contract", + "src/contracts/schnorr_single_key_account_contract", + "src/contracts/test_contract", + "src/contracts/uniswap_contract", +] diff --git a/yarn-project/noir-contracts/scripts/compile.sh b/yarn-project/noir-contracts/scripts/compile.sh index 4a9555b0b1e..08c02e73a45 100755 --- a/yarn-project/noir-contracts/scripts/compile.sh +++ b/yarn-project/noir-contracts/scripts/compile.sh @@ -34,11 +34,11 @@ build() { CONTRACT_NAME=$1 CONTRACT_FOLDER="${CONTRACT_NAME}_contract" echo "Compiling $CONTRACT_NAME..." - cd src/contracts/$CONTRACT_FOLDER - rm -f target/* + rm -f target/${CONTRACT_FOLDER}-* + rm -f target/debug_${CONTRACT_FOLDER}-* # If the compilation fails, rerun the compilation with 'nargo' and show the compiler output. - nargo compile --output-debug; + nargo compile --package $CONTRACT_FOLDER --output-debug; } # Check nargo version matches the expected one diff --git a/yarn-project/noir-contracts/src/scripts/copy_output.ts b/yarn-project/noir-contracts/src/scripts/copy_output.ts index 1b6150fe58b..05da55f50be 100644 --- a/yarn-project/noir-contracts/src/scripts/copy_output.ts +++ b/yarn-project/noir-contracts/src/scripts/copy_output.ts @@ -50,19 +50,18 @@ const main = () => { if (!name) throw new Error(`Missing argument contract name`); const projectName = `${snakeCase(name)}_contract`; - const projectDirPath = `src/contracts/${projectName}`; const contractName = upperFirst(camelCase(name)); const artifactFile = `${projectName}-${contractName}.json`; - const buildJsonFilePath = `${projectDirPath}/target/${artifactFile}`; + const buildJsonFilePath = `./target/${artifactFile}`; const buildJson = JSON.parse(readFileSync(buildJsonFilePath).toString()); const debugArtifactFile = `debug_${artifactFile}`; let debug = undefined; try { - const debugJsonFilePath = `${projectDirPath}/target/${debugArtifactFile}`; + const debugJsonFilePath = `./target/${debugArtifactFile}`; const debugJson = JSON.parse(readFileSync(debugJsonFilePath).toString()); if (debugJson) { debug = debugJson; @@ -91,6 +90,7 @@ const main = () => { // Write a .nr contract interface, for consumption by other Noir Contracts if (INTERFACE_CONTRACTS.includes(name)) { + const projectDirPath = `src/contracts/${projectName}`; const noirInterfaceDestFilePath = `${projectDirPath}/src/interface.nr`; try { writeFileSync(noirInterfaceDestFilePath, generateNoirContractInterface(artifactJson)); diff --git a/yarn-project/yarn-project-base/Dockerfile b/yarn-project/yarn-project-base/Dockerfile index 29f29172995..abb55baad30 100644 --- a/yarn-project/yarn-project-base/Dockerfile +++ b/yarn-project/yarn-project-base/Dockerfile @@ -117,6 +117,7 @@ WORKDIR /usr/src/yarn-project FROM builder_ as noir_types COPY . . COPY --from=noir /usr/src/yarn-project/noir-contracts/src/contracts /usr/src/yarn-project/noir-contracts/src/contracts +COPY --from=noir /usr/src/yarn-project/noir-contracts/target /usr/src/yarn-project/noir-contracts/target WORKDIR /usr/src/yarn-project/noir-contracts # Run yarn build to have the json ABIs available for the types generator