Skip to content

Commit 7a25135

Browse files
committed
Add proto settings.
1 parent d7fdae6 commit 7a25135

19 files changed

Lines changed: 163 additions & 80 deletions

File tree

crates/action-graph/src/action_graph_builder.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -906,7 +906,10 @@ impl<'query> ActionGraphBuilder<'query> {
906906
}
907907

908908
pub async fn setup_proto(&mut self) -> miette::Result<Option<NodeIndex>> {
909-
let index = insert_node_or_exit!(self, ActionNode::setup_proto());
909+
let index = insert_node_or_exit!(
910+
self,
911+
ActionNode::setup_proto(self.app_context.toolchain_config.proto.version.clone())
912+
);
910913

911914
Ok(Some(index))
912915
}

crates/action-graph/tests/action_graph_builder_test.rs

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use moon_affected::AffectedBy;
77
use moon_common::{Id, path::WorkspaceRelativePathBuf};
88
use moon_config::{
99
PipelineActionSwitch, SemVer, TaskArgs, TaskDependencyConfig, TaskOptionRunInCI,
10-
UnresolvedVersionSpec, Version,
10+
UnresolvedVersionSpec, Version, VersionSpec,
1111
};
1212
use moon_platform::{Runtime, RuntimeReq, ToolchainSpec};
1313
use moon_task::{Target, TargetLocator, Task, TaskFileInput};
@@ -24,6 +24,10 @@ fn create_task(project: &str, id: &str) -> Task {
2424
}
2525
}
2626

