diff --git a/stylus-tools/Cargo.toml b/stylus-tools/Cargo.toml index ebf3c7da..92d0d3f9 100644 --- a/stylus-tools/Cargo.toml +++ b/stylus-tools/Cargo.toml @@ -10,6 +10,12 @@ license.workspace = true repository.workspace = true version.workspace = true +include = [ + "src/**/*", + "precompiles/*.sol", + "templates/**", +] + [dependencies] alloy = { workspace = true, features = ["contract", "getrandom", "rpc-types", "signer-local", "sol-types"] } cargo-util-schemas.workspace = true diff --git a/stylus-tools/src/core/project/init.rs b/stylus-tools/src/core/project/init.rs index f01b8ed8..364154ac 100644 --- a/stylus-tools/src/core/project/init.rs +++ b/stylus-tools/src/core/project/init.rs @@ -43,7 +43,7 @@ pub fn init_contract(path: impl AsRef) -> Result<(), InitError> { // Add files from template copy_from_template_if_dne!( - "../../templates/contract" -> path, + "templates/contract" -> path, "src/lib.rs", "src/main.rs", "rust-toolchain.toml", @@ -67,8 +67,8 @@ pub fn init_workspace(path: impl AsRef) -> Result<(), InitError> { // Add files from template copy_from_template_if_dne!( - "../../templates/workspace" -> path, - "Cargo.toml", + "templates/workspace" -> path, + "Cargo.toml.tmpl", "rust-toolchain.toml", "Stylus.toml", ); diff --git a/stylus-tools/src/core/project/new.rs b/stylus-tools/src/core/project/new.rs index b17fc151..b5170d8c 100644 --- a/stylus-tools/src/core/project/new.rs +++ b/stylus-tools/src/core/project/new.rs @@ -22,7 +22,7 @@ pub fn new_contract(path: impl AsRef) -> Result<(), InitError> { // Remove the generated "src/lib.rs" and generate the new one fs::remove_file(path.join("src").join("lib.rs"))?; copy_from_template_if_dne!( - "../../templates/contract" -> path, + "templates/contract" -> path, "src/lib.rs", ); diff --git a/stylus-tools/src/macros.rs b/stylus-tools/src/macros.rs index 3bdfa6ab..8b9dfd3a 100644 --- a/stylus-tools/src/macros.rs +++ b/stylus-tools/src/macros.rs @@ -4,9 +4,13 @@ macro_rules! copy_from_template { ($tmpl:literal -> $root:ident, $($files:expr),* $(,)?) => { $( + let mut filename = $root.join($files); + if filename.extension() == Some(std::ffi::OsStr::new("tmpl")) { + filename = filename.file_stem().unwrap().into(); + } std::fs::write( - $root.join($files), - include_str!(concat!($tmpl, "/", $files)), + filename, + include_str!(concat!(env!("CARGO_MANIFEST_DIR"), "/", $tmpl, "/", $files)), )?; )* }; diff --git a/stylus-tools/src/templates/contract/Cargo.toml b/stylus-tools/src/templates/contract/Cargo.toml deleted file mode 100644 index f54b7475..00000000 --- a/stylus-tools/src/templates/contract/Cargo.toml +++ /dev/null @@ -1,34 +0,0 @@ -[dependencies] -alloy-primitives = "=0.8.20" -alloy-sol-types = "=0.8.20" -mini-alloc = "0.8.4" -stylus-sdk = "0.8.4" -hex = "0.4.3" -dotenv = "0.15.0" - -[dev-dependencies] -tokio = { version = "1.12.0", features = ["full"] } -ethers = "2.0" -eyre = "0.6.8" -stylus-sdk = { version = "0.8.4", features = ["stylus-test"] } - -[features] -export-abi = ["stylus-sdk/export-abi"] -debug = ["stylus-sdk/debug"] -contract-client-gen = [] - -[[bin]] -name = "stylus-hello-world" -path = "src/main.rs" - -[lib] -crate-type = ["lib", "cdylib"] - -[profile.release] -codegen-units = 1 -strip = true -lto = true -panic = "abort" -# If you need to reduce the binary size, it is advisable to try other -# optimization levels, such as "s" and "z" -opt-level = 3 diff --git a/stylus-tools/src/templates/contract/Stylus.toml b/stylus-tools/templates/contract/Stylus.toml similarity index 100% rename from stylus-tools/src/templates/contract/Stylus.toml rename to stylus-tools/templates/contract/Stylus.toml diff --git a/stylus-tools/src/templates/contract/rust-toolchain.toml b/stylus-tools/templates/contract/rust-toolchain.toml similarity index 100% rename from stylus-tools/src/templates/contract/rust-toolchain.toml rename to stylus-tools/templates/contract/rust-toolchain.toml diff --git a/stylus-tools/src/templates/contract/src/lib.rs b/stylus-tools/templates/contract/src/lib.rs similarity index 100% rename from stylus-tools/src/templates/contract/src/lib.rs rename to stylus-tools/templates/contract/src/lib.rs diff --git a/stylus-tools/src/templates/contract/src/main.rs b/stylus-tools/templates/contract/src/main.rs similarity index 100% rename from stylus-tools/src/templates/contract/src/main.rs rename to stylus-tools/templates/contract/src/main.rs diff --git a/stylus-tools/src/templates/workspace/Cargo.toml b/stylus-tools/templates/workspace/Cargo.toml.tmpl similarity index 100% rename from stylus-tools/src/templates/workspace/Cargo.toml rename to stylus-tools/templates/workspace/Cargo.toml.tmpl diff --git a/stylus-tools/src/templates/workspace/Stylus.toml b/stylus-tools/templates/workspace/Stylus.toml similarity index 100% rename from stylus-tools/src/templates/workspace/Stylus.toml rename to stylus-tools/templates/workspace/Stylus.toml diff --git a/stylus-tools/src/templates/workspace/rust-toolchain.toml b/stylus-tools/templates/workspace/rust-toolchain.toml similarity index 100% rename from stylus-tools/src/templates/workspace/rust-toolchain.toml rename to stylus-tools/templates/workspace/rust-toolchain.toml