Skip to content

Commit

Permalink
Merge branch 'master' into feat/forc-call
Browse files Browse the repository at this point in the history
  • Loading branch information
sdankel authored Jan 10, 2025
2 parents 945e38e + 1192b3f commit 6f26d1b
Show file tree
Hide file tree
Showing 76 changed files with 1,478 additions and 683 deletions.
12 changes: 11 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ jobs:
run: |
cargo install --locked --debug --path ./forc-plugins/forc-doc
- name: Build sway-lib-std docs
run: forc doc --manifest-path ./sway-lib-std
run: forc doc --path ./sway-lib-std

build-forc-test-project:
runs-on: buildjet-4vcpu-ubuntu-2204
Expand Down Expand Up @@ -470,6 +470,10 @@ jobs:
run: cargo run --locked --release -p forc -- build --release --locked --path ./test/src/sdk-harness
- name: Cargo Test sway-lib-std
run: cargo test --locked --release --manifest-path ./test/src/sdk-harness/Cargo.toml -- --nocapture
- name: Build All Tests - Experimental Feature 'storage_domains'
run: cargo run --locked --release -p forc -- build --experimental storage_domains --release --locked --path ./test/src/sdk-harness
- name: Cargo Test sway-lib-std - Experimental Feature 'storage_domains'
run: cargo test --locked --release --manifest-path ./test/src/sdk-harness/Cargo.toml -- --nocapture

forc-run-benchmarks:
runs-on: buildjet-4vcpu-ubuntu-2204
Expand Down Expand Up @@ -525,10 +529,16 @@ jobs:
run: cargo install --locked --debug --path ./forc
- name: Run Core Unit Tests
run: forc build --path sway-lib-core && forc test --path sway-lib-core
- name: Run Core Unit Tests - Experimental feature 'storage_domains'
run: forc build --experimental storage_domains --path sway-lib-core && forc test --experimental storage_domains --path sway-lib-core
- name: Run Std Unit Tests
run: forc build --path sway-lib-std && forc test --path sway-lib-std
- name: Run Std Unit Tests - Experimental feature 'storage_domains'
run: forc build --experimental storage_domains --path sway-lib-std && forc test --experimental storage_domains --path sway-lib-std
- name: Run In Language Unit Tests
run: forc build --path test/src/in_language_tests && forc test --path test/src/in_language_tests
- name: Run In Language Unit Tests - Experimental feature 'storage_domains'
run: forc build --experimental storage_domains --path test/src/in_language_tests && forc test --experimental storage_domains --path test/src/in_language_tests

forc-pkg-fuels-deps-check:
runs-on: buildjet-4vcpu-ubuntu-2204
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/gh-pages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ jobs:
run: mdbook build docs/reference

- name: Build Sway std library
run: forc doc --manifest-path ./sway-lib-std
run: forc doc --path ./sway-lib-std

- name: Deploy master std
uses: peaceiris/actions-gh-pages@v3
Expand Down
1 change: 0 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion examples/advanced_storage_variables/src/main.sw
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
contract;

use std::{bytes::Bytes, string::String,};
use std::{bytes::Bytes, string::String};

// ANCHOR: temp_hash_import
use std::hash::Hash;
Expand Down
2 changes: 1 addition & 1 deletion examples/converting_types/src/byte_arrays.sw
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
library;

// ANCHOR: to_byte_array_import
use std::array_conversions::{b256::*, u16::*, u256::*, u32::*, u64::*,};
use std::array_conversions::{b256::*, u16::*, u256::*, u32::*, u64::*};
// ANCHOR_END: to_byte_array_import