27+
fn create_proto_version() -> VersionSpec {
28+
VersionSpec::parse("0.51.4").unwrap()
29+
}
30+
2731
fn create_unresolved_version(version: Version) -> UnresolvedVersionSpec {
2832
UnresolvedVersionSpec::Semantic(SemVer(version))
2933
}
@@ -122,7 +126,7 @@ mod action_graph_builder {
122126
topo(graph),
123127
vec![
124128
ActionNode::sync_workspace(),
125-
ActionNode::setup_proto(),
129+
ActionNode::setup_proto(create_proto_version()),
126130
ActionNode::setup_toolchain_legacy(SetupToolchainLegacyNode {
127131
runtime: runtime.clone(),
128132
}),
@@ -164,7 +168,7 @@ mod action_graph_builder {
164168
topo(graph),
165169
vec![
166170
ActionNode::sync_workspace(),
167-
ActionNode::setup_proto(),
171+
ActionNode::setup_proto(create_proto_version()),
168172
ActionNode::setup_toolchain_legacy(SetupToolchainLegacyNode {
169173
runtime: runtime.clone(),
170174
}),
@@ -205,7 +209,7 @@ mod action_graph_builder {
205209
topo(graph),
206210
vec![
207211
ActionNode::sync_workspace(),
208-
ActionNode::setup_proto(),
212+
ActionNode::setup_proto(create_proto_version()),
209213
ActionNode::setup_toolchain_legacy(SetupToolchainLegacyNode {
210214
runtime: runtime.clone(),
211215
}),
@@ -260,7 +264,7 @@ mod action_graph_builder {
260264
runtime: node.clone(),
261265
root: WorkspaceRelativePathBuf::new(),
262266
}),
263-
ActionNode::setup_proto(),
267+
ActionNode::setup_proto(create_proto_version()),
264268
ActionNode::setup_toolchain_legacy(SetupToolchainLegacyNode {
265269
runtime: bun.clone(),
266270
}),
@@ -286,7 +290,7 @@ mod action_graph_builder {
286290
topo(graph),
287291
vec![
288292
ActionNode::sync_workspace(),
289-
ActionNode::setup_proto(),
293+
ActionNode::setup_proto(create_proto_version()),
290294
ActionNode::setup_toolchain_legacy(SetupToolchainLegacyNode { runtime: bun }),
291295
ActionNode::setup_toolchain_legacy(SetupToolchainLegacyNode {
292296
runtime: node.clone()
@@ -390,7 +394,7 @@ mod action_graph_builder {
390394
topo(graph),
391395
vec![
392396
ActionNode::sync_workspace(),
393-
ActionNode::setup_proto(),
397+
ActionNode::setup_proto(create_proto_version()),
394398
ActionNode::setup_toolchain_legacy(SetupToolchainLegacyNode {
395399
runtime: create_node_runtime()
396400
}),
@@ -475,7 +479,7 @@ mod action_graph_builder {
475479
topo(graph),
476480
vec![
477481
ActionNode::sync_workspace(),
478-
ActionNode::setup_proto(),
482+
ActionNode::setup_proto(create_proto_version()),
479483
ActionNode::setup_toolchain(SetupToolchainNode {
480484
toolchain: spec.clone()
481485
}),
@@ -2446,7 +2450,7 @@ mod action_graph_builder {
24462450
topo(graph),
24472451
vec![
24482452
ActionNode::sync_workspace(),
2449-
ActionNode::setup_proto(),
2453+
ActionNode::setup_proto(create_proto_version()),
24502454
ActionNode::setup_toolchain_legacy(SetupToolchainLegacyNode { runtime: node }),
24512455
]
24522456
);
@@ -2488,7 +2492,7 @@ mod action_graph_builder {
24882492
topo(graph),
24892493
vec![
24902494
ActionNode::sync_workspace(),
2491-
ActionNode::setup_proto(),
2495+
ActionNode::setup_proto(create_proto_version()),
24922496
ActionNode::setup_toolchain_legacy(SetupToolchainLegacyNode { runtime: node1 }),
24932497
ActionNode::setup_toolchain_legacy(SetupToolchainLegacyNode { runtime: node2 }),
24942498
ActionNode::setup_toolchain_legacy(SetupToolchainLegacyNode { runtime: node3 }),
@@ -2515,7 +2519,7 @@ mod action_graph_builder {
25152519
topo(graph),
25162520
vec![
25172521
ActionNode::sync_workspace(),
2518-
ActionNode::setup_proto(),
2522+
ActionNode::setup_proto(create_proto_version()),
25192523
ActionNode::setup_toolchain_legacy(SetupToolchainLegacyNode { runtime: node }),
25202524
]
25212525
);
@@ -2618,7 +2622,7 @@ mod action_graph_builder {
26182622
topo(graph),
26192623
vec![
26202624
ActionNode::sync_workspace(),
2621-
ActionNode::setup_proto(),
2625+
ActionNode::setup_proto(create_proto_version()),
26222626
ActionNode::setup_toolchain_legacy(SetupToolchainLegacyNode { runtime: node }),
26232627
]
26242628
);
@@ -2688,7 +2692,7 @@ mod action_graph_builder {
26882692
topo(graph),
26892693
vec![
26902694
ActionNode::sync_workspace(),
2691-
ActionNode::setup_proto(),
2695+
ActionNode::setup_proto(create_proto_version()),
26922696
ActionNode::setup_toolchain(SetupToolchainNode { toolchain: node }),
26932697
]
26942698
);
@@ -2727,7 +2731,7 @@ mod action_graph_builder {
27272731
topo(graph),
27282732
vec![
27292733
ActionNode::sync_workspace(),
2730-
ActionNode::setup_proto(),
2734+
ActionNode::setup_proto(create_proto_version()),
27312735
ActionNode::setup_toolchain(SetupToolchainNode { toolchain: node1 }),
27322736
ActionNode::setup_toolchain(SetupToolchainNode { toolchain: node2 }),
27332737
ActionNode::setup_toolchain(SetupToolchainNode { toolchain: node3 }),
@@ -2754,7 +2758,7 @@ mod action_graph_builder {
27542758
topo(graph),
27552759
vec![
27562760
ActionNode::sync_workspace(),
2757-
ActionNode::setup_proto(),
2761+
ActionNode::setup_proto(create_proto_version()),
27582762
ActionNode::setup_toolchain(SetupToolchainNode { toolchain: node }),
27592763
]
27602764
);
@@ -2857,7 +2861,7 @@ mod action_graph_builder {
28572861
topo(graph),
28582862
vec![
28592863
ActionNode::sync_workspace(),
2860-
ActionNode::setup_proto(),
2864+
ActionNode::setup_proto(create_proto_version()),
28612865
ActionNode::setup_toolchain(SetupToolchainNode { toolchain: node }),
28622866
]
28632867
);

crates/action/src/action_node.rs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
use moon_common::consts::PROTO_CLI_VERSION;
21
use moon_common::path::WorkspaceRelativePathBuf;
32
use moon_common::{Id, is_test_env};
43
use moon_target::Target;
5-
use moon_toolchain::{Runtime, ToolchainSpec};
4+
use moon_toolchain::{Runtime, ToolchainSpec, VersionSpec};
65
use rustc_hash::{FxHashMap, FxHasher};
76
use serde::Serialize;
87
use std::hash::{Hash, Hasher};
@@ -48,7 +47,9 @@ pub struct SetupEnvironmentNode {
4847
}
4948

5049
#[derive(Clone, Debug, Eq, Hash, PartialEq, Serialize)]
51-
pub struct SetupProtoNode {}
50+
pub struct SetupProtoNode {
51+
pub version: VersionSpec,
52+
}
5253

5354
// DEPRECATED
5455
#[derive(Clone, Debug, Eq, Hash, PartialEq, Serialize)]
@@ -169,8 +170,8 @@ impl ActionNode {
169170
Self::SetupEnvironment(Box::new(node))
170171
}
171172

172-
pub fn setup_proto() -> Self {
173-
Self::SetupProto(Box::new(SetupProtoNode {}))
173+
pub fn setup_proto(version: VersionSpec) -> Self {
174+
Self::SetupProto(Box::new(SetupProtoNode { version }))
174175
}
175176

176177
pub fn setup_toolchain_legacy(node: SetupToolchainLegacyNode) -> Self {
@@ -291,13 +292,13 @@ impl ActionNode {
291292
format!("SetupEnvironment({}, {})", inner.toolchain_id, inner.root)
292293
}
293294
}
294-
Self::SetupProto(_) => {
295+
Self::SetupProto(inner) => {
295296
format!(
296297
"SetupProto({})",
297298
if is_test_env() {
298-
"1.2.3"
299+
"1.2.3".to_string()
299300
} else {
300-
PROTO_CLI_VERSION
301+
inner.version.to_string()
301302
}
302303
)
303304
}

crates/actions/src/actions/setup_proto.rs

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
use moon_action::{Action, ActionStatus};
22
use moon_action_context::ActionContext;
33
use moon_app_context::AppContext;
4-
use moon_common::consts::PROTO_CLI_VERSION;
54
use moon_common::is_test_env;
65
use moon_common::path::exe_name;
76
use moon_console::Checkpoint;
87
use moon_env_var::GlobalEnvBag;
98
use moon_platform::is_using_global_toolchains;
109
use proto_core::flow::install::{InstallOptions, ProtoInstallError};
11-
use proto_core::{Id, ToolSpec, UnresolvedVersionSpec, is_offline, load_tool_from_locator};
10+
use proto_core::{Id, ToolSpec, is_offline, load_tool_from_locator};
1211
use std::sync::Arc;
1312
use tracing::{debug, instrument};
1413

@@ -19,18 +18,19 @@ pub async fn setup_proto(
1918
app_context: Arc<AppContext>,
2019
) -> miette::Result<ActionStatus> {
2120
let bin_name = exe_name("proto");
21+
let proto_version = app_context.toolchain_config.proto.version.to_string();
2222
let install_dir = app_context
2323
.proto_env
2424
.store
2525
.inventory_dir
2626
.join("proto")
27-
.join(PROTO_CLI_VERSION);
27+
.join(&proto_version);
2828

2929
debug!(proto = ?install_dir.join(&bin_name), "Checking if proto is installed");
3030

3131
// Set the version so that proto lookup paths take it into account
3232
let bag = GlobalEnvBag::instance();
33-
bag.set("PROTO_VERSION", PROTO_CLI_VERSION);
33+
bag.set("PROTO_VERSION", &proto_version);
3434
bag.set("PROTO_IGNORE_MIGRATE_WARNING", "true");
3535
bag.set("PROTO_VERSION_CHECK", "false");
3636
bag.set("PROTO_LOOKUP_DIR", &install_dir);
@@ -72,7 +72,7 @@ pub async fn setup_proto(
7272

7373
app_context.console.print_checkpoint(
7474
Checkpoint::Setup,
75-
format!("installing proto {PROTO_CLI_VERSION}"),
75+
format!("installing proto {proto_version}"),
7676
)?;
7777

7878
// Load the built-in proto tool
@@ -84,7 +84,13 @@ pub async fn setup_proto(
8484
.await?;
8585

8686
// Install using proto itself
87-
let spec = ToolSpec::new(UnresolvedVersionSpec::parse(PROTO_CLI_VERSION).unwrap());
87+
let spec = ToolSpec::new(
88+
app_context
89+
.toolchain_config
90+
.proto
91+
.version
92+
.to_unresolved_spec(),
93+
);
8894

8995
if tool.is_setup(&spec).await? {
9096
return Ok(ActionStatus::Skipped);

crates/app/src/session.rs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -179,11 +179,14 @@ impl MoonSession {
179179

180180
pub async fn get_toolchain_registry(&self) -> miette::Result<Arc<ToolchainRegistry>> {
181181
let item = self.toolchain_registry.get_or_init(|| {
182-
let mut registry = ToolchainRegistry::new(PluginHostData {
183-
moon_env: Arc::clone(&self.moon_env),
184-
proto_env: Arc::clone(&self.proto_env),
185-
workspace_graph: Arc::new(OnceLock::new()),
186-
});
182+
let mut registry = ToolchainRegistry::new(
183+
PluginHostData {
184+
moon_env: Arc::clone(&self.moon_env),
185+
proto_env: Arc::clone(&self.proto_env),
186+
workspace_graph: Arc::new(OnceLock::new()),
187+
},
188+
self.toolchain_config.clone(),
189+
);
187190

188191
registry.inherit_configs(&self.toolchain_config.plugins);
189192

crates/app/src/systems/startup.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,8 @@ pub async fn load_toolchain_config(
143143
.await
144144
.into_diagnostic()??;
145145

146+
GlobalEnvBag::instance().set("PROTO_CLI_VERSION", config.proto.version.to_string());
147+
146148
Ok(Arc::new(config))
147149
}
148150

crates/common/src/consts.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,3 @@ pub const BIN_NAME: &str = "moon.exe";
55
pub const BIN_NAME: &str = "moon";
66

77
pub const CONFIG_DIRNAME: &str = ".moon";
8-
9-
pub const PROTO_CLI_VERSION: &str = "0.51.4";

crates/config/src/toolchain/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ mod deno_config;
44
mod moon_config;
55
mod node_config;
66
mod plugin_config;
7+
mod proto_config;
78
mod python_config;
89
mod rust_config;
910

@@ -13,6 +14,7 @@ pub use deno_config::*;
1314
pub use moon_config::*;
1415
pub use node_config::*;
1516
pub use plugin_config::*;
17+
pub use proto_config::*;
1618
pub use python_config::*;
1719
pub use rust_config::*;
1820

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
use crate::config_struct;
2+
use schematic::{Config, DefaultValueResult};
3+
use version_spec::VersionSpec;
4+
5+
fn default_version(_: &()) -> DefaultValueResult<VersionSpec> {
6+
Ok(VersionSpec::parse("0.51.4").ok())
7+
}
8+
9+
config_struct!(
10+
/// Configures how moon integrates with proto.
11+
#[derive(Config)]
12+
pub struct ProtoConfig {
13+
/// The version of proto to download and install,
14+
/// and to use for installing and running other toolchains.
15+
#[setting(default = default_version)]
16+
pub version: VersionSpec,
17+
}
18+
);

crates/config/src/toolchain_config.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,10 @@ config_struct!(
4242
#[setting(nested)]
4343
pub node: Option<NodeConfig>,
4444

45+
/// Configures how moon integrates with proto.
46+
#[setting(nested)]
47+
pub proto: ProtoConfig,
48+
4549
/// Configures and enables the Python platform.
4650
#[setting(nested)]
4751
pub python: Option<PythonConfig>,

0 commit comments

Comments
 (0)