Skip to content

Commit 31578a7

Browse files
committed
feat(templates): add Makefile and rust-toolchain to rust templates
1 parent 1e62a79 commit 31578a7

File tree

7 files changed

+55
-1
lines changed

7 files changed

+55
-1
lines changed

src/commands/legacy_init.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,10 +157,20 @@ fn spin_rust() -> Result<()> {
157157
env!("CARGO_MANIFEST_DIR"),
158158
"/templates/rust-template/gitignore.txt"
159159
));
160+
const MAKE: &str = include_str!(concat!(
161+
env!("CARGO_MANIFEST_DIR"),
162+
"/templates/rust-template/Makefile"
163+
));
164+
const RUST_TOOLCHAIN: &str = include_str!(concat!(
165+
env!("CARGO_MANIFEST_DIR"),
166+
"/templates/rust-template/rust-toolchain"
167+
));
160168

161169
create_file_with_content("lib.rs", LIB)?;
162170
create_file_with_content("Cargo.toml", CARGO)?;
163171
create_file_with_content(".gitignore", GIT_IG)?;
172+
create_file_with_content("Makefile", MAKE)?;
173+
create_file_with_content("rust-toolchain", RUST_TOOLCHAIN)?;
164174

165175
println!("Rust template created sucessfully");
166176

@@ -265,6 +275,14 @@ fn spin_blended_app() -> Result<()> {
265275
env!("CARGO_MANIFEST_DIR"),
266276
"/templates/blendedapp/greeting/Cargo.toml.txt"
267277
));
278+
const MAKEFILE: &str = include_str!(concat!(
279+
env!("CARGO_MANIFEST_DIR"),
280+
"/templates/blendedapp/greeting/Makefile"
281+
));
282+
const RUST_TOOLCHAIN: &str = include_str!(concat!(
283+
env!("CARGO_MANIFEST_DIR"),
284+
"/templates/blendedapp/greeting/rust-toolchain"
285+
));
268286

269287
const GREETING_SC: &str = include_str!(concat!(
270288
env!("CARGO_MANIFEST_DIR"),
@@ -287,6 +305,7 @@ fn spin_blended_app() -> Result<()> {
287305
env!("CARGO_MANIFEST_DIR"),
288306
"/templates/blendedapp/.env"
289307
));
308+
290309
// Create necessary directories and write files
291310
create_directories("contracts")?;
292311
create_directories("tasks")?;
@@ -302,6 +321,8 @@ fn spin_blended_app() -> Result<()> {
302321
create_file_with_content("deploy/00_deploy_contracts.ts", DEPLOYMENT_SCRIPT)?;
303322

304323
create_file_with_content("greeting/Cargo.toml", CARGO_TOML)?;
324+
create_file_with_content("greeting/Makefile", MAKEFILE)?;
325+
create_file_with_content("greeting/rust-toolchain", RUST_TOOLCHAIN)?;
305326
create_file_with_content("greeting/src/lib.rs", LIB)?;
306327
create_file_with_content("README.md", README)?;
307328
create_file_with_content(".env", ENV)?;

src/commands/rust/constants.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,3 +60,13 @@ mod tests {
6060
}
6161
}
6262
"#;
63+
64+
pub const BASIC_TEMPLATE_MAKEFILE: &str = r#"RUSTFLAGS='-C link-arg=-zstack-size=262144 -C target-feature=+bulk-memory'
65+
66+
.PHONY: lib.wasm
67+
lib.wasm: lib.rs Cargo.toml
68+
RUSTFLAGS=$(RUSTFLAGS) cargo build --release --target=wasm32-unknown-unknown --no-default-features --features=""
69+
cp ./target/wasm32-unknown-unknown/release/*.wasm ./lib.wasm
70+
wasm2wat ./lib.wasm > ./lib.wat || true"#;
71+
72+
pub const BASIC_TEMPLATE_RUST_TOOLCHAIN: &str = r#"nightly"#;

src/commands/rust/init.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,15 @@ fn create_default_template(project_path: &PathBuf) -> Result<(), Error> {
9191
.map_err(|e| Error::InitializationError(format!("Failed to create Cargo.toml: {}", e)))?;
9292

9393
std::fs::write(project_path.join("lib.rs"), BASIC_TEMPLATE_LIB_RS)
94-
.map_err(|e| Error::InitializationError(format!("Failed to create lib.rs: {}", e)))?;
9594

95+
std::fs::write(project_path.join("Makefile"), BASIC_TEMPLATE_MAKEFILE)
96+
.map_err(|e| Error::Initialization(format!("Failed to create Makefile: {}", e)))?;
97+
98+
std::fs::write(
99+
project_path.join("rust-toolchain"),
100+
BASIC_TEMPLATE_RUST_TOOLCHAIN,
101+
)
102+
.map_err(|e| Error::Initialization(format!("Failed to create rust-toolchain: {}", e)))?;
96103
Ok(())
97104
}
98105

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
RUSTFLAGS='-C link-arg=-zstack-size=262144 -C target-feature=+bulk-memory'
2+
3+
.PHONY: lib.wasm
4+
lib.wasm: lib.rs Cargo.toml
5+
RUSTFLAGS=$(RUSTFLAGS) cargo build --release --target=wasm32-unknown-unknown --no-default-features --features=""
6+
cp ./target/wasm32-unknown-unknown/release/*.wasm ./lib.wasm
7+
wasm2wat ./lib.wasm > ./lib.wat || true
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
nightly

templates/rust-template/Makefile

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
RUSTFLAGS='-C link-arg=-zstack-size=262144 -C target-feature=+bulk-memory'
2+
3+
.PHONY: lib.wasm
4+
lib.wasm: lib.rs Cargo.toml
5+
RUSTFLAGS=$(RUSTFLAGS) cargo build --release --target=wasm32-unknown-unknown --no-default-features --features=""
6+
cp ./target/wasm32-unknown-unknown/release/*.wasm ./lib.wasm
7+
wasm2wat ./lib.wasm > ./lib.wat || true
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
nightly

0 commit comments

Comments
 (0)