pub fn to_byte_array() {
Expand Down
2 changes: 1 addition & 1 deletion examples/converting_types/src/bytes.sw
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
library;

// ANCHOR: to_bytes_import
use std::{bytes::Bytes, bytes_conversions::{b256::*, u16::*, u256::*, u32::*, u64::*,}};
use std::{bytes::Bytes, bytes_conversions::{b256::*, u16::*, u256::*, u32::*, u64::*}};
// ANCHOR_END: to_bytes_import

pub fn convert_to_bytes() {
Expand Down
2 changes: 1 addition & 1 deletion examples/wallet_smart_contract/src/main.sw
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// ANCHOR: full_wallet
contract;

use std::{asset::transfer, call_frames::msg_asset_id, context::msg_amount,};
use std::{asset::transfer, call_frames::msg_asset_id, context::msg_amount};

// ANCHOR: abi_import
use wallet_abi::Wallet;
Expand Down
6 changes: 3 additions & 3 deletions forc-plugins/forc-doc/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ $ cargo install --path forc-plugins/forc-doc
Great! Let's check everything is working as intended. Try running `forc doc` on one of the test directories:

```sh
$ forc doc --manifest-path src/tests/data/impl_traits --open
$ forc doc --path src/tests/data/impl_traits --open
```

If it succeeded, you should be seeing the test docs in your browser.
Expand Down Expand Up @@ -274,10 +274,10 @@ Now we can call this function anytime we need to generate a searchbar for our we
Once you've made some changes, run the `forc doc` binary, passing it a path containing a `Forc.toml`:

```sh
cargo run -- --manifest-path path/to/manifest --open
cargo run -- --path path/to/manifest --open
```

> **Tip:** VS Code user? Try the Live Server plugin to make viewing changes even easier. It will reload a webpage on updates, so you only need to rebuild the docs (`cargo run -- --manifest-path path/to/manifest`). Just right click the index file of docs produced by `forc doc` which can be found in the `out/doc` directory, and choose the option "open with Live Server". Voila!
> **Tip:** VS Code user? Try the Live Server plugin to make viewing changes even easier. It will reload a webpage on updates, so you only need to rebuild the docs (`cargo run -- --path path/to/manifest`). Just right click the index file of docs produced by `forc doc` which can be found in the `out/doc` directory, and choose the option "open with Live Server". Voila!
[forc-reference]: https://fuellabs.github.io/sway/master/book/forc/index.html "forc reference"
[manifest-reference]: https://fuellabs.github.io/sway/master/book/forc/manifest_reference.html "manifest reference"
Expand Down
11 changes: 6 additions & 5 deletions forc-plugins/forc-doc/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ forc_util::cli_examples! {
crate::cli::Command {
[ Build the docs for a project in the current path => "forc doc"]
[ Build the docs for a project in the current path and open it in the browser => "forc doc --open" ]
[ Build the docs for a project located in another path => "forc doc --manifest-path {path}" ]
[ Build the docs for a project located in another path => "forc doc --path {path}" ]
[ Build the docs for the current project exporting private types => "forc doc --document-private-items" ]
[ Build the docs offline without downloading any dependency from the network => "forc doc --offline" ]
}
Expand All @@ -20,10 +20,11 @@ forc_util::cli_examples! {
version
)]
pub struct Command {
/// Path to the Forc.toml file. By default, forc-doc searches for the Forc.toml
/// file in the current directory or any parent directory.
#[clap(long)]
pub manifest_path: Option<String>,
/// Path to the project.
///
/// If not specified, current working directory will be used.
#[clap(short, long, alias = "manifest-path")]
pub path: Option<String>,
/// Include non-public items in the documentation.
#[clap(long)]
pub document_private_items: bool,
Expand Down
2 changes: 1 addition & 1 deletion forc-plugins/forc-doc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ pub fn compile_html(
get_doc_dir: &dyn Fn(&Command) -> String,
) -> Result<(PathBuf, Box<PackageManifestFile>)> {
// get manifest directory
let dir = if let Some(ref path) = build_instructions.manifest_path {
let dir = if let Some(ref path) = build_instructions.path {
PathBuf::from(path)
} else {
std::env::current_dir()?
Expand Down
4 changes: 2 additions & 2 deletions forc-plugins/forc-doc/src/tests/expects/impl_trait/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ fn test_impl_traits_default() {
let doc_dir_name: &str = "impl_traits_default";
let project_name = "impl_traits";
let command = Command {
manifest_path: Some(format!("{}/{}", DATA_DIR, project_name)),
path: Some(format!("{}/{}", DATA_DIR, project_name)),
doc_path: Some(doc_dir_name.into()),
..Default::default()
};
Expand Down Expand Up @@ -171,7 +171,7 @@ fn test_impl_traits_no_deps() {
let doc_dir_name: &str = "impl_traits_no_deps";
let project_name: &str = "impl_traits_clone";
let command = Command {
manifest_path: Some(format!("{}/{}", DATA_DIR, project_name)),
path: Some(format!("{}/{}", DATA_DIR, project_name)),
doc_path: Some(doc_dir_name.into()),
no_deps: true,
..Default::default()
Expand Down
4 changes: 2 additions & 2 deletions forc-plugins/forc-doc/tests/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ use std::path::Path;
fn builds_lib_std_docs() {
let path = Path::new("./../../sway-lib-std");
let build_instructions = Command {
manifest_path: Some(path.to_str().unwrap().to_string()),
path: Some(path.to_str().unwrap().to_string()),
..Default::default()
};
println!("Building docs for {:?}", build_instructions.manifest_path);
println!("Building docs for {:?}", build_instructions.path);
let res = compile_html(&build_instructions, &get_doc_dir);
assert!(res.is_ok());
}
37 changes: 8 additions & 29 deletions forc-plugins/forc-fmt/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ use std::{
path::{Path, PathBuf},
sync::Arc,
};
use sway_core::{BuildConfig, BuildTarget};
use sway_utils::{constants, find_parent_manifest_dir, get_sway_files, is_sway_file};
use swayfmt::Formatter;
use taplo::formatter as taplo_fmt;
Expand Down Expand Up @@ -46,7 +45,9 @@ pub struct App {
/// - Exits with `1` and prints a diff if formatting is required.
#[clap(short, long)]
pub check: bool,
/// Path to the project, if not specified, current working directory will be used.
/// Path to the project.
///
/// If not specified, current working directory will be used.
#[clap(short, long)]
pub path: Option<String>,
#[clap(short, long)]
Expand Down Expand Up @@ -77,13 +78,8 @@ fn run() -> Result<()> {
if let Some(f) = app.file.as_ref() {
let file_path = &PathBuf::from(f);

// If we're formatting a single file, find the nearest manifest if within a project.
// Otherwise, we simply provide 'None' to format_file().
let manifest_file = find_parent_manifest_dir(file_path)
.map(|path| path.join(constants::MANIFEST_FILE_NAME));

if is_sway_file(file_path) {
format_file(&app, file_path.to_path_buf(), manifest_file, &mut formatter)?;
format_file(&app, file_path.to_path_buf(), &mut formatter)?;
return Ok(());
}

Expand Down Expand Up @@ -142,12 +138,7 @@ fn get_sway_dirs(workspace_dir: PathBuf) -> Vec<PathBuf> {
/// - Ok(true) if executed successfully and formatted,
/// - Ok(false) if executed successfully and not formatted,
/// - Err if it fails to execute at all.
fn format_file(
app: &App,
file: PathBuf,
manifest_file: Option<PathBuf>,
formatter: &mut Formatter,
) -> Result<bool> {
fn format_file(app: &App, file: PathBuf, formatter: &mut Formatter) -> Result<bool> {
let file = file.canonicalize()?;
if is_file_dirty(&file) {
bail!(
Expand All @@ -160,14 +151,7 @@ fn format_file(
if let Ok(file_content) = fs::read_to_string(&file) {
let mut edited = false;
let file_content: Arc<str> = Arc::from(file_content);
let build_config = manifest_file.map(|f| {
BuildConfig::root_from_file_name_and_manifest_path(
file.clone(),
f,
BuildTarget::default(),
)
});
match Formatter::format(formatter, file_content.clone(), build_config.as_ref()) {
match Formatter::format(formatter, file_content.clone()) {
Ok(formatted_content) => {
if app.check {
if *file_content != formatted_content {
Expand Down Expand Up @@ -213,12 +197,7 @@ fn format_workspace_at_dir(app: &App, workspace: &WorkspaceManifestFile, dir: &P
for entry in read_dir.filter_map(|res| res.ok()) {
let path = entry.path();
if is_sway_file(&path) {
format_file(
app,
path,
Some(workspace.dir().to_path_buf()),
&mut formatter,
)?;
format_file(app, path, &mut formatter)?;
}
}
}
Expand Down Expand Up @@ -295,7 +274,7 @@ fn format_pkg_at_dir(app: &App, dir: &Path, formatter: &mut Formatter) -> Result
let mut contains_edits = false;

for file in files {
contains_edits |= format_file(app, file, Some(manifest_file.clone()), formatter)?;
contains_edits |= format_file(app, file, formatter)?;
}
// format manifest using taplo formatter
contains_edits |= format_manifest(app, manifest_file)?;
Expand Down
12 changes: 12 additions & 0 deletions sway-ast/src/expr/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,18 @@ impl ReassignmentOpVariant {
ReassignmentOpVariant::ShrEquals => "rsh",
}
}

pub fn as_str(&self) -> &'static str {
match self {
ReassignmentOpVariant::Equals => EqToken::AS_STR,
ReassignmentOpVariant::AddEquals => AddEqToken::AS_STR,
ReassignmentOpVariant::SubEquals => SubEqToken::AS_STR,
ReassignmentOpVariant::MulEquals => StarEqToken::AS_STR,
ReassignmentOpVariant::DivEquals => DivEqToken::AS_STR,
ReassignmentOpVariant::ShlEquals => ShlEqToken::AS_STR,
ReassignmentOpVariant::ShrEquals => ShrEqToken::AS_STR,
}
}
}

#[derive(Clone, Debug, Serialize)]
Expand Down
8 changes: 8 additions & 0 deletions sway-ast/src/expr/op_code.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,14 @@ macro_rules! define_op_codes (
}
}

pub fn op_code_as_str(&self) -> &'static str {
match self {
$(Instruction::$op_name { .. } => {
$s
},)*
}
}

#[allow(clippy::vec_init_then_push)]
pub fn register_arg_idents(&self) -> Vec<Ident> {
match self {
Expand Down
Loading

0 comments on commit 6f26d1b

Please sign in to comment.