Skip to content

Commit

Permalink
Update deno and rust.
Browse files Browse the repository at this point in the history
  • Loading branch information
milesj committed Sep 20, 2023
1 parent 4fb3801 commit 7071c1f
Show file tree
Hide file tree
Showing 13 changed files with 88 additions and 66 deletions.
8 changes: 4 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions crates/core/dep-graph/src/dep_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,8 @@ impl<'ws> DepGraphBuilder<'ws> {
return pair.clone();
}

let mut project_runtime = Runtime::System;
let mut workspace_runtime = Runtime::System;
let mut project_runtime = Runtime::system();
let mut workspace_runtime = Runtime::system();

if let Some(platform) = PlatformManager::read().find(|p| match task {
Some(task) => p.matches(&task.platform, None),
Expand Down
2 changes: 1 addition & 1 deletion crates/core/emitter/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ harness = false
[dependencies]
moon_action = { path = "../action" }
moon_action_context = { path = "../action-context" }
moon_platform_runtime = { path = "../platform-runtime" }
moon_platform_runtime2 = { path = "../../../nextgen/platform-runtime" }
moon_project = { path = "../../../nextgen/project" }
moon_target = { path = "../../../nextgen/target" }
moon_task = { path = "../../../nextgen/task" }
Expand Down
2 changes: 1 addition & 1 deletion crates/core/emitter/src/event.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use moon_action::{Action, ActionNode};
use moon_action_context::ActionContext;
use moon_platform_runtime::Runtime;
use moon_platform_runtime2::Runtime;
use moon_project::Project;
use moon_target::Target;
use moon_task::Task;
Expand Down
2 changes: 1 addition & 1 deletion crates/core/runner/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ moon_emitter = { path = "../emitter" }
moon_hash = { path = "../../../nextgen/hash" }
moon_logger = { path = "../logger" }
moon_platform = { path = "../platform" }
moon_platform_runtime = { path = "../platform-runtime" }
moon_platform_runtime2 = { path = "../../../nextgen/platform-runtime" }
moon_process = { path = "../../../nextgen/process" }
moon_project = { path = "../../../nextgen/project" }
moon_target = { path = "../../../nextgen/target" }
Expand Down
2 changes: 1 addition & 1 deletion crates/core/runner/src/runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use moon_emitter::{Emitter, Event, EventFlow};
use moon_hash::ContentHasher;
use moon_logger::{debug, warn};
use moon_platform::PlatformManager;
use moon_platform_runtime::Runtime;
use moon_platform_runtime2::Runtime;
use moon_process::{args, output_to_error, output_to_string, Command, Output};
use moon_project::Project;
use moon_target::{TargetError, TargetScope};
Expand Down
38 changes: 17 additions & 21 deletions crates/deno/platform/src/platform.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use moon_deno_lang::{load_lockfile_dependencies, DenoJson, DENO_DEPS};
use moon_deno_tool::DenoTool;
use moon_hash::ContentHasher;
use moon_logger::{debug, map_list};
use moon_platform::{Platform, Runtime, Version};
use moon_platform::{Platform, Runtime, RuntimeReq};
use moon_process::Command;
use moon_project::Project;
use moon_task::Task;
Expand Down Expand Up @@ -51,7 +51,7 @@ impl DenoPlatform {
DenoPlatform {
config: config.to_owned(),
proto_env,
toolchain: ToolManager::new(Runtime::Deno(Version::new_global())),
toolchain: ToolManager::new(Runtime::new(PlatformType::Deno, RuntimeReq::Global)),
typescript_config: typescript_config.to_owned(),
workspace_root: workspace_root.to_path_buf(),
}
Expand All @@ -65,7 +65,7 @@ impl Platform for DenoPlatform {
}

fn get_runtime_from_config(&self, _project_config: Option<&ProjectConfig>) -> Runtime {
Runtime::Deno(Version::new_global())
Runtime::new(PlatformType::Deno, RuntimeReq::Global)
}

fn matches(&self, platform: &PlatformType, runtime: Option<&Runtime>) -> bool {
Expand All @@ -74,7 +74,7 @@ impl Platform for DenoPlatform {
}

if let Some(runtime) = &runtime {
return matches!(runtime, Runtime::Deno(_));
return matches!(runtime.platform, PlatformType::Deno);
}

false
Expand Down Expand Up @@ -104,8 +104,8 @@ impl Platform for DenoPlatform {
Ok(Box::new(tool))
}

fn get_tool_for_version(&self, version: Version) -> miette::Result<Box<&dyn Tool>> {
let tool = self.toolchain.get_for_version(&version)?;
fn get_tool_for_version(&self, req: RuntimeReq) -> miette::Result<Box<&dyn Tool>> {
let tool = self.toolchain.get_for_version(&req)?;

Ok(Box::new(tool))
}
Expand All @@ -123,17 +123,15 @@ impl Platform for DenoPlatform {
// None => Version::new_global(),
// };

let version = Version::new_global();
let req = RuntimeReq::Global;
let mut last_versions = FxHashMap::default();

if !self.toolchain.has(&version) {
self.toolchain.register(
&version,
DenoTool::new(&self.proto_env, &self.config, &version)?,
);
if !self.toolchain.has(&req) {
self.toolchain
.register(&req, DenoTool::new(&self.proto_env, &self.config, &req)?);
}

self.toolchain.setup(&version, &mut last_versions).await?;
self.toolchain.setup(&req, &mut last_versions).await?;

Ok(())
}
Expand All @@ -152,16 +150,14 @@ impl Platform for DenoPlatform {
runtime: &Runtime,
last_versions: &mut FxHashMap<String, SemVersion>,
) -> miette::Result<u8> {
let version = runtime.version();
let req = &runtime.requirement;

if !self.toolchain.has(&version) {
self.toolchain.register(
&version,
DenoTool::new(&self.proto_env, &self.config, &version)?,
);
if !self.toolchain.has(req) {
self.toolchain
.register(req, DenoTool::new(&self.proto_env, &self.config, req)?);
}

Ok(self.toolchain.setup(&version, last_versions).await?)
Ok(self.toolchain.setup(req, last_versions).await?)
}

async fn install_deps(
Expand All @@ -174,7 +170,7 @@ impl Platform for DenoPlatform {
return Ok(());
}

let tool = self.toolchain.get_for_version(runtime.version())?;
let tool = self.toolchain.get_for_version(&runtime.requirement)?;

debug!(target: LOG_TARGET, "Installing dependencies");

Expand Down
2 changes: 1 addition & 1 deletion crates/deno/tool/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ publish = false

[dependencies]
moon_config = { path = "../../../nextgen/config" }
moon_platform_runtime = { path = "../../core/platform-runtime" }
moon_platform_runtime2 = { path = "../../../nextgen/platform-runtime" }
moon_tool = { path = "../../core/tool" }
miette = { workspace = true }
proto_core = { workspace = true }
Expand Down
6 changes: 3 additions & 3 deletions crates/deno/tool/src/deno_tool.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use moon_config::DenoConfig;
use moon_platform_runtime::Version;
use moon_platform_runtime2::RuntimeReq;
use moon_tool::{async_trait, Tool};
use proto_core::ProtoEnvironment;
use std::path::PathBuf;
Expand All @@ -15,14 +15,14 @@ impl DenoTool {
pub fn new(
_proto: &ProtoEnvironment,
config: &DenoConfig,
version: &Version,
req: &RuntimeReq,
) -> miette::Result<DenoTool> {
let mut deno = DenoTool {
config: config.to_owned(),
global: true,
};

if version.is_global() {
if req.is_global() {
deno.global = true;
// node.config.version = None;
} else {
Expand Down
46 changes: 25 additions & 21 deletions crates/rust/platform/src/rust_platform.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ use moon_action_context::ActionContext;
use moon_common::{is_ci, Id};
use moon_config::{
BinEntry, HasherConfig, PlatformType, ProjectConfig, ProjectsAliasesMap, ProjectsSourcesMap,
RustConfig,
RustConfig, VersionSpec,
};
use moon_hash::ContentHasher;
use moon_logger::{debug, map_list};
use moon_platform::{Platform, Runtime, Version};
use moon_platform::{Platform, Runtime, RuntimeReq};
use moon_process::Command;
use moon_project::Project;
use moon_rust_lang::{
Expand Down Expand Up @@ -55,7 +55,7 @@ impl RustPlatform {
RustPlatform {
config: config.to_owned(),
proto_env,
toolchain: ToolManager::new(Runtime::Rust(Version::new_global())),
toolchain: ToolManager::new(Runtime::new(PlatformType::Rust, RuntimeReq::Global)),
workspace_root: workspace_root.to_path_buf(),
}
}
Expand All @@ -71,16 +71,22 @@ impl Platform for RustPlatform {
if let Some(config) = &project_config {
if let Some(rust_config) = &config.toolchain.rust {
if let Some(version) = &rust_config.version {
return Runtime::Rust(Version::new_override(version.to_string()));
return Runtime::new(
PlatformType::Rust,
RuntimeReq::ToolchainOverride(VersionSpec::Version(version.to_owned())),
);
}
}
}

if let Some(version) = &self.config.version {
return Runtime::Rust(Version::new(version.to_string()));
return Runtime::new(
PlatformType::Rust,
RuntimeReq::Toolchain(VersionSpec::Version(version.to_owned())),
);
}

Runtime::Rust(Version::new_global())
Runtime::new(PlatformType::Rust, RuntimeReq::Global)
}

fn matches(&self, platform: &PlatformType, runtime: Option<&Runtime>) -> bool {
Expand All @@ -89,7 +95,7 @@ impl Platform for RustPlatform {
}

if let Some(runtime) = &runtime {
return matches!(runtime, Runtime::Rust(_));
return matches!(runtime.platform, PlatformType::Rust);
}

false
Expand Down Expand Up @@ -155,8 +161,8 @@ impl Platform for RustPlatform {
Ok(Box::new(tool))
}

fn get_tool_for_version(&self, version: Version) -> miette::Result<Box<&dyn Tool>> {
let tool = self.toolchain.get_for_version(&version)?;
fn get_tool_for_version(&self, req: RuntimeReq) -> miette::Result<Box<&dyn Tool>> {
let tool = self.toolchain.get_for_version(&req)?;

Ok(Box::new(tool))
}
Expand All @@ -167,8 +173,8 @@ impl Platform for RustPlatform {

async fn setup_toolchain(&mut self) -> miette::Result<()> {
let version = match &self.config.version {
Some(v) => Version::new(v.to_string()),
None => Version::new_global(),
Some(v) => RuntimeReq::Toolchain(VersionSpec::Version(v.to_owned())),
None => RuntimeReq::Global,
};

let mut last_versions = FxHashMap::default();
Expand Down Expand Up @@ -199,16 +205,16 @@ impl Platform for RustPlatform {
runtime: &Runtime,
last_versions: &mut FxHashMap<String, SemVersion>,
) -> miette::Result<u8> {
let version = runtime.version();
let req = &runtime.requirement;

if !self.toolchain.has(&version) {
if !self.toolchain.has(req) {
self.toolchain.register(
&version,
RustTool::new(&self.proto_env, &self.config, &version).await?,
req,
RustTool::new(&self.proto_env, &self.config, req).await?,
);
}

Ok(self.toolchain.setup(&version, last_versions).await?)
Ok(self.toolchain.setup(req, last_versions).await?)
}

async fn install_deps(
Expand All @@ -217,7 +223,7 @@ impl Platform for RustPlatform {
runtime: &Runtime,
working_dir: &Path,
) -> miette::Result<()> {
let tool = self.toolchain.get_for_version(runtime.version())?;
let tool = self.toolchain.get_for_version(&runtime.requirement)?;

if find_cargo_lock(working_dir).is_none() {
print_checkpoint("cargo generate-lockfile", Checkpoint::Setup);
Expand Down Expand Up @@ -466,10 +472,8 @@ impl Platform for RustPlatform {
| "rustdoc" | "rustfmt" | "rustup" => {}
// Handle toolchains for cargo commands
"cargo" => {
let version = runtime.version();

if version.is_override() {
args.push(format!("+{}", version.number));
if runtime.requirement.is_override() {
args.push(format!("+{}", runtime.requirement));
}
}
// Binary may be installed to ~/.cargo/bin
Expand Down
2 changes: 1 addition & 1 deletion crates/rust/tool/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ publish = false
[dependencies]
moon_config = { path = "../../../nextgen/config" }
moon_logger = { path = "../../core/logger" }
moon_platform_runtime = { path = "../../core/platform-runtime" }
moon_platform_runtime2 = { path = "../../../nextgen/platform-runtime" }
moon_process = { path = "../../../nextgen/process" }
moon_terminal = { path = "../../core/terminal" }
moon_tool = { path = "../../core/tool" }
Expand Down
8 changes: 4 additions & 4 deletions crates/rust/tool/src/rust_tool.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use moon_config::RustConfig;
use moon_logger::debug;
use moon_platform_runtime::Version;
use moon_platform_runtime2::RuntimeReq;
use moon_process::Command;
use moon_terminal::{print_checkpoint, Checkpoint};
use moon_tool::{async_trait, load_tool_plugin, Tool};
Expand All @@ -25,7 +25,7 @@ impl RustTool {
pub async fn new(
proto: &ProtoEnvironment,
config: &RustConfig,
version: &Version,
req: &RuntimeReq,
) -> miette::Result<RustTool> {
let mut rust = RustTool {
config: config.to_owned(),
Expand All @@ -34,11 +34,11 @@ impl RustTool {
.await?,
};

if version.is_global() {
if req.is_global() {
rust.global = true;
rust.config.version = None;
} else {
rust.config.version = SemVersion::parse(&version.number).ok();
rust.config.version = req.to_version();
};

Ok(rust)
Expand Down
Loading

0 comments on commit 7071c1f

Please sign in to comment.