Skip to content

Commit

Permalink
Prepare for release 0.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
ksew1 committed Oct 3, 2024
1 parent 3af55e5 commit 1afe181
Show file tree
Hide file tree
Showing 6 changed files with 207 additions and 1 deletion.
57 changes: 57 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
name: Release

on:
workflow_dispatch:

permissions:
contents: write

jobs:
verify-branch:
name: Verify that runs on the main branch
runs-on: ubuntu-latest
steps:
- name: Fail if branch is not main
if: github.ref != 'refs/heads/main'
run: |
echo "The release workflow should only be triggered on the main branch"
exit 1
get-version:
name: Get version from Cargo.toml
needs: verify-branch
runs-on: ubuntu-latest
outputs:
version: ${{ steps.version.outputs.version }}

steps:
- uses: actions/checkout@v4

- name: Get version from Cargo.toml
id: lookupVersion
uses: mikefarah/yq@f15500b20a1c991c8729870ba60a4dc3524b6a94
with:
cmd: yq -oy '"v" + .workspace.package.version' 'Cargo.toml'

- name: Print version
id: version
run: |
VERSION=${{ steps.lookupVersion.outputs.result }}
echo "version=$VERSION" >> "$GITHUB_OUTPUT"
create-release:
name: Create release
runs-on: ubuntu-latest
needs: get-version
steps:
- uses: actions/checkout@v4

- name: Create GitHub release
id: create-release
uses: taiki-e/create-gh-release-action@72d65cee1f8033ef0c8b5d79eaf0c45c7c578ce3
with:
token: ${{ secrets.GITHUB_TOKEN }}
changelog: CHANGELOG.md
allow-missing-changelog: true
title: $version
ref: refs/tags/${{ needs.get-version.outputs.version }}
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Changelog

All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]
7 changes: 7 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,13 @@ members = [
version = "0.1.0"
edition = "2021"

authors = ["Software Mansion <contact@swmansion.com>"]
categories = ["development-tools"]
license = "MIT"
keywords = ["cairo-lang", "starknet"]
readme = "README.md"
repository = "https://github.com/software-mansion/cairo-annotations"

[workspace.dependencies]
cairo-lang-sierra-to-casm = "2.8.2"
cairo-lang-sierra = "2.8.2"
Expand Down
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2024 Software Mansion

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
107 changes: 106 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,106 @@
# cairo-annotations
# Cairo Annotations

The `cairo-annotations` crate provides tools tailored for working with annotations in the Cairo language.
These
annotations are part of the Sierra Debug Information format and serve to enrich the code by detailing information.

> 📝 **Note**
>
> Although this crate is primarily utilized by projects like `cairo-coverage`, `cairo-profiler`, and `starknet-foundry`,
> it is also fully capable of functioning as a standalone library to work with Sierra Debug Information annotations.
## Features of Cairo Annotations

### Structured Annotations

`cairo-annotations` offers a structured representation, allowing for more ergonomic manipulation of annotations.
Some
key features include:

- **Coverage Annotations**: Track locations in the Cairo code that correspond to specific Sierra statements.
- **Profiler Annotations**: Provide mappings from Sierra statements to fully qualified Cairo paths, detailing which
functions in the Cairo code triggered them.

All annotations implement the `TryFromDebugInfo` trait, enabling their extraction from Sierra debug information.
Here's
a simple example:

```rust
let annotations = VersionedCoverageAnnotations::try_from_debug_info(sierra_debug_info).unwrap();
```

### Coverage Annotations

Coverage annotations provide a mapping from Sierra statement indices to sources in the Cairo code that resulted in their
creation.
For extensive documentation,
see [CoverageAnnotationsV1](./crates/cairo-annotations/src/annotations/coverage.rs).

Example to retrieve code location information:

```rust
use cairo_annotations::annotations::coverage::{
CodeLocation, ColumnNumber, CoverageAnnotationsV1, LineNumber, SourceCodeLocation,
SourceCodeSpan, SourceFileFullPath, VersionedCoverageAnnotations,
};
use cairo_annotations::annotations::TryFromDebugInfo;
use cairo_lang_sierra::program::StatementIdx;

let VersionedCoverageAnnotations::V1(annotations) =
VersionedCoverageAnnotations::try_from_debug_info(sierra_debug_info).unwrap();

let code_locations = annotations
.statements_code_locations
.get( & StatementIdx(331))
.unwrap();

assert_eq!(
code_locations,
&[CodeLocation(
SourceFileFullPath("/path/to/my/file.cairo".into()),
SourceCodeSpan {
start: SourceCodeLocation { line: LineNumber(7), col: ColumnNumber(4) },
end: SourceCodeLocation { line: LineNumber(7), col: ColumnNumber(4) },
}
)]
);
```

### Profiler Annotations

Profiler annotations map Sierra statement indices to Cairo function paths, showing which functions led to their
generation.
Detailed information is available
in [ProfilerAnnotationsV1](./crates/cairo-annotations/src/annotations/profiler.rs).

Example to obtain the Cairo path:

```rust
use cairo_annotations::annotations::profiler::{
FunctionName, ProfilerAnnotationsV1, VersionedProfilerAnnotations,
};
use cairo_annotations::annotations::TryFromDebugInfo;
use cairo_lang_sierra::program::StatementIdx;

let VersionedProfilerAnnotations::V1(annotations) =
VersionedProfilerAnnotations::try_from_debug_info(sierra_debug_info).unwrap();

let functions_names = annotations
.statements_functions
.get( & StatementIdx(331))
.unwrap();

assert_eq!(
functions_names,
&[FunctionName("scarb_template::fib".into())]
);
```

## Integration with Snforge

Annotations are particularly useful for getting information about executed code. If you are using `snforge`, you can
leverage the `--save-trace-data` flag to generate trace data.

Deserialize this data using `VersionedCallTrace` from the `cairo-annotations` crate, and subsequently
use `map_pcs_to_sierra_statement_ids` to map the trace to Sierra statement IDs.

8 changes: 8 additions & 0 deletions crates/cairo-annotations/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,14 @@ name = "cairo-annotations"
version.workspace = true
edition.workspace = true

authors.workspace = true
categories.workspace = true
description = "Structured annotations for Cairo"
license.workspace = true
keywords.workspace = true
readme.workspace = true
repository.workspace = true

[dependencies]
cairo-lang-sierra-to-casm.workspace = true
cairo-lang-sierra.workspace = true
Expand Down

0 comments on commit 1afe181

Please sign in to comment.