Skip to content

Commit

Permalink
refactor: rust formatting (#422)
Browse files Browse the repository at this point in the history
* refactor: update rustfmt.toml

* refactor: apply cargo +nightly fmt

* refactor: update rustfmt job in Rust workflow

* refactor: fix pull_request trigger on rust.yml

* refactor: use rolling nightly toolchain

* refactor: use nightly rustfmt in scripts/execution_layer.py

* refactor: update mysticeti,external workflows

* refactor(sui-json-rpc-api): skip formatting of method argument comments

* refactor: fix rustfmt check in external workflow

* refactor: format external_crates/move

* refactor(CI): trigger external workflow on develop

* refactor: add Rust and fmt setup guidelines in README

* refactor: remove suiop-cli format override
  • Loading branch information
kodemartin authored May 30, 2024
1 parent 937eba6 commit 4e92259
Show file tree
Hide file tree
Showing 22 changed files with 436 additions and 352 deletions.
29 changes: 15 additions & 14 deletions crates/sui-framework/build.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
// Copyright (c) Mysten Labs, Inc.
// SPDX-License-Identifier: Apache-2.0

use anyhow::Result;
use move_binary_format::CompiledModule;
use move_compiler::editions::Edition;
use move_package::{BuildConfig as MoveBuildConfig, LintFlag};
use std::{
collections::BTreeMap,
env, fs,
path::{Path, PathBuf},
};

use anyhow::Result;
use move_binary_format::CompiledModule;
use move_compiler::editions::Edition;
use move_package::{BuildConfig as MoveBuildConfig, LintFlag};
use sui_move_build::{BuildConfig, SuiPackageHooks};

const DOCS_DIR: &str = "docs";
Expand Down Expand Up @@ -220,8 +220,8 @@ fn build_packages_with_move_config(
serialize_modules_to_file(timelock, &out_dir.join(timelock_dir)).unwrap();
// write out generated docs
if write_docs {
// Remove the old docs directory -- in case there was a module that was deleted (could
// happen during development).
// Remove the old docs directory -- in case there was a module that was deleted
// (could happen during development).
if Path::new(DOCS_DIR).exists() {
std::fs::remove_dir_all(DOCS_DIR).unwrap();
}
Expand Down Expand Up @@ -260,16 +260,17 @@ fn build_packages_with_move_config(
}
}

/// Post process the generated docs so that they are in a format that can be consumed by
/// docusaurus.
/// * Flatten out the tree-like structure of the docs directory that we generate for a package into
/// a flat list of packages;
/// * Deduplicate packages (since multiple packages could share dependencies); and
/// Post process the generated docs so that they are in a format that can be
/// consumed by docusaurus.
/// * Flatten out the tree-like structure of the docs directory that we generate
/// for a package into a flat list of packages;
/// * Deduplicate packages (since multiple packages could share dependencies);
/// and
/// * Write out the package docs in a flat directory structure.
fn relocate_docs(prefix: &str, files: &[(String, String)], output: &mut BTreeMap<String, String>) {
// Turn on multi-line mode so that `.` matches newlines, consume from the start of the file to
// beginning of the heading, then capture the heading and replace with the yaml tag for docusaurus. E.g.,
// ```
// Turn on multi-line mode so that `.` matches newlines, consume from the start
// of the file to beginning of the heading, then capture the heading and
// replace with the yaml tag for docusaurus. E.g., ```
// -<a name="0x2_display"></a>
// -
// -# Module `0x2::display`
Expand Down
68 changes: 37 additions & 31 deletions crates/sui-framework/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,28 +1,30 @@
// Copyright (c) Mysten Labs, Inc.
// SPDX-License-Identifier: Apache-2.0

use move_binary_format::binary_config::BinaryConfig;
use move_binary_format::compatibility::Compatibility;
use move_binary_format::file_format::{Ability, AbilitySet};
use move_binary_format::CompiledModule;
use std::fmt::Formatter;

use move_binary_format::{
binary_config::BinaryConfig,
compatibility::Compatibility,
file_format::{Ability, AbilitySet},
CompiledModule,
};
use move_core_types::gas_algebra::InternalGas;
use once_cell::sync::Lazy;
use serde::{Deserialize, Serialize};
use std::fmt::Formatter;
use sui_types::base_types::ObjectRef;
use sui_types::storage::ObjectStore;
use sui_types::{
base_types::ObjectID,
base_types::{ObjectID, ObjectRef},
digests::TransactionDigest,
move_package::MovePackage,
object::{Object, OBJECT_START_VERSION},
MOVE_STDLIB_PACKAGE_ID, SUI_FRAMEWORK_PACKAGE_ID, SUI_SYSTEM_PACKAGE_ID,
storage::ObjectStore,
DEEPBOOK_PACKAGE_ID, MOVE_STDLIB_PACKAGE_ID, STARDUST_PACKAGE_ID, SUI_FRAMEWORK_PACKAGE_ID,
SUI_SYSTEM_PACKAGE_ID, TIMELOCK_PACKAGE_ID,
};
use sui_types::{DEEPBOOK_PACKAGE_ID, STARDUST_PACKAGE_ID, TIMELOCK_PACKAGE_ID};
use tracing::error;

/// Represents a system package in the framework, that's built from the source code inside
/// sui-framework.
/// Represents a system package in the framework, that's built from the source
/// code inside sui-framework.
#[derive(Clone, Serialize, PartialEq, Eq, Deserialize)]
pub struct SystemPackage {
pub id: ObjectID,
Expand Down Expand Up @@ -104,8 +106,8 @@ macro_rules! define_system_packages {
pub struct BuiltInFramework;
impl BuiltInFramework {
/// Dedicated method to iterate on `stardust` packages.
// TODO: integrate to iter_system_packages when we make a new system-framework-snapshot
// with the associated protocol bump:wq
// TODO: integrate to iter_system_packages when we make a new
// system-framework-snapshot with the associated protocol bump:wq
pub fn iter_stardust_packages() -> impl Iterator<Item = &'static SystemPackage> {
define_system_packages!([
(
Expand All @@ -127,9 +129,10 @@ impl BuiltInFramework {
}

pub fn iter_system_packages() -> impl Iterator<Item = &'static SystemPackage> {
// All system packages in the current build should be registered here, and this is the only
// place we need to worry about if any of them changes.
// TODO: Is it possible to derive dependencies from the bytecode instead of manually specifying them?
// All system packages in the current build should be registered here, and this
// is the only place we need to worry about if any of them changes.
// TODO: Is it possible to derive dependencies from the bytecode instead of
// manually specifying them?
define_system_packages!([
(MOVE_STDLIB_PACKAGE_ID, "move-stdlib", []),
(
Expand Down Expand Up @@ -174,17 +177,18 @@ pub fn legacy_test_cost() -> InternalGas {
InternalGas::new(0)
}

/// Check whether the framework defined by `modules` is compatible with the framework that is
/// already on-chain (i.e. stored in `object_store`) at `id`.
/// Check whether the framework defined by `modules` is compatible with the
/// framework that is already on-chain (i.e. stored in `object_store`) at `id`.
///
/// - Returns `None` if the current package at `id` cannot be loaded, or the compatibility check
/// fails (This is grounds not to upgrade).
/// - Panics if the object at `id` can be loaded but is not a package -- this is an invariant
/// violation.
/// - Returns the digest of the current framework (and version) if it is equivalent to the new
/// framework (indicates support for a protocol upgrade without a framework upgrade).
/// - Returns the digest of the new framework (and version) if it is compatible (indicates
/// support for a protocol upgrade with a framework upgrade).
/// - Returns `None` if the current package at `id` cannot be loaded, or the
/// compatibility check fails (This is grounds not to upgrade).
/// - Panics if the object at `id` can be loaded but is not a package -- this is
/// an invariant violation.
/// - Returns the digest of the current framework (and version) if it is
/// equivalent to the new framework (indicates support for a protocol upgrade
/// without a framework upgrade).
/// - Returns the digest of the new framework (and version) if it is compatible
/// (indicates support for a protocol upgrade with a framework upgrade).
pub async fn compare_system_package<S: ObjectStore>(
object_store: &S,
id: &ObjectID,
Expand All @@ -200,12 +204,14 @@ pub async fn compare_system_package<S: ObjectStore>(
return Some(
Object::new_system_package(
modules,
// note: execution_engine assumes any system package with version OBJECT_START_VERSION is freshly created
// rather than upgraded
// note: execution_engine assumes any system package with version
// OBJECT_START_VERSION is freshly created rather than
// upgraded
OBJECT_START_VERSION,
dependencies,
// Genesis is fine here, we only use it to calculate an object ref that we can use
// for all validators to commit to the same bytes in the update
// Genesis is fine here, we only use it to calculate an object ref that we can
// use for all validators to commit to the same bytes in
// the update
TransactionDigest::genesis_marker(),
)
.compute_object_reference(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,16 @@

//! Example demonstrating building and compiling two native token packages.
use iota_sdk::types::block::address::AliasAddress;
use iota_sdk::types::block::output::{AliasId, FoundryId};
use iota_sdk::Url;
use sui_genesis_builder::stardust::native_token::package_builder;
use sui_genesis_builder::stardust::native_token::package_data::{
NativeTokenModuleData, NativeTokenPackageData,
use iota_sdk::{
types::block::{
address::AliasAddress,
output::{AliasId, FoundryId},
},
Url,
};
use sui_genesis_builder::stardust::native_token::{
package_builder,
package_data::{NativeTokenModuleData, NativeTokenPackageData},
};

fn main() -> anyhow::Result<()> {
Expand Down
Loading

0 comments on commit 4e92259

Please sign in to comment.