TITLE: Installing CKB Rust Target DESCRIPTION: Adds the `riscv64imac-unknown-none-elf` target to your Rust installation using `rustup`. This is the required target for compiling code to run on the CKB-VM. SOURCE: https://github.com/cryptape/ckb-script-templates/blob/main/README.md#_snippet_0 LANGUAGE: Shell CODE: ``` rustup target add riscv64imac-unknown-none-elf ``` ---------------------------------------- TITLE: Installing cargo-generate DESCRIPTION: Installs the `cargo-generate` tool, a cargo subcommand used for generating projects from templates. This tool is essential for creating projects based on the `ckb-script-templates`. SOURCE: https://github.com/cryptape/ckb-script-templates/blob/main/README.md#_snippet_6 LANGUAGE: Shell CODE: ``` cargo install cargo-generate ``` ---------------------------------------- TITLE: Building CKB Contracts with Make - Shell DESCRIPTION: Provides examples of using the `make build` command to compile CKB contracts with different configurations, including debug mode, custom rust flags, additional cargo arguments, building a specific contract, controlling build directory cleanup, and specifying the Clang version for C code. SOURCE: https://github.com/cryptape/ckb-script-templates/blob/main/README.md#_snippet_22 LANGUAGE: Shell CODE: ``` make build make build MODE=debug make build CUSTOM_RUSTFLAGS="" make build CARGO_ARGS="--verbose" make build CONTRACT=second-contract make build CLEAN_BUILD_DIR_FIRST=false make build CLANG=clang-17 ``` ---------------------------------------- TITLE: Running CKB Contract Tests with Make - Shell DESCRIPTION: Demonstrates how to execute the tests defined within the `tests` crate or similar test setups provided by the template using the simple `make test` command. SOURCE: https://github.com/cryptape/ckb-script-templates/blob/main/README.md#_snippet_23 LANGUAGE: Shell CODE: ``` make test ``` ---------------------------------------- TITLE: Generating CKB Workspace with Prompt DESCRIPTION: Uses `cargo-generate` to create a new workspace project from the `ckb-script-templates` repository. This command prompts the user for the project name. SOURCE: https://github.com/cryptape/ckb-script-templates/blob/main/README.md#_snippet_7 LANGUAGE: Shell CODE: ``` cargo generate gh:cryptape/ckb-script-templates workspace ``` ---------------------------------------- TITLE: Generating Standalone Contract Project with Cargo - Shell DESCRIPTION: Illustrates the use of `cargo generate` with the specified GitHub template to create a standalone CKB contract project outside of the default workspace structure. SOURCE: https://github.com/cryptape/ckb-script-templates/blob/main/README.md#_snippet_25 LANGUAGE: Shell CODE: ``` cargo generate gh:cryptape/ckb-script-templates standalone-contract ``` ---------------------------------------- TITLE: Generating CKB Workspace with Name DESCRIPTION: Uses `cargo-generate` to create a new workspace project from the `ckb-script-templates` repository, specifying the project name directly using the `--name` flag to skip the prompt. SOURCE: https://github.com/cryptape/ckb-script-templates/blob/main/README.md#_snippet_8 LANGUAGE: Shell CODE: ``` cargo generate gh:cryptape/ckb-script-templates workspace --name my-first-contract-workspace ``` ---------------------------------------- TITLE: Building and Testing Standalone Contracts with Make - Shell DESCRIPTION: Provides commands to build, test, check, and run clippy for a standalone CKB contract project generated using the `standalone-contract` template. SOURCE: https://github.com/cryptape/ckb-script-templates/blob/main/README.md#_snippet_26 LANGUAGE: Shell CODE: ``` cd standalone-first-contract make build make test make check make clippy ``` ---------------------------------------- TITLE: Generating Contract Crate in Workspace DESCRIPTION: Runs the `make generate` command from the workspace root to create a new contract crate within the `contracts` sub-folder. This command prompts for the contract crate name. SOURCE: https://github.com/cryptape/ckb-script-templates/blob/main/README.md#_snippet_13 LANGUAGE: Shell CODE: ``` make generate ``` ---------------------------------------- TITLE: Generating Named Contract Crate DESCRIPTION: Runs the `make generate` command, specifying the contract crate name using the `CRATE` variable. This avoids the prompt and creates the crate directly in the `contracts` folder. SOURCE: https://github.com/cryptape/ckb-script-templates/blob/main/README.md#_snippet_14 LANGUAGE: Shell CODE: ``` make generate CRATE=second-contract ``` ---------------------------------------- TITLE: Generating Native Simulator with Make - Shell DESCRIPTION: Explains the command to generate a native simulator for a specific contract subproject using `make generate-native-simulator`, highlighting that the `CRATE` parameter is mandatory and must specify an existing subproject name. SOURCE: https://github.com/cryptape/ckb-script-templates/blob/main/README.md#_snippet_27 LANGUAGE: Shell CODE: ``` make generate-native-simulator CRATE= ``` ---------------------------------------- TITLE: Example: Generating Native Simulator for a Specific Crate - Shell DESCRIPTION: Provides a concrete example of using the `make generate-native-simulator` command to build the native simulator specifically for the `example_crate` subproject. SOURCE: https://github.com/cryptape/ckb-script-templates/blob/main/README.md#_snippet_28 LANGUAGE: Shell CODE: ``` make generate-native-simulator CRATE=example_crate ``` ---------------------------------------- TITLE: Navigating into Workspace Directory DESCRIPTION: Changes the current directory to the newly created CKB workspace directory. This is necessary before generating contract crates within the workspace. SOURCE: https://github.com/cryptape/ckb-script-templates/blob/main/README.md#_snippet_11 LANGUAGE: Shell CODE: ``` cd my-first-contract-workspace ``` ---------------------------------------- TITLE: Listing Workspace Directory Structure DESCRIPTION: Uses the `tree` command to display the directory structure of the newly generated CKB workspace, showing the initial files and folders like `Cargo.toml`, `Makefile`, `scripts`, and `tests`. SOURCE: https://github.com/cryptape/ckb-script-templates/blob/main/README.md#_snippet_12 LANGUAGE: Shell CODE: ``` tree . ``` ---------------------------------------- TITLE: Generating Crate with Custom Template/Dest DESCRIPTION: Executes the `make generate` command, specifying both a different template (`c-wrapper-crate`) using `TEMPLATE` and a different destination directory (`crates`) using `DESTINATION`. This allows generating non-contract crates or contracts in custom locations. SOURCE: https://github.com/cryptape/ckb-script-templates/blob/main/README.md#_snippet_17 LANGUAGE: Shell CODE: ``` make generate TEMPLATE=c-wrapper-crate DESTINATION=crates ``` ---------------------------------------- TITLE: Generating Contract with Custom Template DESCRIPTION: Executes the `make generate` command, specifying a different template (e.g., `atomics-contract`) using the `TEMPLATE` variable instead of the default `contract` template. The crate is still created in the `contracts` subfolder. SOURCE: https://github.com/cryptape/ckb-script-templates/blob/main/README.md#_snippet_15 LANGUAGE: Shell CODE: ``` make generate TEMPLATE=atomics-contract ``` ---------------------------------------- TITLE: Generating Crate in Custom Directory DESCRIPTION: Runs the `make generate` command, specifying a different destination directory (e.g., `crates`) using the `DESTINATION` variable. By default, this will use the `contract` template. SOURCE: https://github.com/cryptape/ckb-script-templates/blob/main/README.md#_snippet_16 LANGUAGE: Shell CODE: ``` make DESTINATION=crates ``` ---------------------------------------- TITLE: Performing Reproducible Build with Docker Script - Shell DESCRIPTION: Shows how to use the `./scripts/reproducible_build_docker` script to perform reproducible builds leveraging a Docker container with locked compiler versions, including options to update checksums, skip cleaning intermediate files, and configure proxy settings for crate downloads. SOURCE: https://github.com/cryptape/ckb-script-templates/blob/main/README.md#_snippet_24 LANGUAGE: Shell CODE: ``` ./scripts/reproducible_build_docker ./scripts/reproducible_build_docker --update ./scripts/reproducible_build_docker --no-clean ./scripts/reproducible_build_docker --proxy "..." ``` ---------------------------------------- TITLE: Installing Clang 18+ on Debian/Ubuntu DESCRIPTION: Downloads and executes a script to install Clang version 18 or newer on Debian or Ubuntu systems. This is one of the required dependencies for building CKB contracts. SOURCE: https://github.com/cryptape/ckb-script-templates/blob/main/README.md#_snippet_1 LANGUAGE: Shell CODE: ``` wget https://apt.llvm.org/llvm.sh && chmod +x llvm.sh && sudo ./llvm.sh 18 && rm llvm.sh ``` ---------------------------------------- TITLE: Installing Clang on Fedora DESCRIPTION: Installs the Clang compiler using the `dnf` package manager on Fedora 39+ systems. Clang is required for compiling parts of the CKB contracts or dependencies. SOURCE: https://github.com/cryptape/ckb-script-templates/blob/main/README.md#_snippet_2 LANGUAGE: Shell CODE: ``` sudo dnf -y install clang ``` ---------------------------------------- TITLE: Installing Clang on Archlinux DESCRIPTION: Installs the Clang compiler using the `pacman` package manager on Archlinux. Clang is a necessary dependency for building CKB contracts. SOURCE: https://github.com/cryptape/ckb-script-templates/blob/main/README.md#_snippet_3 LANGUAGE: Shell CODE: ``` sudo pacman --noconfirm -Syu clang ``` ---------------------------------------- TITLE: Installing Clang/Yasm on Windows (Scoop) DESCRIPTION: Installs the Clang compiler and Yasm assembler using the Scoop package manager on Windows. These are required dependencies for building CKB contracts on Windows. SOURCE: https://github.com/cryptape/ckb-script-templates/blob/main/README.md#_snippet_5 LANGUAGE: Shell CODE: ``` scoop install llvm yasm ``` ---------------------------------------- TITLE: Installing Clang on macOS DESCRIPTION: Installs the Clang compiler version 18 using the Homebrew package manager on macOS. Clang is required for building CKB contracts. SOURCE: https://github.com/cryptape/ckb-script-templates/blob/main/README.md#_snippet_4 LANGUAGE: Shell CODE: ``` brew install llvm@18 ``` ---------------------------------------- TITLE: Updating CKB Rust Flags in Makefile DESCRIPTION: Shows an example line for modifying the `FULL_RUSTFLAGS` variable in a Makefile. This configuration ensures the correct RISC-V target features are enabled while disabling the atomic extension (`-a`) which might not be supported by CKB-VM, especially relevant when using crates like `bytes` with `dummy-atomic`. SOURCE: https://github.com/cryptape/ckb-script-templates/blob/main/README.md#_snippet_18 LANGUAGE: Makefile CODE: ``` FULL_RUSTFLAGS := -C target-feature=+zba,+zbb,+zbc,+zbs,-a $(CUSTOM_RUSTFLAGS) ``` ---------------------------------------- TITLE: Adding ckb-c-stdlib Git Submodule DESCRIPTION: Adds the `ckb-c-stdlib` library as a Git submodule in the `deps` directory. This library is required for C code used in CKB contracts, particularly for templates like `c-wrapper-crate`. SOURCE: https://github.com/cryptape/ckb-script-templates/blob/main/README.md#_snippet_19 LANGUAGE: Shell CODE: ``` git submodule add https://github.com/nervosnetwork/ckb-c-stdlib deps/ckb-c-stdlib ``` ---------------------------------------- TITLE: Creating Shell Alias for Workspace Gen DESCRIPTION: Defines a shell alias `create-ckb-scripts` to shorten the command for generating a CKB workspace using `cargo-generate`. This simplifies repeated use. SOURCE: https://github.com/cryptape/ckb-script-templates/blob/main/README.md#_snippet_9 LANGUAGE: Shell CODE: ``` alias create-ckb-scripts="cargo generate gh:cryptape/ckb-script-templates workspace" ``` ---------------------------------------- TITLE: Using Alias for Workspace Generation DESCRIPTION: Executes the previously defined shell alias `create-ckb-scripts` to generate a CKB workspace, demonstrating how the alias simplifies the command. SOURCE: https://github.com/cryptape/ckb-script-templates/blob/main/README.md#_snippet_10 LANGUAGE: Shell CODE: ``` create-ckb-scripts ``` ---------------------------------------- TITLE: Adding lib-dummy-atomics Git Submodule DESCRIPTION: Adds the `lib-dummy-atomics` library as a Git submodule in the `deps` directory. This specific library might be required by certain templates, like `atomics-contract`, to provide dummy atomic operations. SOURCE: https://github.com/cryptape/ckb-script-templates/blob/main/README.md#_snippet_20 LANGUAGE: Shell CODE: ``` git submodule add https://github.com/xxuejie/lib-dummy-atomics deps/lib-dummy-atomics ``` ---------------------------------------- TITLE: Adding ckb-stack-reorg-bootloader Git Submodule DESCRIPTION: Adds the `ckb-stack-reorg-bootloader` library as a Git submodule in the `deps` directory. This is a dependency for the `stack-reorder-contract` template. SOURCE: https://github.com/cryptape/ckb-script-templates/blob/main/README.md#_snippet_21 LANGUAGE: Shell CODE: ``` git submodule add https://github.com/xxuejie/ckb-stack-reorg-bootloader deps/ckb-stack-reorg-bootloader ```