Skip to content
Merged
Changes from 5 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
21 changes: 20 additions & 1 deletion cli/src/rust_template.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ use std::{
process::Stdio,
};

const ANCHOR_MSRV: &str = "1.89.0";

/// Program initialization template
#[derive(Clone, Debug, Default, Eq, PartialEq, Parser, ValueEnum)]
pub enum ProgramTemplate {
Expand All @@ -33,6 +35,7 @@ pub fn create_program(name: &str, template: ProgramTemplate, with_mollusk: bool)
let program_path = Path::new("programs").join(name);
let common_files = vec![
("Cargo.toml".into(), workspace_manifest().into()),
("rust-toolchain.toml".into(), rust_toolchain_toml()),
(
program_path.join("Cargo.toml"),
cargo_toml(name, with_mollusk),
Expand All @@ -48,6 +51,18 @@ pub fn create_program(name: &str, template: ProgramTemplate, with_mollusk: bool)
create_files(&[common_files, template_files].concat())
}

/// Helper to create a rust-toolchain.toml at the workspace root
fn rust_toolchain_toml() -> String {
format!(
r#"[toolchain]
channel = "{msrv}"
components = ["rustfmt","clippy"]
profile = "minimal"
"#,
msrv = ANCHOR_MSRV
)
}

/// Create a program with a single `lib.rs` file.
fn create_program_template_single(name: &str, program_path: &Path) -> Files {
vec![(
Expand Down Expand Up @@ -748,11 +763,15 @@ name = "tests"
version = "0.1.0"
description = "Created with Anchor"
edition = "2021"
rust-version = "{msrv}"

[dependencies]
anchor-client = "{VERSION}"
anchor-client = "{version}"
{name} = {{ version = "0.1.0", path = "../programs/{name}" }}
"#,
msrv = ANCHOR_MSRV,
version = VERSION,
name = name,
)
}

Expand Down