Skip to content

gblend init option Blended App Foundry Template #6

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
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 4 additions & 18 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,12 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- uses: Swatinem/rust-cache@v2
with:
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
restore-keys: |
${{ runner.os }}-cargo-

- uses: dtolnay/rust-toolchain@master
with:
toolchain: nightly-2024-10-01
toolchain: nightly-2025-01-27
components: rustfmt, clippy

- name: Lint
run: |
cargo fmt -- --check
Expand All @@ -34,19 +28,11 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- uses: Swatinem/rust-cache@v2
with:
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
restore-keys: |
${{ runner.os }}-cargo-


- uses: dtolnay/rust-toolchain@stable

- name: Install wasm32 target
run: rustup target add wasm32-unknown-unknown

- name: Test
run: cargo test --all-features --locked


3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@
/target
/testing
/tmp
/.idea
/.idea
.DS_Store
2 changes: 1 addition & 1 deletion rust-toolchain
Original file line number Diff line number Diff line change
@@ -1 +1 @@
nightly-2024-10-01
nightly-2025-01-27
139 changes: 133 additions & 6 deletions src/commands/legacy_init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ pub async fn legacy_init() -> Result<()> {
"Hardhat JavaScript (Solidity & Vyper)",
"Hardhat TypeScript (Solidity & Vyper)",
"Rust",
"Blendedapp 🔄",
"Blendedapp Hardhat 🔄",
"Blendedapp Foundry 🔄",
"Exit",
];
let selection = Select::new()
Expand All @@ -41,8 +42,9 @@ pub async fn legacy_init() -> Result<()> {
0 => spin_js(use_erc20)?,
1 => spin_ts(use_erc20)?,
2 => spin_rust()?,
3 => spin_blended_app()?,
4 => {
3 => spin_blended_app_hardhat()?,
4 => spin_blended_app_foundry()?,
5 => {
println!("Exiting program.");
return Ok(()); // Exit the program gracefully
}
Expand Down Expand Up @@ -243,8 +245,8 @@ fn spin_ts(use_erc20: bool) -> Result<()> {
Ok(())
}

fn spin_blended_app() -> Result<()> {
println!("Creating blended app ...");
fn spin_blended_app_hardhat() -> Result<()> {
println!("Creating blended app with Hardhat ...");

// Embed the files in the binary using `include_str!`
const HARDHAT_CONFIG: &str = include_str!(concat!(
Expand Down Expand Up @@ -328,7 +330,132 @@ fn spin_blended_app() -> Result<()> {
create_file_with_content(".env", ENV)?;
create_file_with_content(".gitignore", GIT_IGNORE)?;

println!("Blended app created successfully!");
println!("Blended app with Hardhat created successfully!");

Ok(())
}

fn spin_blended_app_foundry() -> Result<()> {
println!("Creating blended app with Foundry...");

// Embed the files in the binary using `include_str!`
const JAVASCRIPT_GIT_IGNORE: &str = include_str!(concat!(
env!("CARGO_MANIFEST_DIR"),
"/templates/blendedAppFoundry/javascript/.gitignore"
));
const JAVASCRIPT_PACKAGE_JSON: &str = include_str!(concat!(
env!("CARGO_MANIFEST_DIR"),
"/templates/blendedAppFoundry/javascript/package.json"
));
const JAVASCRIPT_SOLIDITY: &str = include_str!(concat!(
env!("CARGO_MANIFEST_DIR"),
"/templates/blendedAppFoundry/javascript/solidity.js"
));
const JAVASCRIPT_RUST: &str = include_str!(concat!(
env!("CARGO_MANIFEST_DIR"),
"/templates/blendedAppFoundry/javascript/rust.js"
));

const RUST_GIT_IGNORE: &str = include_str!(concat!(
env!("CARGO_MANIFEST_DIR"),
"/templates/blendedAppFoundry/rust/.gitignore"
));
const RUST_CARGO_TOML: &str = include_str!(concat!(
env!("CARGO_MANIFEST_DIR"),
"/templates/blendedAppFoundry/rust/Cargo.toml"
));
const RUST_MAKEFILE: &str = include_str!(concat!(
env!("CARGO_MANIFEST_DIR"),
"/templates/blendedAppFoundry/rust/Makefile"
));
const RUST_LIB_RS: &str = include_str!(concat!(
env!("CARGO_MANIFEST_DIR"),
"/templates/blendedAppFoundry/rust/lib.rs"
));
const RUST_TOOLCHAIN: &str = include_str!(concat!(
env!("CARGO_MANIFEST_DIR"),
"/templates/blendedAppFoundry/rust/rust-toolchain"
));

const SOLIDITY_GIT_IGNORE: &str = include_str!(concat!(
env!("CARGO_MANIFEST_DIR"),
"/templates/blendedAppFoundry/solidity/.gitignore"
));
const SOLIDITY_README: &str = include_str!(concat!(
env!("CARGO_MANIFEST_DIR"),
"/templates/blendedAppFoundry/solidity/README.md"
));
const SOLIDITY_FOUNDRY_TOML: &str = include_str!(concat!(
env!("CARGO_MANIFEST_DIR"),
"/templates/blendedAppFoundry/solidity/foundry.toml"
));

const SOLIDITY_GIT_WORKFLOW_TEST: &str = include_str!(concat!(
env!("CARGO_MANIFEST_DIR"),
"/templates/blendedAppFoundry/solidity/.github/workflows/test.yml"
));
const SOLIDITY_SOURCE_CONTRACT: &str = include_str!(concat!(
env!("CARGO_MANIFEST_DIR"),
"/templates/blendedAppFoundry/solidity/src/FluentSdkRustTypesTest.sol"
));
const SOLIDITY_SOURCE_CONSTRUCTOR: &str = include_str!(concat!(
env!("CARGO_MANIFEST_DIR"),
"/templates/blendedAppFoundry/solidity/src/deployConstructor/FluentSdkRustTypesTest.txt"
));
const SOLIDITY_TEST_CONTRACT: &str = include_str!(concat!(
env!("CARGO_MANIFEST_DIR"),
"/templates/blendedAppFoundry/solidity/test/FluentSdkRustTypesTest.t.sol"
));

const README: &str = include_str!(concat!(
env!("CARGO_MANIFEST_DIR"),
"/templates/blendedAppFoundry/README.md"
));
const GIT_MODULES: &str = include_str!(concat!(
env!("CARGO_MANIFEST_DIR"),
"/templates/blendedAppFoundry/.gitmodules"
));

// Create necessary directories and write files
create_directories("javascript")?;
create_directories("rust")?;
create_directories("solidity")?;

create_file_with_content("javascript/.gitignore", JAVASCRIPT_GIT_IGNORE)?;
create_file_with_content("javascript/package.json", JAVASCRIPT_PACKAGE_JSON)?;
create_file_with_content("javascript/solidity.js", JAVASCRIPT_SOLIDITY)?;
create_file_with_content("javascript/rust.js", JAVASCRIPT_RUST)?;

create_file_with_content("rust/.gitignore", RUST_GIT_IGNORE)?;
create_file_with_content("rust/Cargo.toml", RUST_CARGO_TOML)?;
create_file_with_content("rust/Makefile", RUST_MAKEFILE)?;
create_file_with_content("rust/lib.rs", RUST_LIB_RS)?;
create_file_with_content("rust/rust-toolchain", RUST_TOOLCHAIN)?;

create_file_with_content("solidity/.gitignore", SOLIDITY_GIT_IGNORE)?;
create_file_with_content("solidity/README.md", SOLIDITY_README)?;
create_file_with_content("solidity/foundry.toml", SOLIDITY_FOUNDRY_TOML)?;
create_file_with_content(
"solidity/.github/workflows/test.yml",
SOLIDITY_GIT_WORKFLOW_TEST,
)?;
create_file_with_content(
"solidity/src/FluentSdkRustTypesTest.sol",
SOLIDITY_SOURCE_CONTRACT,
)?;
create_file_with_content(
"solidity/src/deployConstructor/FluentSdkRustTypesTest.txt",
SOLIDITY_SOURCE_CONSTRUCTOR,
)?;
create_file_with_content(
"solidity/test/FluentSdkRustTypesTest.t.sol",
SOLIDITY_TEST_CONTRACT,
)?;

create_file_with_content("README.md", README)?;
create_file_with_content(".gitmodules", GIT_MODULES)?;

println!("Blended app with Foundry created successfully!");

Ok(())
}
54 changes: 26 additions & 28 deletions src/commands/rust/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,39 +117,37 @@ fn build_project(
if verbose {
println!(" ~ detected project name: {}", project_name)
}

let (target_dir, library_name) = if target_dir.is_none() {
let result = Command::new("cargo")
.arg("metadata")
.arg("--no-deps")
.output()
.map_err(|e| {
let (target_dir, library_name) = match target_dir {
None => {
let result = Command::new("cargo")
.arg("metadata")
.arg("--no-deps")
.output()
.map_err(|e| {
if verbose {
println!("Failed to get target directory: {:?}", e);
}
Error::Build("Failed to get target directory".to_string())
})?;
let utf8_string = from_utf8(&result.stdout).map_err(|e| {
if verbose {
println!("Failed to get target directory: {:?}", e);
println!("Failed to decode UTF-8 output: {:?}", e);
}
Error::Build("Failed to get target directory".to_string())
})?;
let utf8_string = from_utf8(&result.stdout).map_err(|e| {
if verbose {
println!("Failed to decode UTF-8 output: {:?}", e);
}
Error::Build("Failed to get target directory".to_string())
})?;
let json_value = json::parse(utf8_string).expect("can't parse json with manifest");
let package = json_value["packages"]
.members()
.find(|package| package["name"].to_string() == project_name)
.expect("can't find package in the manifest");
let library_name = package["targets"].members().find_map(|target| {
target["kind"]
let json_value = json::parse(utf8_string).expect("can't parse json with manifest");
let package = json_value["packages"]
.members()
.find(|lib| lib.to_string() == "cdylib")?;
Some(format!("{}.wasm", target["name"].to_string()))
});
let target_directory = json_value["target_directory"].to_string();
(target_directory, library_name)
} else {
(target_dir.unwrap(), None)
.find(|package| package["name"] == project_name)
.expect("can't find package in the manifest");
let library_name = package["targets"].members().find_map(|target| {
target["kind"].members().find(|lib| *lib == "cdylib")?;
Some(format!("{}.wasm", target["name"]))
});
let target_directory = json_value["target_directory"].to_string();
(target_directory, library_name)
}
Some(dir) => (dir, None),
};

let library_name =
Expand Down
2 changes: 1 addition & 1 deletion src/commands/rust/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ impl Tool {
Self::WasmTarget => Command::new("rustup")
.args(["target", "list", "--installed"])
.output()
.map_or(false, |output| {
.is_ok_and(|output| {
String::from_utf8_lossy(&output.stdout).contains("wasm32-unknown-unknown")
}),
Self::Wasm2Wat => Command::new(self.command())
Expand Down
3 changes: 3 additions & 0 deletions templates/blendedAppFoundry/.gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "solidity/lib/forge-std"]
path = solidity/lib/forge-std
url = https://github.com/foundry-rs/forge-std
Loading