coral-xyz / anchor

⚓ Solana Sealevel Framework
https://anchor-lang.com
Apache License 2.0
3.68k stars 1.35k forks source link

Add instructions to readme/contributing on how anchor can be built and tested #964

Open paul-schaaf opened 3 years ago

paul-schaaf commented 3 years ago

see e.g. https://github.com/solana-labs/solana/blob/master/README.md

armaniferrante commented 3 years ago

Three options

1) Individual crates - E.g. lang/ or spl/ can be built and tested like any other rust code 2) CLI - a local version can be built with the cli/ crate. I just use an alias to the built artifact in target/debug/anchor and run it locally, though you can also cargo install with the path. 3) End to end tests - tests/ and examples/ have examples of this. But they do nothing more than use file paths to the crates to use the crates in the local repo. Each folder is a unique Anchor workspace.

dahifi commented 3 years ago

I've been pouring through the tests a lot the past few days, and just this morning started recording what I hope will be a series of vids stepping through them.

The first thing I point out is that the travis.yml file is already a decent how-to install and setup description of all the prereqs. I don't mess around with Travis in my local environment, but I could take that and fix it up in the readme?

dahifi commented 3 years ago

I'm ready to append this to the readme GETTING STARTED section:

In depth installation steps for Linux can be found by following along with the .travis.yml file. Assuming you have NVM and Rust already installed:

rustup update && rustup component add rustfmt clippy
nvm install 17 && nvm use 17
sudo apt-get install -y pkg-config build-essential libudev-dev

npm install -g mocha
npm install -g ts-mocha
npm install -g typescript
npm install -g ts-node
npm install -g buffer
cd ts && yarn && yarn build && npm link && cd ../
npm install -g @project-serum/serum
npm install -g @project-serum/common
npm install -g @solana/spl-token
sh -c "$(curl -sSfL https://release.solana.com/v1.8.0/install)"

You can follow along with the scripts therein to see the Rust build and test commands, as well as the e2e tests. The test directories are a full of useful examples of both Anchor programs and relevant JS bindings, and also show how to include non-anchor dependency programs for localnet testing.


Is that better, or did you have something else in mind @paul-schaaf?

ilyazub commented 2 years ago

sudo apt-get install -y pkg-config build-essential libudev-dev

On Fedora, there's systemd-devel instead of libudev-dev. I can add a PR with Fedora build prerequisites to the installation.md if you're interested.

$ dnf info systemd-devel
Last metadata expiration check: 0:23:52 ago on Tue 23 Nov 2021 06:30:12 PM EET.
Installed Packages
Name         : systemd-devel
Version      : 246.15
Release      : 1.fc33
Architecture : x86_64
Size         : 430 k
Source       : systemd-246.15-1.fc33.src.rpm
Repository   : @System
From repo    : updates
Summary      : Development headers for systemd
URL          : https://www.freedesktop.org/wiki/Software/systemd
License      : LGPLv2+ and MIT
Description  : Development headers and auxiliary files for developing applications linking
             : to libudev or libsystemd.

Anchor failed to compile before installing systemd-devel.

$ cargo install --git https://github.com/project-serum/anchor --tag v0.18.2 anchor-cli --locked
# ...
error: failed to run custom build command for `hidapi v1.2.6`

Caused by:
  process didn't exit successfully: `/tmp/cargo-installvBHDea/release/build/hidapi-445d32b72e0cb0a5/build-script-build` (exit status: 101)
  --- stdout
  cargo:rerun-if-env-changed=LIBUDEV_NO_PKG_CONFIG
  cargo:rerun-if-env-changed=PKG_CONFIG
  cargo:rerun-if-env-changed=LIBUDEV_STATIC
  cargo:rerun-if-env-changed=LIBUDEV_DYNAMIC
  cargo:rerun-if-env-changed=PKG_CONFIG_ALL_STATIC
  cargo:rerun-if-env-changed=PKG_CONFIG_ALL_DYNAMIC
  cargo:rerun-if-env-changed=PKG_CONFIG_PATH_x86_64-unknown-linux-gnu
  cargo:rerun-if-env-changed=PKG_CONFIG_PATH_x86_64_unknown_linux_gnu
  cargo:rerun-if-env-changed=HOST_PKG_CONFIG_PATH
  cargo:rerun-if-env-changed=PKG_CONFIG_PATH
  cargo:rerun-if-env-changed=PKG_CONFIG_LIBDIR_x86_64-unknown-linux-gnu
  cargo:rerun-if-env-changed=PKG_CONFIG_LIBDIR_x86_64_unknown_linux_gnu
  cargo:rerun-if-env-changed=HOST_PKG_CONFIG_LIBDIR
  cargo:rerun-if-env-changed=PKG_CONFIG_LIBDIR
  cargo:rerun-if-env-changed=PKG_CONFIG_SYSROOT_DIR_x86_64-unknown-linux-gnu
  cargo:rerun-if-env-changed=PKG_CONFIG_SYSROOT_DIR_x86_64_unknown_linux_gnu
  cargo:rerun-if-env-changed=HOST_PKG_CONFIG_SYSROOT_DIR
  cargo:rerun-if-env-changed=PKG_CONFIG_SYSROOT_DIR

  --- stderr
  thread 'main' panicked at 'Unable to find libudev: Failure { command: "\"pkg-config\" \"--libs\" \"--cflags\" \"libudev\"", output: Output { status: ExitStatus(ExitStatus(256)), stdout: "", stderr: "Package li
budev was not found in the pkg-config search path.\nPerhaps you should add the directory containing `libudev.pc'\nto the PKG_CONFIG_PATH environment variable\nPackage 'libudev', required by 'virtual:world', not
found\n" } }', /home/ilyazub/.cargo/registry/src/github.com-1ecc6299db9ec823/hidapi-1.2.6/build.rs:53:54
  note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
warning: build failed, waiting for other jobs to finish...
error: failed to compile `anchor-cli v0.18.2 (https://github.com/project-serum/anchor?tag=v0.18.2#1319dc65)`, intermediate artifacts can be found at `/tmp/cargo-installvBHDea`

Caused by:
  build failed

And succeeded after.

$ sudo dnf install systemd-devel
$ cargo install --git https://github.com/project-serum/anchor --tag v0.18.2 anchor-cli --locked
# ...
    Finished release [optimized] target(s) in 7m 59s
  Installing /home/ilyazub/.cargo/bin/anchor
   Installed package `anchor-cli v0.18.2 (https://github.com/project-serum/anchor?tag=v0.18.2#1319dc65)` (executable `anchor`)