Skip to content

Commit

Permalink
Merge branch 'release/2.4.1' into release/2.4.2
Browse files Browse the repository at this point in the history
  • Loading branch information
cwkang1998 committed Sep 2, 2024
2 parents ce2b6b4 + 725ae86 commit a19794b
Show file tree
Hide file tree
Showing 20 changed files with 226 additions and 189 deletions.
93 changes: 48 additions & 45 deletions .github/workflows/sync-changes-to-release-branch.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,52 +13,55 @@ permissions:
# release flow.
jobs:
sync-branches:
strategy:
matrix:
supported-version:
[
"1.1.0",
"1.1.1",
"2.0.1",
"2.0.2",
"2.1.0",
"2.1.1",
"2.2.0",
"2.3.0",
"2.3.1",
"2.4.0",
"2.4.1",
"2.4.2",
"2.4.3",
"2.4.4",
"2.5.0",
"2.5.1",
"2.5.2",
"2.5.3",
"2.5.4",
"2.6.0",
"2.6.1",
"2.6.2",
"2.6.3",
]
# strategy:
# matrix:
# supported-version:
# [
# "1.1.0",
# "1.1.1",
# "2.0.1",
# "2.0.2",
# "2.1.0",
# "2.1.1",
# "2.2.0",
# "2.3.0",
# "2.3.1",
# "2.4.0",
# "2.4.1",
# "2.4.2",
# "2.4.3",
# "2.4.4",
# "2.5.0",
# "2.5.1",
# "2.5.2",
# "2.5.3",
# "2.5.4",
# "2.6.0",
# "2.6.1",
# "2.6.2",
# "2.6.3",
# ]
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
# Do nothing for now since the newest changes include version updates.
- name: Do nothing
run: echo nothing
# - name: Checkout
# uses: actions/checkout@v4
# with:
# fetch-depth: 0

# This user can be anything using any email, just for git to work as expected.
- name: setup git configs
run: |
git config user.name "cwkang1998 (Github Action)"
git config user.email "23054115+cwkang1998@users.noreply.github.com"
# # This user can be anything using any email, just for git to work as expected.
# - name: setup git configs
# run: |
# git config user.name "cwkang1998 (Github Action)"
# git config user.email "23054115+cwkang1998@users.noreply.github.com"

- name: update all release branches
run: |
git checkout main
git fetch origin
git checkout release/${{ matrix.supported-version }}
git pull
git merge origin/main
git push origin release/${{ matrix.supported-version }}
# - name: update all release branches
# run: |
# git checkout main
# git fetch origin
# git checkout release/${{ matrix.supported-version }}
# git pull
# git merge origin/main
# git push origin release/${{ matrix.supported-version }}
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@


