### CircleCI Workflow for Scarb Setup Source: https://github.com/software-mansion/scarb/blob/main/website/docs/guides/using-scarb-in-ci.md Example CircleCI configuration to set up Scarb. It downloads the installer script and adds Scarb to the PATH for subsequent commands. ```yaml version: 2.1 parameters: scarb_version: type: string default: "{{ rel.sampleVersion }}" jobs: check: docker: - image: cimg/base:2023.03 steps: - checkout - run: name: Setup Scarb command: | echo 'export PATH="$HOME/.local/bin:$PATH"' >> "$BASH_ENV" source "$BASH_ENV" curl --proto '=https' --tlsv1.2 -sSf https://docs.swmansion.com/scarb/install.sh | bash -s -- -v << pipeline.parameters.scarb_version >> - run: scarb fmt --check - run: scarb lint - run: scarb build workflows: ci: jobs: - check ``` -------------------------------- ### GitHub Actions CI Workflow Source: https://github.com/software-mansion/scarb/blob/main/website/docs/guides/using-scarb-in-ci.md Example GitHub Actions workflow to set up Scarb and run checks. Uses the `software-mansion/setup-scarb` action for installation and caching. ```yaml name: CI on: push: branches: [main] merge_group: pull_request: jobs: check: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - uses: software-mansion/setup-scarb@v1 with: scarb-version: "{{ rel.sampleVersion }}" - run: scarb fmt --check - run: scarb lint - run: scarb test ``` -------------------------------- ### GitLab CI Configuration for Scarb Source: https://github.com/software-mansion/scarb/blob/main/website/docs/guides/using-scarb-in-ci.md Example GitLab CI configuration to install and use Scarb. It downloads the Scarb installer script and sets up the environment. ```yaml variables: SCARB_VERSION: "{{ rel.sampleVersion }}" stages: - check scarb: stage: check image: ubuntu:jammy script: - apt-get update && apt-get install -y curl - export PATH="$HOME/.local/bin:$PATH" && curl --proto '=https' --tlsv1.2 -sSf https://docs.swmansion.com/scarb/install.sh | bash -s -- -v $SCARB_VERSION - scarb fmt --check - scarb lint - scarb build ``` -------------------------------- ### Tool Configuration Example Source: https://github.com/software-mansion/scarb/blob/main/website/docs/reference/manifest.md An example of how to configure tool-specific settings within the [tool] section of Scarb.toml. Scarb ignores these keys, preventing warnings about unused configurations. ```toml [tool.snforge] exit-first = true ``` -------------------------------- ### Build the hello_world project with Scarb Source: https://github.com/software-mansion/scarb/blob/main/examples/hello_world/README.md Use this command to compile the project. Ensure Scarb is installed and configured in your environment. ```shell scarb build ``` -------------------------------- ### Install Scarb via Starkup Script Source: https://github.com/software-mansion/scarb/blob/main/website/download.md Use this command to install Scarb and other essential Cairo development tools on macOS and Linux using the starkup script. Follow the on-screen instructions. ```shell curl --proto '=https' --tlsv1.2 -sSf https://sh.starkup.dev | sh ``` -------------------------------- ### Windows Manual Installation - Add to PATH Source: https://github.com/software-mansion/scarb/blob/main/website/download.md Add the 'scarb\bin' directory to your system's PATH environment variable for Scarb to be accessible from any terminal. ```shell %LOCALAPPDATA%\Programs\scarb\bin ``` -------------------------------- ### Example: Building External Contracts Source: https://github.com/software-mansion/scarb/blob/main/website/docs/extensions/starknet/contract-target.md An example of how to configure Scarb.toml to build an external contract (`AccountUpgradeable` from the `openzeppelin` package) along with your project's contracts. ```toml [dependencies] starknet = "{{ rel.stable.starknetPackageVersionReq }}" openzeppelin = "0.19.0" [[target.starknet-contract]] build-external-contracts = ["openzeppelin_presets::account::AccountUpgradeable"] ``` -------------------------------- ### Install Specific Scarb Version via Script Source: https://github.com/software-mansion/scarb/blob/main/website/download.md Install a specific version of Scarb, such as a preview or nightly release, using the official installation script. Replace `{{ rel.sampleVersion }}` with the desired version. ```shell-vue curl --proto '=https' --tlsv1.2 -sSf https://docs.swmansion.com/scarb/install.sh | sh -s -- -v {{ rel.sampleVersion }} ``` -------------------------------- ### Install Scarb in NixOS Source: https://github.com/software-mansion/scarb/blob/main/website/download.md Use the community-maintained Cairo Nix overlay to install Scarb and a Cairo development environment. ```nix nix shell github:cairo-nix/cairo-nix ``` -------------------------------- ### Call foo_bar Function Source: https://github.com/software-mansion/scarb/blob/main/extensions/scarb-doc/tests/data/runnable_examples_mdx/src/hello_world-foo_bar.mdx This example demonstrates how to invoke the foo_bar function. Ensure the function is available in your scope. ```cairo foo_bar(); ``` -------------------------------- ### Example Scarb.lock File Content Source: https://github.com/software-mansion/scarb/blob/main/website/docs/reference/lockfile.md This TOML snippet illustrates the structure of a Scarb.lock file. It includes package metadata such as name, version, source, and a list of dependencies for each package in the dependency tree. The file starts with a header indicating it's auto-generated and its version. ```toml # Code generated by scarb DO NOT EDIT. version = 1 [[package]] name = "alexandria_data_structures" version = "0.1.0" source = "git+https://github.com/keep-starknet-strange/alexandria.git#3356bf0c5c1a089167d7d3c28d543e195325e596" [[package]] name = "alexandria_math" version = "0.2.0" source = "git+https://github.com/keep-starknet-strange/alexandria.git#3356bf0c5c1a089167d7d3c28d543e195325e596" dependencies = [ "alexandria_data_structures", ] [[package]] name = "hello_world" version = "0.1.0" dependencies = [ "alexandria_data_structures", "alexandria_math", ] ``` -------------------------------- ### SemVer Version Requirement Examples Source: https://github.com/software-mansion/scarb/blob/main/website/docs/reference/specifying-dependencies.md Illustrates various SemVer-compatible version requirements and the corresponding allowed version ranges. Note the special handling for versions before 1.0.0. ```text 1.2.3 := >=1.2.3, <2.0.0 1.2 := >=1.2.0, <2.0.0 1 := >=1.0.0, <2.0.0 0.2.3 := >=0.2.3, <0.3.0 0.2 := >=0.2.0, <0.3.0 0.0.3 := >=0.0.3, <0.0.4 0.0 := >=0.0.0, <0.1.0 0 := >=0.0.0, <1.0.0 ``` -------------------------------- ### Example Cairo Project Code Source: https://github.com/software-mansion/scarb/blob/main/website/docs/extensions/documentation-generation.md This is an example Cairo code snippet demonstrating documentation comments for enums, structs, and functions. It includes inline and outer documentation comments, as well as examples of how to invoke functions. ```cairo //! This module is an example one. //! It tries to show how documentation comments work. /// Example Enum. It's really similar to [ExampleStruct] pub enum ExampleEnum { /// First enum variant. VARIANT_A, /// Second enum variant. VARIANT_B } /// Example struct. Contains a public field and a private one. pub struct ExampleStruct { /// Private field. field_a: felt252, /// Public field. pub field_b: felt252, /// [`ExampleEnum`] field field_c: ExampleEnum } /// Function that prints "test" to stdout with endline. /// Can invoke it like that: /// ```cairo /// fn main() { /// test(); /// } /// ``` pub fn test() { println!("test"); } /// Main function that Cairo runs as a binary entrypoint. /// This function uses [test] function. pub fn main() { //! This is an inner comment. It refers to it's parent which is the main function. println!("hello_world"); test(); } ``` -------------------------------- ### Example Output of Script with Variables Source: https://github.com/software-mansion/scarb/blob/main/website/docs/reference/scripts.md Shows the output when running the 'foo' script defined with environment and shell variables. Only the exported 'HELLO' variable and the 'USER' environment variable are displayed. ```shell $ scarb run foo Hello SWMANSION! ``` -------------------------------- ### Install Latest Scarb Version with asdf Source: https://github.com/software-mansion/scarb/blob/main/website/download.md Install the latest stable release of Scarb using the asdf version manager. Ensure asdf is installed and configured correctly. ```shell asdf install scarb latest ``` -------------------------------- ### Install WASM Target Source: https://github.com/software-mansion/scarb/blob/main/website/docs/extensions/oracles/wasm.md Command to install the `wasm32-wasip2` Rust cross-compiler. ```shell rustup target add wasm32-wasip2 ``` -------------------------------- ### Install Latest Stable Scarb via Script Source: https://github.com/software-mansion/scarb/blob/main/website/download.md Install the latest stable release of Scarb directly using the official installation script. This method is for macOS and Linux. ```shell curl --proto '=https' --tlsv1.2 -sSf https://docs.swmansion.com/scarb/install.sh | sh ``` -------------------------------- ### Dependency Normalization Example Source: https://github.com/software-mansion/scarb/blob/main/website/docs/registries/package-tarball.md Illustrates how dependency specifications in Scarb.toml are normalized for registry use, stripping non-registry source properties like local paths. ```toml [dependencies] foobar = { version = "1.2.3", path = "../foobar" } ``` ```toml [dependencies.foobar] version = "1.2.3" ``` -------------------------------- ### List Available Scarb Versions with asdf Source: https://github.com/software-mansion/scarb/blob/main/website/download.md View all installable Scarb versions using the asdf CLI tool. This command helps in selecting a specific version for installation. ```shell asdf list all scarb ``` -------------------------------- ### Example JSON Output for Compilation Source: https://github.com/software-mansion/scarb/blob/main/website/docs/writing-extensions/json-output.md This example demonstrates the newline-delimited JSON output generated by Scarb during a build process, including compilation status, diagnostic errors, and final error messages. ```shell $ scarb --json build {"status":"compiling","message":"hello v0.1.0 ([..]Scarb.toml)"} {"type":"diagnostic","message":"error: Skipped tokens. Expected: Module/Use/FreeFunction/ExternFunction/ExternType/Trait/Impl/Struct/Enum or an attribute.\n --> lib.cairo:1:1\nnot_a_keyword ^***********^\n\n","code":"E1000"} {"type":"error","message":"could not compile `hello` due to previous error"} ``` -------------------------------- ### Add Package Keywords Source: https://github.com/software-mansion/scarb/blob/main/website/docs/reference/manifest.md An array of strings that describe your package, aiding in registry searches. Keywords should be ASCII text, start with a letter, and be at most 20 characters long. ```toml [package] keywords = ["account", "wallet", "erc-20"] ``` -------------------------------- ### Verify Scarb Installation Source: https://github.com/software-mansion/scarb/blob/main/website/download.md Run this command in a new terminal session to confirm that Scarb and the Cairo language versions are correctly displayed. ```shell scarb --version ``` -------------------------------- ### Install Latest Nightly Scarb via Script Source: https://github.com/software-mansion/scarb/blob/main/website/download.md Install the latest nightly build of Scarb using the official installation script. This command is suitable for macOS and Linux users who need cutting-edge features. ```shell curl --proto '=https' --tlsv1.2 -sSf https://docs.swmansion.com/scarb/install.sh | sh -s -- -v nightly ``` -------------------------------- ### Example VCS.json Structure Source: https://github.com/software-mansion/scarb/blob/main/website/docs/registries/package-tarball.md This JSON structure provides information about the version control system used for a package, specifically Git commit hash and path within the VCS. ```json { "git": { "sha1": "a928d5ba03fc09d3316b39f04f30ee135df0c606" }, "path_in_vcs": "" } ``` -------------------------------- ### Invoke foo_bar Function Source: https://github.com/software-mansion/scarb/blob/main/extensions/scarb-doc/tests/data/runnable_examples/src/hello_world-foo_bar.md Example of how to invoke the foo_bar function. Ensure the foo and bar functions are accessible in the current scope. ```cairo foo_bar(); ``` -------------------------------- ### Writing Runnable Doc Tests in Cairo Source: https://github.com/software-mansion/scarb/blob/main/website/docs/extensions/documentation-generation.md Embed runnable code examples within documentation comments using the `cairo,runnable` attributes on the code fence. These examples are compiled and executed by `scarb doc` to ensure accuracy. ```cairo /// Adds two numbers together. /// ```cairo,runnable /// let result = add(2, 3); /// assert(result == 5, 'should be 5'); /// ``` pub fn add(a: u32, b: u32) -> u32 { a + b } ``` -------------------------------- ### Configure Scarb Formatter Source: https://github.com/software-mansion/scarb/blob/main/website/docs/guides/formatting.md Customize formatter behavior by adding a `[tool.fmt]` section to your `Scarb.toml` file. This example enables sorting of module-level items. ```toml [tool.fmt] sort-module-level-items = true ``` -------------------------------- ### Invoke bar Function Source: https://github.com/software-mansion/scarb/blob/main/extensions/scarb-doc/tests/data/runnable_examples/src/hello_world-bar.md Example of how to call the bar function. Ensure the function is accessible in your scope. ```cairo bar(); ``` -------------------------------- ### Example of Macro Expansion Source: https://github.com/software-mansion/scarb/blob/main/website/docs/procedural-macros/writing.md Illustrates how an attribute macro prepends a constant declaration before the annotated item. The original Cairo code is shown alongside its expanded form after the macro is applied. ```cairo #[my_macro] fn example() -> u32 { MY_CONST } ``` ```cairo const MY_CONST: u32 = 42; fn example() -> u32 { MY_CONST } ``` -------------------------------- ### Example of Remote Linking URL Structure Source: https://github.com/software-mansion/scarb/blob/main/website/docs/extensions/documentation-generation.md This illustrates the expected format of a 'View source' link generated by Scarb when a `--remote-base-url` is configured, including the file path and line range anchor. ```text https://github.com/ExampleRepoOwner/ExampleRepoProject/blob/example_branch/hello_world/src/lib.cairo#L10-L15 ``` -------------------------------- ### Run benchmarks with hyperfine Source: https://github.com/software-mansion/scarb/blob/main/guidelines/BENCHMARKING.md Use hyperfine to run benchmarks multiple times for reliable results. Configure warmup runs and the number of actual runs. This example benchmarks 'scarb build -w'. ```sh hyperfine --warmup 1 --runs 10 -- 'scarb build -w' ``` -------------------------------- ### Example of Panicking Implementation Source: https://github.com/software-mansion/scarb/blob/main/website/docs/procedural-macros/diagnostics.md This code snippet shows a previous, less informative implementation of the `fib` macro that would panic on invalid input, contrasting with the diagnostic approach. ```text thread '' (51728626) panicked at src/lib.rs:43:44: called `Result::unwrap()` on an `Err` value: ParseIntError { kind: InvalidDigit } note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace thread '' (51728626) panicked at library/core/src/panicking.rs:225:5: panic in a function that cannot unwind ``` -------------------------------- ### Define a Custom Profile in Scarb.toml Source: https://github.com/software-mansion/scarb/blob/main/website/docs/guides/defining-custom-profiles.md Define a new custom profile with a unique name in `Scarb.toml`. This example creates a 'custom-profile' and sets a specific Cairo compiler option. ```toml [profile.custom-profile.cairo] sierra-replace-ids = false ``` -------------------------------- ### Cairo Lint Example Output Source: https://github.com/software-mansion/scarb/blob/main/website/docs/extensions/linter.md Observe a typical warning message generated by `scarb lint`, indicating an unnecessary comparison with a boolean value and suggesting a more direct approach. ```sh $ scarb lint Linting hello_world v0.1.0 (/hello_world/Scarb.toml) warning: Plugin diagnostic: Unnecessary comparison with a boolean value. Use the variable directly. --> /hello_world/src/lib.cairo:2:8 | 2 | | if is_true() == true { | ----------------- | ``` -------------------------------- ### Using Procedural Macros in Cairo Code Source: https://github.com/software-mansion/scarb/blob/main/design/01-proc-macro.md Utilize procedural macros in Cairo by importing them and applying them as derive, attribute, or macro calls. This example shows derive and attribute macros. ```cairo use add_macro::add; use tracing_macro::instrument; use to_value_macro::ToValue; #[derive(ToValue)] struct Input { value: felt252, } #[instrument] fn main() -> felt252 { let a = Input { value: 1 }; let b = Input { value: 2 }; add!(a.to_value(), b.to_value()); } ``` -------------------------------- ### Create a Starknet Foundry Project Source: https://github.com/software-mansion/scarb/blob/main/website/docs/guides/creating-a-new-package.md Initialize a new Scarb package with Starknet Foundry as the test runner using the `--test-runner=starknet-foundry` flag. ```shell scarb new hello_world --test-runner=starknet-foundry ``` -------------------------------- ### Test the hello_world project with Scarb Source: https://github.com/software-mansion/scarb/blob/main/examples/hello_world/README.md Use this command to run the project's tests. This is useful for verifying the project's functionality and correctness. ```shell scarb test ``` -------------------------------- ### Use Custom Profile Source: https://github.com/software-mansion/scarb/blob/main/website/docs/reference/profiles.md Build a project using a custom profile named 'my-profile' via the command line. ```shell scarb --profile my-profile build ``` -------------------------------- ### Example Dependency Specification Source: https://github.com/software-mansion/scarb/blob/main/website/docs/reference/lockfile.md This TOML snippet shows how to specify a dependency using a Git repository and a specific branch. Without a lockfile, Scarb would always pull the latest commit from this branch, potentially leading to unreproducible builds. ```toml alexandria_math = { git = "https://github.com/keep-starknet-strange/alexandria.git", branch = "next" } ``` -------------------------------- ### Using the Create Wrapper Macro in Cairo Source: https://github.com/software-mansion/scarb/blob/main/website/docs/procedural-macros/examples.md This example demonstrates how to apply the `create_wrapper` attribute macro to a Cairo function. The macro generates a new function (`named_wrapper`) that calls the original `fib` function with a specified argument (16). ```cairo // hello_world/src/lib.cairo fn main() -> u32 { named_wrapper() } #[create_wrapper(named_wrapper,16)] fn fib(mut n: u32) -> u32 { let mut a: u32 = 0; let mut b: u32 = 1; while n != 0 { n = n - 1; let temp = b; b = a + b; a = temp; } a } #[cfg(test)] mod tests { use super::main; #[test] fn it_works() { assert(main() == 987, 'invalid value returned!'); } } ``` -------------------------------- ### Full Cairo Snippet with Entry Point Source: https://github.com/software-mansion/scarb/blob/main/website/docs/extensions/documentation-generation.md Use this format when your code block contains top-level items like `fn main()`. You must define the entry point yourself. The documented package is imported with `use package_name::*;`. ```cairo /// ```cairo,runnable /// #[executable] /// fn main() -> i32 { /// add(-1, 1) /// } /// ``` pub fn add(a: i32, b: i32) -> i32 { a + b } ``` -------------------------------- ### Invalid Macro Usage Examples Source: https://github.com/software-mansion/scarb/blob/main/website/docs/procedural-macros/diagnostics.md These examples demonstrate how to invoke the `fib` macro with invalid arguments to trigger the custom error diagnostics. ```cairo fn main() -> u32 { fib!(12,16); fib!("abcd"); fib!(16) } ``` -------------------------------- ### Link to Package Documentation Source: https://github.com/software-mansion/scarb/blob/main/website/docs/reference/manifest.md Specifies a URL to a website hosting the crate's documentation. ```toml [package] documentation = "https://john.github.io/cairo-package" ``` -------------------------------- ### Install Specific Scarb Version with asdf Source: https://github.com/software-mansion/scarb/blob/main/website/download.md Install a specific version of Scarb using the asdf version manager. Replace `{{ rel.sampleVersion }}` with the desired version number. ```shell-vue asdf install scarb {{ rel.sampleVersion }} ``` -------------------------------- ### Scarb CLI and Commands Overview Source: https://github.com/software-mansion/scarb/blob/main/guidelines/ARCHITECTURE.md Diagram illustrating the Scarb CLI entrypoint and its interaction with built-in commands and external subcommands like Cairo Language Server, scarb run, scarb doc, and scarb test. ```mermaid flowchart TD scarb([scarb CLI]) scarb---BUILTIN_CMDS scarb---EXT_CMDS subgraph BUILTIN_CMDS ["Built-in commands"] direction LR BLD[scarb build] CHK[scarb check] UPD[scarb update] FTH[scarb fetch] FMT[scarb fmt] CLN[scarb clean] CAC[scarb cache] NEW[scarb init/new] UPD[scarb add/rm/update] PUB[scarb package/publish] MET[scarb metadata] CMD[scarb commands] MAN[scarb manifest-path] end subgraph EXT_CMDS ["External subcommands system"] direction LR CAIRO_LS["Cairo Language Server"] CAIRO_RUN["scarb run"] SCARB_DOC["scarb doc"] SNFORGE["scarb test\n(can redirect to either snforge,\ncairo-test or other runner)"] end ``` -------------------------------- ### Initialize Theme and Sidebar Settings Source: https://github.com/software-mansion/scarb/blob/main/extensions/scarb-mdbook/tests/data/hello_world/output/404.html This script attempts to retrieve and normalize theme and sidebar settings from local storage. It handles potential errors during access and applies default themes based on system preferences. ```javascript try { let theme = localStorage.getItem('mdbook-theme'); let sidebar = localStorage.getItem('mdbook-sidebar'); if (theme.startsWith('"') && theme.endsWith('"')) { localStorage.setItem('mdbook-theme', theme.slice(1, theme.length - 1)); } if (sidebar.startsWith('"') && sidebar.endsWith('"')) { localStorage.setItem('mdbook-sidebar', sidebar.slice(1, sidebar.length - 1)); } } catch (e) { } ``` ```javascript const default_theme = window.matchMedia("(prefers-color-scheme: dark)").matches ? default_dark_theme : default_light_theme; let theme; try { theme = localStorage.getItem('mdbook-theme'); } catch(e) { } if (theme === null || theme === undefined) { theme = default_theme; } const html = document.documentElement; html.classList.remove('light') html.classList.add(theme); html.classList.add("js"); ``` ```javascript let sidebar = null; const sidebar_toggle = document.getElementById("mdbook-sidebar-toggle-anchor"); if (document.body.clientWidth >= 1080) { try { sidebar = localStorage.getItem('mdbook-sidebar'); } catch(e) { } sidebar = sidebar || 'visible'; } else { sidebar = 'hidden'; sidebar_toggle.checked = false; } if (sidebar === 'visible') { sidebar_toggle.checked = true; } else { html.classList.remove('sidebar-visible'); } ``` -------------------------------- ### Building with Specific Profiles Source: https://context7.com/software-mansion/scarb/llms.txt Use the 'scarb build' command with the --profile flag to compile using custom configurations. ```shell scarb build --profile release scarb build --profile audit ``` -------------------------------- ### works Source: https://github.com/software-mansion/scarb/blob/main/extensions/scarb-doc/tests/data/expose_macros/src/hello_world-regina-VisibleStruct.md The 'works' field within VisibleStruct, used for documentation examples. ```APIDOC ## Member works for members as well Fully qualified path: [hello_world](./hello_world.md)::[regina](./hello_world-regina.md)::[VisibleStruct](./hello_world-regina-VisibleStruct.md)::[works](./hello_world-regina-VisibleStruct.md#works) ```cairo pub works: felt252 ``` ``` -------------------------------- ### Main Function Signature Source: https://github.com/software-mansion/scarb/blob/main/extensions/scarb-doc/tests/data/duplicated_item_names/src/hello_world-main.md This is the entry point for the Cairo program. It is declared using the 'fn' keyword. ```cairo fn main() ``` -------------------------------- ### hello_world::foo Source: https://github.com/software-mansion/scarb/blob/main/extensions/scarb-doc/tests/data/runnable_examples_mdx/src/hello_world-foo.mdx Function that prints "foo" to stdout with endline. ```APIDOC ## hello_world::foo ### Description Function that prints "foo" to stdout with endline. ### Signature ```rust pub fn foo() ``` ### Usage Example ```runnable foo(); ``` ``` -------------------------------- ### Display Help for Scarb Build Command Source: https://github.com/software-mansion/scarb/blob/main/website/docs.md This command provides detailed help specifically for the 'scarb build' command. ```shell scarb build --help ``` -------------------------------- ### main Function Source: https://github.com/software-mansion/scarb/blob/main/extensions/scarb-mdbook/tests/data/hello_world/input/src/hello_world-main.md The `main` function is the entry point of the program. It returns a `u32` value. ```APIDOC ## main Function ### Description The `main` function serves as the entry point for the program execution. It is defined within the `hello_world` module and returns an unsigned 32-bit integer. ### Signature ```rust fn main() -> u32 ``` ``` -------------------------------- ### Initialize theme and sidebar settings Source: https://github.com/software-mansion/scarb/blob/main/extensions/scarb-mdbook/tests/data/hello_world/output/free_functions.html This JavaScript code initializes theme and sidebar settings based on local storage and user preferences. It handles potential errors during local storage access and applies the appropriate theme and sidebar visibility. ```javascript const path_to_root = ""; const default_light_theme = "light"; const default_dark_theme = "navy"; // Keyboard shortcuts // ------------------ // Press ← or → to navigate between chapters // Press ? to show this help // Press Esc to hide this help try { let theme = localStorage.getItem('mdbook-theme'); let sidebar = localStorage.getItem('mdbook-sidebar'); if (theme.startsWith('"') && theme.endsWith('"')) { localStorage.setItem('mdbook-theme', theme.slice(1, theme.length - 1)); } if (sidebar.startsWith('"') && sidebar.endsWith('"')) { localStorage.setItem('mdbook-sidebar', sidebar.slice(1, sidebar.length - 1)); } } catch (e) { } const default_theme = window.matchMedia("(prefers-color-scheme: dark)").matches ? default_dark_theme : default_light_theme; let theme; try { theme = localStorage.getItem('mdbook-theme'); } catch(e) { } if (theme === null || theme === undefined) { theme = default_theme; } const html = document.documentElement; html.classList.remove('light') html.classList.add(theme); html.classList.add("js"); let sidebar = null; const sidebar_toggle = document.getElementById("mdbook-sidebar-toggle-anchor"); if (document.body.clientWidth >= 1080) { try { sidebar = localStorage.getItem('mdbook-sidebar'); } catch(e) { } sidebar = sidebar || 'visible'; } else { sidebar = 'hidden'; sidebar_toggle.checked = false; } if (sidebar === 'visible') { sidebar_toggle.checked = true; } else { html.classList.remove('sidebar-visible'); } ``` -------------------------------- ### Display Help for a Specific Scarb Command Source: https://github.com/software-mansion/scarb/blob/main/website/docs.md To get detailed information about a specific command and its flags, append --help to the command. ```shell scarb COMMAND --help ``` -------------------------------- ### Add Scarb Plugin for asdf Source: https://github.com/software-mansion/scarb/blob/main/website/download.md Add the official Scarb plugin to asdf to manage multiple Scarb installations. This command is for macOS and Linux. ```shell asdf plugin add scarb ``` -------------------------------- ### Display Detailed Scarb Help Source: https://github.com/software-mansion/scarb/blob/main/website/docs.md Use this command for more comprehensive information about Scarb's functionalities and options. ```shell scarb --help ``` -------------------------------- ### Cairo Glue Code for WASM Oracle Source: https://github.com/software-mansion/scarb/blob/main/website/docs/extensions/oracles/wasm.md Example of Cairo glue code to invoke a WASM oracle function, resolving the component from assets. ```cairo pub fn add(left: u64, right: u64) -> oracle::Result { oracle::invoke( "wasm:mypkg_oracle.wasm", // Resolved from assets. [!code highlight] "add", (left, right) ) } ``` -------------------------------- ### Configure Starknet contract compilation Source: https://github.com/software-mansion/scarb/blob/main/website/docs/cheatsheet.md To build Starknet contracts, add the `starknet` dependency to your `Scarb.toml` and include a `[[target.starknet-contract]]` section. ```toml [dependencies] starknet = "{{ rel.stable.starknetPackageVersionReq }}" [[target.starknet-contract]] ``` -------------------------------- ### Define 'one' function in Cairo Source: https://github.com/software-mansion/scarb/blob/main/extensions/scarb-doc/tests/data/hello_world_doc_groups/src/hello_world-A-one.md This snippet defines the 'one' function in Cairo. It is part of a larger example and serves as a basic building block. ```cairo fn one() ``` -------------------------------- ### Call add function and print result Source: https://github.com/software-mansion/scarb/blob/main/extensions/scarb-doc/tests/data/runnable_examples_multiple_per_item/src/hello_world-add.md Demonstrates calling the 'add' function with positive integers and printing the output. Ensure the 'add' function is accessible in your scope. ```cairo let x = add(2, 3); println("{}", x); ``` -------------------------------- ### Cairo Macro Usage with `fib!` Source: https://github.com/software-mansion/scarb/blob/main/website/docs/procedural-macros/examples.md This example shows how to call a Cairo macro that generates a constant value. The macro is invoked at the top level of the module. ```cairo fib!(16); fn main() -> u32 { FIB16 } ``` -------------------------------- ### Executable main function with add Source: https://github.com/software-mansion/scarb/blob/main/extensions/scarb-doc/tests/data/runnable_examples_multiple_per_item/src/hello_world-add.md Shows how to use the 'add' function within an executable 'main' function, including a case with negative input. This snippet requires the #[executable] attribute. ```cairo #[executable] fn main() -> i32 { add(-1, 1) } ``` -------------------------------- ### Define Guinea Enum in Cairo Source: https://github.com/software-mansion/scarb/blob/main/extensions/scarb-doc/tests/data/hello_world_linked_items/src/hello_world-Guinea.md Defines an enumeration named Guinea with two variants: Guinea and Equatorial. This is a basic example of enum definition in Cairo. ```cairo enum Guinea { Guinea, Equatorial, } ``` -------------------------------- ### Create a new Scarb project Source: https://github.com/software-mansion/scarb/blob/main/website/docs/cheatsheet.md Use `scarb new` to create a new project in a specified directory. `scarb init` can be used to initialize a project in the current directory. ```shell scarb new project/directory ``` -------------------------------- ### Manage Workspace Packages and Scripts Source: https://context7.com/software-mansion/scarb/llms.txt Use `scarb build --workspace` to build all members, `scarb build --package ` for a specific member, and `scarb run --workspace