-
Notifications
You must be signed in to change notification settings - Fork 2
feat: artifact support #122
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
lima-limon-inc
wants to merge
35
commits into
main
Choose a base branch
from
fabrizioorsi/i121-artifact-support
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 21 commits
Commits
Show all changes
35 commits
Select commit
Hold shift + click to select a range
22cb532
feat: pass $TARGET triple to crate at compile time
lima-limon-inc e0b66c1
feat: initial TargetTriple implementation
lima-limon-inc f2cbb16
feat: add Display impl for TargetTriple
lima-limon-inc 3cf9674
feat: implement artifact serialization
lima-limon-inc 8e095e5
feat: add Artifacts to Component
lima-limon-inc 85d1d75
feat: create lib and bin directories before executing the install script
lima-limon-inc 610e10c
feat: download artifacts
lima-limon-inc 734b715
feat: final touches when installing artifacts
lima-limon-inc 53a8aab
feat: add file// support for artifacts
lima-limon-inc 889216c
refactor: move install_artifact to cargo script
lima-limon-inc 3cd188e
feat: obtain curl version from Cargo.toml instead of hardcoding it
lima-limon-inc 9c9212f
refactor: make installation pipeline more linear
lima-limon-inc 0a4ba74
feat: save downloaded file in .tmp, then rename it when finished
lima-limon-inc a3da0d7
feat: fail in debug builds, continue in release mode
lima-limon-inc 305f5e6
feat: remove test file:// artifact from VM
lima-limon-inc 7727632
feat: add artifact support in libraries
lima-limon-inc 08f3053
feat: add std.masp as an example
lima-limon-inc a309539
feat: add miden VM Triplet
lima-limon-inc c18366e
feat: update manifest with new Triplet
lima-limon-inc 6b7c1e8
feat: add miden to the list of wellknown targets
lima-limon-inc c82f722
chore: reword comments
lima-limon-inc d8395a7
Merge branch 'main' into fabrizioorsi/i121-artifact-support
lima-limon-inc d0d2f32
Merge branch 'main' into fabrizioorsi/i121-artifact-support
lima-limon-inc 0b42d98
Merge branch 'main' into fabrizioorsi/i121-artifact-support
lima-limon-inc eb5d145
Merge branch 'main' into fabrizioorsi/i121-artifact-support
lima-limon-inc ab2b6de
WIP
lima-limon-inc 7fec7b8
refactor: remove Artifact HashMap in favor of lists
lima-limon-inc e7a32f0
refactor: take MidenVM artifacts into account
lima-limon-inc f32fcdc
refactor: remove target from artifact, obtain it from the link itself
lima-limon-inc 31aa2a2
refactor: contains now returns the Option<String> instead of bool
lima-limon-inc 3d138da
refactor: rename Artifact::contains -> Artifact::get_uri_for
lima-limon-inc 54d3b42
nit: make lint
lima-limon-inc a2d9adb
nit: remove pub indicator from Artifact
lima-limon-inc 40842f4
docs: expand Artifact documentation
lima-limon-inc d4acf30
nit: remove example artifact uris
lima-limon-inc File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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,157 @@ | ||
| use std::{fmt::Display, str::FromStr}; | ||
|
|
||
| use serde::{Deserialize, Serialize}; | ||
| use thiserror::Error; | ||
|
|
||
| #[derive(Serialize, Deserialize, Debug, Clone)] | ||
| pub struct Artifacts { | ||
| artifacts: Vec<Artifact>, | ||
| } | ||
|
|
||
| impl Artifacts { | ||
| /// Get a URI to download an artifact that's valid for [target]. | ||
| pub fn get_uri_for(&self, target: &TargetTriple) -> Option<String> { | ||
| self.artifacts | ||
| .iter() | ||
| .find(|artifact| artifact.target == *target) | ||
| .map(|arti| arti.uri.clone()) | ||
| } | ||
| } | ||
|
|
||
| /// Represents a mapping from a given [target] to the [url] which contains it. | ||
| #[derive(Serialize, Deserialize, Debug, Clone)] | ||
| struct Artifact { | ||
| target: TargetTriple, | ||
|
|
||
| uri: String, | ||
| } | ||
|
|
||
| /// Struct that represents a target architecture by the rust compiler. | ||
| /// There is no universal standadarized way to represent them, however, | ||
| /// according to the | ||
| /// [LLVM documentation](https://llvm.org/doxygen/Triple_8h_source.html), | ||
| /// most triples have one of the following two shapes: | ||
| /// - "ARCHITECTURE-VENDOR-OPERATING_SYSTEM" | ||
| /// - "ARCHITECTURE-VENDOR-OPERATING_SYSTEM-ENVIRONMENT" | ||
| /// | ||
| /// This template does match with two major wellknown targets: | ||
| /// aarch64-apple-darwin and x86_64-unknown-linux-gnu. | ||
| /// | ||
| /// There is one *notable* special case which is the Miden VM. MASP Libraries | ||
| /// are OS/environent-agnostic, since they target the Miden VM itself. So, they | ||
| /// use the following triplet: zkvm-miden-unknown | ||
| #[derive(Debug, PartialEq, Eq, Clone)] | ||
| pub struct TargetTriple { | ||
| architecture: String, | ||
| vendor: String, | ||
| operating_system: String, | ||
| environment: Option<String>, | ||
| } | ||
|
|
||
| impl serde::ser::Serialize for TargetTriple { | ||
| fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> | ||
| where | ||
| S: serde::ser::Serializer, | ||
| { | ||
| serializer.serialize_str(&self.to_string()) | ||
| } | ||
| } | ||
|
|
||
| impl<'de> serde::de::Deserialize<'de> for TargetTriple { | ||
| fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> | ||
| where | ||
| D: serde::de::Deserializer<'de>, | ||
| { | ||
| let s = String::deserialize(deserializer)?; | ||
| s.parse::<Self>().map_err(serde::de::Error::custom) | ||
| } | ||
| } | ||
|
|
||
| #[derive(Error, Debug)] | ||
| pub enum TargetTripleError { | ||
| #[error("Failed to deserialize TargetTriplet because: {0}")] | ||
| UnrecognizedTargetTriple(String), | ||
| } | ||
|
|
||
| impl FromStr for TargetTriple { | ||
| type Err = TargetTripleError; | ||
|
|
||
| fn from_str(s: &str) -> Result<Self, Self::Err> { | ||
| let mut parts = s.split("-"); | ||
| let architecture = parts | ||
| .next() | ||
| .ok_or(TargetTripleError::UnrecognizedTargetTriple( | ||
| "Missing 'architecture' field".into(), | ||
| ))? | ||
| .into(); | ||
| let vendor = parts | ||
| .next() | ||
| .ok_or(TargetTripleError::UnrecognizedTargetTriple("Missing 'vendor' field".into()))? | ||
| .into(); | ||
| let operating_system = parts | ||
| .next() | ||
| .ok_or(TargetTripleError::UnrecognizedTargetTriple( | ||
| "Missing 'operating_system' field".into(), | ||
| ))? | ||
| .into(); | ||
| let environment = parts.next().map(String::from); | ||
| Ok(TargetTriple { | ||
| architecture, | ||
| vendor, | ||
| operating_system, | ||
| environment, | ||
| }) | ||
| } | ||
| } | ||
|
|
||
| impl Display for TargetTriple { | ||
| fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { | ||
| let repr = format!( | ||
| "{}-{}-{}{}", | ||
| self.architecture, | ||
| self.vendor, | ||
| self.operating_system, | ||
| self.environment.as_ref().map(|env| format!("-{}", env)).unwrap_or_default() | ||
| ); | ||
| write!(f, "{repr}") | ||
| } | ||
| } | ||
|
|
||
| impl TargetTriple { | ||
| pub fn miden_vm() -> TargetTriple { | ||
| TargetTriple { | ||
| architecture: String::from("zkvm"), | ||
| vendor: String::from("miden"), | ||
| operating_system: String::from("unknown"), | ||
| environment: None, | ||
| } | ||
| } | ||
| } | ||
|
|
||
| #[cfg(test)] | ||
| mod tests { | ||
| use std::str::FromStr; | ||
|
|
||
| use super::TargetTriple; | ||
|
|
||
| #[test] | ||
| /// Test that we can parse triples that we actually support. | ||
| fn parse_wellknown_targets() { | ||
| let mut failed_parsing = Vec::new(); | ||
| let well_known_targets = | ||
| ["aarch64-apple-darwin", "x86_64-unknown-linux-gnu", "zkvm-miden-unknown"]; | ||
| for target in well_known_targets { | ||
| if let Err(err) = TargetTriple::from_str(target) { | ||
| failed_parsing.push((target, err)); | ||
| } | ||
| } | ||
| if failed_parsing.is_empty() { | ||
| return; | ||
| } | ||
| let err_message = failed_parsing.iter().fold( | ||
| String::from("Failed to serialize the following well known targets:"), | ||
| |acc, (target, err)| format!("{acc}\n - {target}, because {}", err), | ||
| ); | ||
| panic!("{}", err_message) | ||
| } | ||
| } |
This file contains hidden or 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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These URLS are not intended to be merged and are only here to test this PR. They should be removed before merging.