#### We currently support the following cairo version & scarb version.
- [x] Cairo 1.1.0 (Scarb v0.4.0)
<!-- - [x] Cairo 1.1.0 (Scarb v0.4.0)
- [x] Cairo 1.1.1 (Scarb v0.4.1)
- [x] Cairo 2.0.1 (Scarb v0.5.1)
- [x] Cairo 2.0.2 (Scarb v0.5.2)
- [x] Cairo 2.1.0 (Scarb v0.6.1)
- [x] Cairo 2.1.1 (Scarb v0.6.2)
- [x] Cairo 2.2.0 (Scarb v0.7.0)
- [x] Cairo & Scarb 2.3.0
- [x] Cairo & Scarb 2.3.0 -->
- [x] Cairo & Scarb 2.3.1
- [x] Cairo & Scarb 2.4.0
- [x] Cairo & Scarb 2.4.1
Expand Down
12 changes: 0 additions & 12 deletions crates/cli/src/resolver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,7 @@ pub enum TargetType {

pub fn get_dynamic_compiler(cairo_version: SupportedCairoVersions) -> Box<dyn DynamicCompiler> {
match cairo_version {
<<<<<<< HEAD
// SupportedCairoVersions::V1_1_0 => Box::new(VoyagerGeneratorV1_1_0),
// SupportedCairoVersions::V1_1_1 => Box::new(VoyagerGeneratorV1_1_1),
// SupportedCairoVersions::V2_0_0 => Box::new(VoyagerGeneratorV2_0_0),
// SupportedCairoVersions::V2_0_1 => Box::new(VoyagerGeneratorV2_0_1),
// SupportedCairoVersions::V2_0_2 => Box::new(VoyagerGeneratorV2_0_2),
// SupportedCairoVersions::V2_1_0 => Box::new(VoyagerGeneratorV2_1_0),
// SupportedCairoVersions::V2_1_1 => Box::new(VoyagerGeneratorV2_1_1),
// SupportedCairoVersions::V2_2_0 => Box::new(VoyagerGeneratorV2_2_0),
SupportedCairoVersions::V2_4_2 => Box::new(VoyagerGenerator),
=======
SupportedCairoVersions::V2_4_3 => Box::new(VoyagerGenerator),
>>>>>>> main
}
}

Expand Down
24 changes: 0 additions & 24 deletions crates/cli/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,36 +28,12 @@ pub fn detect_local_tools() -> (SupportedScarbVersions, SupportedCairoVersions)
.collect::<Vec<&str>>()[1];

let scarb_version = match scarb_version {
<<<<<<< HEAD
// "0.4.0" => SupportedScarbVersions::V0_4_0,
// "0.4.1" => SupportedScarbVersions::V0_4_1,
// "0.5.0" => SupportedScarbVersions::V0_5_0,
// "0.5.1" => SupportedScarbVersions::V0_5_1,
// "0.5.2" => SupportedScarbVersions::V0_5_2,
// "0.6.1" => SupportedScarbVersions::V0_6_1,
// "0.6.2" => SupportedScarbVersions::V0_6_2,
// "0.7.0" => SupportedScarbVersions::V0_7_0,
"2.4.2" => SupportedScarbVersions::V2_4_2,
=======
"2.4.3" => SupportedScarbVersions::V2_4_3,
>>>>>>> main
_ => panic!("Unsupported scarb version: {}", scarb_version),
};

let cairo_version = match cairo_version {
<<<<<<< HEAD
// "1.1.0" => SupportedCairoVersions::V1_1_0,
// "1.1.1" => SupportedCairoVersions::V1_1_1,
// "2.0.0" => SupportedCairoVersions::V2_0_0,
// "2.0.1" => SupportedCairoVersions::V2_0_1,
// "2.0.2" => SupportedCairoVersions::V2_0_2,
// "2.1.0" => SupportedCairoVersions::V2_1_0,
// "2.1.1" => SupportedCairoVersions::V2_1_1,
// "2.2.0" => SupportedCairoVersions::V2_2_0,
"2.4.2" => SupportedCairoVersions::V2_4_2,
=======
"2.4.3" => SupportedCairoVersions::V2_4_3,
>>>>>>> main
_ => {
println!("Unsupported cairo version {}. We thus do not guarantee compatibility and compilation might fail as a result.", cairo_version);
// Use latest Scarb version as default.
Expand Down
32 changes: 0 additions & 32 deletions crates/dyn-compiler/src/dyn_compiler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,57 +3,25 @@ use camino::Utf8PathBuf;

#[derive(Debug, Clone, Copy)]
pub enum SupportedCairoVersions {
// V1_1_0,
// V1_1_1,
// V2_0_0,
// V2_0_1,
// V2_0_2,
// V2_1_0,
// V2_1_1,
// V2_2_0,
V2_4_2,
}

impl ToString for SupportedCairoVersions {
fn to_string(&self) -> String {
match self {
// SupportedCairoVersions::V1_1_0 => "1.1.0".into(),
// SupportedCairoVersions::V1_1_1 => "1.1.1".into(),
// SupportedCairoVersions::V2_0_0 => "2.0.0".into(),
// SupportedCairoVersions::V2_0_1 => "2.0.1".into(),
// SupportedCairoVersions::V2_0_2 => "2.0.2".into(),
// SupportedCairoVersions::V2_1_0 => "2.1.0".into(),
// SupportedCairoVersions::V2_1_1 => "2.1.1".into(),
// SupportedCairoVersions::V2_2_0 => "2.2.0".into(),
SupportedCairoVersions::V2_4_2 => "2.4.2".into(),
}
}
}

#[derive(Debug, Clone, Copy)]
pub enum SupportedScarbVersions {
// V0_4_0,
// V0_4_1,
// V0_5_0,
// V0_5_1,
// V0_5_2,
// V0_6_1,
// V0_6_2,
// V0_7_0,
V2_4_2,
}

impl ToString for SupportedScarbVersions {
fn to_string(&self) -> String {
match self {
// SupportedScarbVersions::V0_4_0 => "0.4.0".into(),
// SupportedScarbVersions::V0_4_1 => "0.4.1".into(),
// SupportedScarbVersions::V0_5_0 => "0.5.0".into(),
// SupportedScarbVersions::V0_5_1 => "0.5.1".into(),
// SupportedScarbVersions::V0_5_2 => "0.5.2".into(),
// SupportedScarbVersions::V0_6_1 => "0.6.1".into(),
// SupportedScarbVersions::V0_6_2 => "0.6.2".into(),
// SupportedScarbVersions::V0_7_0 => "0.7.0".into(),
SupportedScarbVersions::V2_4_2 => "2.4.2".into(),
}
}
Expand Down
44 changes: 33 additions & 11 deletions crates/voyager-resolver-cairo/src/compiler/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,12 @@ use cairo_lang_defs::ids::ModuleId;
use cairo_lang_filesystem::db::FilesGroup;
use cairo_lang_filesystem::ids::{CrateId, CrateLongId, FileLongId};
use camino::Utf8PathBuf;
use scarb_utils::get_external_nonlocal_packages;
use std::clone;
use std::collections::HashMap;
use std::path::{Path, PathBuf};
use std::thread::sleep;
use std::time::Duration;

use cairo_lang_defs::db::DefsGroup;
use cairo_lang_diagnostics::ToOption;
Expand Down Expand Up @@ -127,7 +131,6 @@ impl Compiler for VoyagerGenerator {

// Creates a graph where nodes are cairo modules, and edges are the dependencies between modules.
let graph = create_graph(&project_modules);
_display_graphviz(&graph);

// Read Scarb manifest file to get the list of contracts to verify from the [tool.voyager] section.
// This returns the relative file paths of the contracts to verify.
Expand Down Expand Up @@ -157,8 +160,20 @@ impl Compiler for VoyagerGenerator {
.filter(|m| contracts_to_verify.contains(&m.relative_filepath))
.collect::<Vec<_>>();

let external_packages = get_external_nonlocal_packages(metadata.clone());

let (required_modules_paths, attachment_modules_data) =
self.get_reduced_project(&graph, modules_to_verify)?;
self.get_reduced_project(&graph, modules_to_verify.clone())?;

// Filter away packages that are external, imported from git repository & std.
let attachment_modules_data = attachment_modules_data
.iter()
.filter(|(k, _)| {
let base_package_name = &k.0.split("::").collect::<Vec<&str>>()[0].to_string();
!external_packages.contains(base_package_name) && base_package_name != "super"
})
.map(|(k, v)| (k.clone(), v.clone()))
.collect::<HashMap<ModulePath, CairoAttachmentModule>>();

let target_dir = Utf8PathBuf::from(
manifest_path
Expand Down Expand Up @@ -188,19 +203,32 @@ impl Compiler for VoyagerGenerator {
// Get the Cairo Modules corresponding to the required modules paths.
let required_modules = project_modules
.iter()
.filter(|m| required_modules_paths.contains(&m.path))
.filter(|m| {
let base_package_name = &m.path.0.split("::").collect::<Vec<&str>>()[0].trim();
required_modules_paths.contains(&m.path)
&& !external_packages.contains(&base_package_name.to_string())
})
.collect::<Vec<_>>();
// Copy these modules in the target directory.
// Copy readme files and license files over too
copy_required_files(&required_modules, &target_dir, ws)?;

// Generate each of the scarb manifest files for the output directory.
// The dependencies are updated to include the required modules as local dependencies.
generate_scarb_updated_files(metadata, &target_dir, required_modules)?;
generate_scarb_updated_files(metadata, &target_dir, required_modules, external_packages)?;

let package_name = unit.main_component().package.id.name.to_string();
let generated_crate_dir = target_dir.path_existent().unwrap().join(package_name);
//Locally run scarb build to make sure that everything compiles correctly before sending the files to voyager.

// Problem with this step is that sometimes the build happens faster than the Scarb.toml is actually created and detected.
// For some weird reason this is only an issue before cairo 2.6?
// Adding this artificial delay here in order to hopefully resolve this, or at least reduce its occurrences.
// TODO: actually addressing this, or not. Likely related to this https://github.com/rust-lang/rust/issues/51775
// likely also related to the fact that during compilation and resolving the git cloned libraries takes some time to be
// pulled and updated, which might have caused this.
sleep(Duration::from_secs(2));

// Locally run scarb build to make sure that everything compiles correctly before sending the files to voyager.
run_scarb_build(generated_crate_dir.as_str())?;

Ok(())
Expand Down Expand Up @@ -297,12 +325,6 @@ impl VoyagerGenerator {
&required_modules_paths,
imports_path_not_matching_resolved_path.clone(),
);
println!(
"{:?}\n {:?}\n {:?}",
required_modules_paths,
imports_path_not_matching_resolved_path.clone(),
attachment_modules_data
);

let unrequired_attachment_modules: HashMap<ModulePath, CairoAttachmentModule> =
attachment_modules_data
Expand Down
2 changes: 1 addition & 1 deletion crates/voyager-resolver-cairo/src/compiler/queries.rs
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,7 @@ pub fn extract_file_imports(
let import_path = segments
.clone()
.into_iter()
.map(|x| x.as_syntax_node().get_text(db))
.map(|x| x.as_syntax_node().get_text(db).trim().to_string())
.join("::");

// The resolver must resolve using the correct module that is importing it.
Expand Down
Loading

0 comments on commit a19794b

Please sign in to comment.