-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
207 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters