Skip to content
This repository was archived by the owner on Mar 27, 2025. It is now read-only.
Closed
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 .envrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Based on https://github.com/direnv/direnv-vscode/blob/158e8302c2594cc0eaa5f8b4f0cafedd4e1c0315/.envrc

# You can define your system-specific logic (like Git settings or GH tokens) in .envrc.local
# If that logic is usable by other people and might improve development environment, consider
# contributing it to this file!

source_env_if_exists .envrc.local

if [[ -z "${SKIP_NIX:-}" ]] && has nix; then

if nix flake metadata &>/dev/null && has use_flake; then
# use flakes if possible
use flake

else
# Otherwise fall back to pure nix
use nix
fi

fi
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,7 @@
# These are backup files generated by rustfmt
**/*.rs.bk

# Generated by nix
# Nix stuff
result
.envrc.local
.direnv
13 changes: 13 additions & 0 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
// See https://go.microsoft.com/fwlink/?LinkId=827846 to learn about workspace recommendations.
// Extension identifier format: ${publisher}.${name}. Example: vscode.csharp
// List of extensions which should be recommended for users of this workspace.
"recommendations": [
"mkhl.direnv",
"jnoortheen.nix-ide",
"rust-lang.rust-analyzer",
"redhat.vscode-yaml"
],
// List of extensions recommended by VS Code that should not be recommended for users of this workspace.
"unwantedRecommendations": []
}
16 changes: 16 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"direnv.restart.automatic": true,
"redhat.telemetry.enabled": false,
"yaml.recommendations.show": false,
"nix.serverPath": "nil",
"nix.enableLanguageServer": true,
"nix.serverSettings": {
"nil": {
"formatting": {
"command": [
"nixpkgs-fmt"
]
}
}
},
}
78 changes: 76 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,80 @@ pub fn pedersen() {
}
```

## Nix
## Working on this project

We provide a [Nix Flake](./flake.nix) that shows you how to configure an environment if you're building your Rust code inside Nix.
Due to the large number of native dependencies, this project uses [Nix](https://nixos.org/) and [direnv](https://direnv.net/) to streamline the development experience.

### Setting up your environment

For the best experience, please follow these instructions to setup your environment:
1. Install Nix following [their guide](https://nixos.org/download.html) for your operating system
2. Create the file `~/.config/nix/nix.conf` with the contents:
```ini
experimental-features = nix-command
extra-experimental-features = flakes
```
3. Install direnv into your Nix profile by running:
```sh
nix profile install nixpkgs#direnv
```
4. Add direnv to your shell following [their guide](https://direnv.net/docs/hook.html)
5. Restart your shell

### Shell & editor experience

Now that your environment is set up, you can get to work on the project.

1. Clone the repository, such as:
```sh
git clone git@github.com:noir-lang/barretenberg-sys
```
2. Navigate to the directory:
```sh
cd barretenberg-sys
```
3. You should see a __direnv error__ because projects aren't allowed by default. Make sure you trust our `.envrc` file, then you need to run:
```sh
direnv allow
```
4. Now, wait awhile for all the native dependencies to be built. This will take some time and direnv will warn you that it is taking a long time, but we just need to let it run.
5. Once you are presented with your prompt again, you can start your editor within the project directory (we recommend [VSCode](https://code.visualstudio.com/)):
```sh
code .
```
6. (Recommended) When launching VSCode for the first time, you should be prompted to install our recommended plugins. We highly recommend installing these for the best development experience.

### Building and testing

Building and testing the project is done through Nix commands.

To build the project, run `nix build .` (or `nix build . -L` for verbose output).

To run clippy and all tests in the project, run `nix flake check` (or `nix flake check -L` for verbose output).

### Building against a different local/remote version of Barretenberg

If you are working on this crate, it is likely that you want to incorporate changes from some other version of Barretenberg
instead of the version this project is pinned against.

To reference a different version of Barretenberg, you can add the `--override-input` flag. For example:

```sh
nix build . --override-input barretenberg /home/phated/barretenberg
```

```sh
nix flake check --override-input barretenberg /home/phated/barretenberg
```

```sh
nix flake check --override-input barretenberg github:phated/barretenberg/mybranch
```

### Without direnv

If you have hesitations with using `direnv`, you can launch a subshell with `nix develop` and then launch your editor
from within the subshell.

__Note:__ If you aren't using direnv nor launch your editor within the subshell, your editor won't have the correct environment
variables to find system dependencies and probably won't be able to build the project.
2 changes: 2 additions & 0 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ fn main() -> Result<()> {
.allowlist_function("acir_proofs_get_total_circuit_size")
.allowlist_function("acir_proofs_init_proving_key")
.allowlist_function("acir_proofs_init_verification_key")
.allowlist_function("acir_serialize_verification_key_into_field_elements")
.allowlist_function("acir_serialize_proof_into_field_elements")
.allowlist_function("acir_proofs_new_proof")
.allowlist_function("acir_proofs_verify_proof")
.allowlist_function("pedersen_plookup_compress_fields")
Expand Down
9 changes: 8 additions & 1 deletion cspell.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,13 @@
"consts",
"acir",
"schnorr",
"plookup"
"plookup",
"direnv",
"envrc",
"nixpkgs",
"clippy",
"subshell",
"phated",
"mybranch"
]
}
13 changes: 13 additions & 0 deletions default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
let
lock = builtins.fromJSON (builtins.readFile ./flake.lock);
flakeCompatRev = lock.nodes.flake-compat.locked.rev;
flakeCompatHash = lock.nodes.flake-compat.locked.narHash;
flakeCompat = fetchTarball {
url = "https://github.com/edolstra/flake-compat/archive/${flakeCompatRev}.tar.gz";
sha256 = flakeCompatHash;
};
compat = import flakeCompat {
src = ./.;
};
in
compat.defaultNix
57 changes: 12 additions & 45 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading