From 3f7516cceaaf92a33dbf49862743bc58f75778fb Mon Sep 17 00:00:00 2001 From: AlexSherb Date: Sun, 10 Mar 2024 17:28:30 +0300 Subject: [PATCH 1/2] Added cargo-script support --- compiler/base/orchestrator/src/coordinator.rs | 36 ++++++++++- ui/frontend/ConfigMenu.tsx | 21 +++++++ ui/frontend/compileActions.ts | 1 + ui/frontend/reducers/configuration.ts | 19 ++++-- ui/frontend/reducers/output/clippy.ts | 1 + ui/frontend/reducers/output/execute.ts | 63 ++++++++++--------- ui/frontend/reducers/output/format.ts | 1 + ui/frontend/reducers/output/macroExpansion.ts | 1 + ui/frontend/reducers/output/miri.ts | 1 + ui/frontend/selectors/index.ts | 22 +++++-- ui/frontend/types.ts | 5 ++ ui/src/main.rs | 20 ++++-- ui/src/metrics.rs | 14 +++++ ui/src/server_axum.rs | 24 ++++++- ui/src/server_axum/websocket.rs | 3 + 15 files changed, 179 insertions(+), 53 deletions(-) diff --git a/compiler/base/orchestrator/src/coordinator.rs b/compiler/base/orchestrator/src/coordinator.rs index c5538209f..99f5db117 100644 --- a/compiler/base/orchestrator/src/coordinator.rs +++ b/compiler/base/orchestrator/src/coordinator.rs @@ -362,6 +362,7 @@ pub struct ExecuteRequest { pub tests: bool, pub backtrace: bool, pub code: String, + pub cargo_script: bool, } impl ExecuteRequest { @@ -374,7 +375,12 @@ impl ExecuteRequest { } fn execute_cargo_request(&self) -> ExecuteCommandRequest { - let mut args = vec![]; + let is_cargo_script_enabled = self.channel == Channel::Nightly && self.cargo_script; + let mut args = if is_cargo_script_enabled { + vec!["-Zscript"] + } else { + vec![] + }; let cmd = match (self.tests, self.crate_type.is_binary()) { (true, _) => "test", @@ -387,6 +393,11 @@ impl ExecuteRequest { args.push("--release"); } + if is_cargo_script_enabled { + args.push("--manifest-path"); + args.push("src/main.rs"); + } + let mut envs = HashMap::new(); if self.backtrace { envs.insert("RUST_BACKTRACE".to_owned(), "1".to_owned()); @@ -452,6 +463,7 @@ pub struct CompileRequest { pub tests: bool, pub backtrace: bool, pub code: String, + pub cargo_script: bool, } impl CompileRequest { @@ -558,6 +570,7 @@ pub struct FormatRequest { pub crate_type: CrateType, pub edition: Edition, pub code: String, + pub cargo_script: bool, } impl FormatRequest { @@ -607,6 +620,7 @@ pub struct ClippyRequest { pub crate_type: CrateType, pub edition: Edition, pub code: String, + pub cargo_script: bool, } impl ClippyRequest { @@ -655,6 +669,7 @@ pub struct MiriRequest { pub crate_type: CrateType, pub edition: Edition, pub code: String, + pub cargo_script: bool, } impl MiriRequest { @@ -703,6 +718,7 @@ pub struct MacroExpansionRequest { pub crate_type: CrateType, pub edition: Edition, pub code: String, + pub cargo_script: bool, } impl MacroExpansionRequest { @@ -2592,8 +2608,6 @@ fn basic_secure_docker_command() -> Command { "--platform", DOCKER_ARCH, "--cap-drop=ALL", - "--net", - "none", "--memory", "512m", "--memory-swap", @@ -2635,6 +2649,7 @@ impl Backend for DockerBackend { let mut command = basic_secure_docker_command(); command .args(["--name", &name]) + .args(["--network", "host"]) .arg("-i") .args(["-a", "stdin", "-a", "stdout", "-a", "stderr"]) .args(["-e", "PLAYGROUND_ORCHESTRATOR=1"]) @@ -2908,6 +2923,7 @@ mod tests { tests: false, backtrace: false, code: String::new(), + cargo_script: false, }; fn new_execute_request() -> ExecuteRequest { @@ -3357,6 +3373,7 @@ mod tests { tests: false, backtrace: false, code: String::new(), + cargo_script: false, }; #[tokio::test] @@ -3455,6 +3472,7 @@ mod tests { tests: false, backtrace: false, code: String::new(), + cargo_script: false, }; const DEFAULT_ASSEMBLY_FLAVOR: AssemblyFlavor = AssemblyFlavor::Intel; @@ -3601,6 +3619,7 @@ mod tests { tests: false, backtrace: false, code: String::new(), + cargo_script: false, }; #[tokio::test] @@ -3637,6 +3656,7 @@ mod tests { tests: false, backtrace: false, code: r#"pub fn mul(a: u8, b: u8) -> u8 { a * b }"#.into(), + cargo_script: false, }; let response = coordinator.compile(req).with_timeout().await.unwrap(); @@ -3664,6 +3684,7 @@ mod tests { tests: false, backtrace: false, code: r#"#[export_name = "inc"] pub fn inc(a: u8) -> u8 { a + 1 }"#.into(), + cargo_script: false, }; let response = coordinator.compile(req).with_timeout().await.unwrap(); @@ -3684,6 +3705,7 @@ mod tests { crate_type: CrateType::Binary, edition: Edition::Rust2015, code: String::new(), + cargo_script: false, }; const ARBITRARY_FORMAT_INPUT: &str = "fn main(){1+1;}"; @@ -3772,6 +3794,7 @@ mod tests { crate_type: CrateType::Library(LibraryType::Rlib), edition: Edition::Rust2021, code: String::new(), + cargo_script: false, }; #[tokio::test] @@ -3846,6 +3869,7 @@ mod tests { crate_type: CrateType::Binary, edition: Edition::Rust2021, code: String::new(), + cargo_script: false, }; #[tokio::test] @@ -3885,6 +3909,7 @@ mod tests { crate_type: CrateType::Library(LibraryType::Cdylib), edition: Edition::Rust2018, code: String::new(), + cargo_script: false, }; #[tokio::test] @@ -3935,6 +3960,7 @@ mod tests { tests: false, backtrace: false, code: "pub fn alpha() {}".into(), + cargo_script: false, }; let response = coordinator @@ -3955,6 +3981,7 @@ mod tests { tests: req.tests, backtrace: req.backtrace, code: "pub fn beta() {}".into(), + cargo_script: false, }; let response = coordinator @@ -3985,6 +4012,7 @@ mod tests { tests: false, backtrace: false, code: r#"fn main() { println!("hello") }"#.into(), + cargo_script: false, }; let res = coordinator.execute(req.clone()).await.unwrap(); @@ -4013,6 +4041,7 @@ mod tests { tests: false, backtrace: false, code: r#"fn main() { std::process::abort(); }"#.into(), + cargo_script: false, }; let res = coordinator.execute(req.clone()).await.unwrap(); @@ -4034,6 +4063,7 @@ mod tests { tests: false, backtrace: false, code: Default::default(), + cargo_script: false, } } diff --git a/ui/frontend/ConfigMenu.tsx b/ui/frontend/ConfigMenu.tsx index 2dbdc5559..aa3caf578 100644 --- a/ui/frontend/ConfigMenu.tsx +++ b/ui/frontend/ConfigMenu.tsx @@ -9,12 +9,15 @@ import { useAppDispatch, useAppSelector } from './hooks'; import * as config from './reducers/configuration'; import { AssemblyFlavor, + CargoScript, + Channel, DemangleAssembly, Editor, Orientation, PairCharacters, ProcessAssembly, } from './types'; +import { shallowEqual } from 'react-redux'; const MONACO_THEMES = [ 'vs', 'vs-dark', 'vscode-dark-plus', @@ -30,6 +33,8 @@ const ConfigMenu: React.FC = () => { const assemblyFlavor = useAppSelector((state) => state.configuration.assemblyFlavor); const demangleAssembly = useAppSelector((state) => state.configuration.demangleAssembly); const processAssembly = useAppSelector((state) => state.configuration.processAssembly); + const cargoScript = useAppSelector((state) => state.configuration.cargoScript); + const isNightly = useAppSelector((state) => state.configuration.channel === Channel.Nightly, shallowEqual); const dispatch = useAppDispatch(); const changeAceTheme = useCallback((t: string) => dispatch(config.changeAceTheme(t)), [dispatch]); @@ -45,6 +50,8 @@ const ConfigMenu: React.FC = () => { useCallback((p: ProcessAssembly) => dispatch(config.changeProcessAssembly(p)), [dispatch]); const changeDemangleAssembly = useCallback((d: DemangleAssembly) => dispatch(config.changeDemangleAssembly(d)), [dispatch]); + const changeCargoScript = + useCallback((c: CargoScript) => dispatch(config.changeCargoScript(c)), [dispatch]); return ( @@ -142,6 +149,20 @@ const ConfigMenu: React.FC = () => { onChange={changeProcessAssembly} /> + + {isNightly && ( + + + + + )} ); }; diff --git a/ui/frontend/compileActions.ts b/ui/frontend/compileActions.ts index cb93f98d4..7b2af5bde 100644 --- a/ui/frontend/compileActions.ts +++ b/ui/frontend/compileActions.ts @@ -17,6 +17,7 @@ interface CompileRequestBody { assemblyFlavor: string; demangleAssembly: string; processAssembly: string; + cargoScript: boolean; } const CompileResponseBody = z.object({ diff --git a/ui/frontend/reducers/configuration.ts b/ui/frontend/reducers/configuration.ts index bd85a7354..6b83e125b 100644 --- a/ui/frontend/reducers/configuration.ts +++ b/ui/frontend/reducers/configuration.ts @@ -4,6 +4,7 @@ import { ThunkAction } from '../actions'; import { AssemblyFlavor, Backtrace, + CargoScript, Channel, DemangleAssembly, Edition, @@ -35,6 +36,7 @@ interface State { mode: Mode; edition: Edition; backtrace: Backtrace; + cargoScript: CargoScript } const initialState: State = { @@ -56,6 +58,7 @@ const initialState: State = { mode: Mode.Debug, edition: Edition.Rust2021, backtrace: Backtrace.Disabled, + cargoScript: CargoScript.Enabled }; const slice = createSlice({ @@ -117,6 +120,9 @@ const slice = createSlice({ changeProcessAssembly: (state, action: PayloadAction) => { state.processAssembly = action.payload; }, + changeCargoScript: (state, action: PayloadAction) => { + state.cargoScript = action.payload; + }, }, }); @@ -135,16 +141,17 @@ export const { changePairCharacters, changePrimaryAction, changeProcessAssembly, + changeCargoScript } = slice.actions; export const changeEdition = (edition: Edition): ThunkAction => - (dispatch) => { - if (edition === Edition.Rust2024) { - dispatch(changeChannel(Channel.Nightly)); - } + (dispatch) => { + if (edition === Edition.Rust2024) { + dispatch(changeChannel(Channel.Nightly)); + } - dispatch(changeEditionRaw(edition)); - }; + dispatch(changeEditionRaw(edition)); + }; export default slice.reducer; diff --git a/ui/frontend/reducers/output/clippy.ts b/ui/frontend/reducers/output/clippy.ts index 5382c5932..19b08878c 100644 --- a/ui/frontend/reducers/output/clippy.ts +++ b/ui/frontend/reducers/output/clippy.ts @@ -23,6 +23,7 @@ interface ClippyRequestBody { crateType: string; edition: string; code: string; + cargoScript: boolean; } const ClippyResponseBody = z.object({ diff --git a/ui/frontend/reducers/output/execute.ts b/ui/frontend/reducers/output/execute.ts index 46ac1ded7..c0fe7cda2 100644 --- a/ui/frontend/reducers/output/execute.ts +++ b/ui/frontend/reducers/output/execute.ts @@ -83,6 +83,7 @@ export interface ExecuteRequestBody { code: string; edition: string; backtrace: boolean; + cargoScript: boolean; } const ExecuteResponseBody = z.object({ @@ -108,16 +109,16 @@ const prepareWithCurrentSequenceNumber =

(payload: P, sequenceNumber: number) const sequenceNumberMatches =

(whenMatch: (state: Draft, payload: P) => void) => - (state: Draft, action: WsPayloadAction

) => { - const { - payload, - meta: { sequenceNumber }, - } = action; + (state: Draft, action: WsPayloadAction

) => { + const { + payload, + meta: { sequenceNumber }, + } = action; - if (sequenceNumber === state.sequenceNumber) { - whenMatch(state, payload); - } - }; + if (sequenceNumber === state.sequenceNumber) { + whenMatch(state, payload); + } + }; const slice = createSlice({ name: 'output/execute', @@ -137,17 +138,17 @@ const slice = createSlice({ }), }, wsExecuteStdin: { - reducer: () => {}, + reducer: () => { }, prepare: prepareWithCurrentSequenceNumber, }, wsExecuteStdinClose: { - reducer: () => {}, + reducer: () => { }, prepare: prepareWithCurrentSequenceNumber, }, wsExecuteKill: { - reducer: () => {}, + reducer: () => { }, prepare: prepareWithCurrentSequenceNumber, }, @@ -231,28 +232,28 @@ export const { wsExecuteRequest, allowLongRun, wsExecuteKill } = slice.actions; export const performCommonExecute = (crateType: string, tests: boolean): ThunkAction => - (dispatch, getState) => { - const state = getState(); - const body = executeRequestPayloadSelector(state, { crateType, tests }); - const useWebSocket = executeViaWebsocketSelector(state); - - if (useWebSocket) { - dispatch(wsExecuteRequest(body)); - } else { - dispatch(performExecute(body)); - } - }; + (dispatch, getState) => { + const state = getState(); + const body = executeRequestPayloadSelector(state, { crateType, tests }); + const useWebSocket = executeViaWebsocketSelector(state); + + if (useWebSocket) { + dispatch(wsExecuteRequest(body)); + } else { + dispatch(performExecute(body)); + } + }; const dispatchWhenSequenceNumber = (cb: (sequenceNumber: number) => A): ThunkAction => - (dispatch, getState) => { - const state = getState(); - const sequenceNumber = currentExecutionSequenceNumberSelector(state); - if (sequenceNumber) { - const action = cb(sequenceNumber); - dispatch(action); - } - }; + (dispatch, getState) => { + const state = getState(); + const sequenceNumber = currentExecutionSequenceNumberSelector(state); + if (sequenceNumber) { + const action = cb(sequenceNumber); + dispatch(action); + } + }; export const wsExecuteStdin = (payload: string): ThunkAction => dispatchWhenSequenceNumber((sequenceNumber) => diff --git a/ui/frontend/reducers/output/format.ts b/ui/frontend/reducers/output/format.ts index efdedea07..40d322aea 100644 --- a/ui/frontend/reducers/output/format.ts +++ b/ui/frontend/reducers/output/format.ts @@ -21,6 +21,7 @@ interface FormatRequestBody { channel: string; edition: string; code: string; + cargoScript: boolean; } const FormatResponseBody = z.object({ diff --git a/ui/frontend/reducers/output/macroExpansion.ts b/ui/frontend/reducers/output/macroExpansion.ts index 850e965c6..fb7d08a1c 100644 --- a/ui/frontend/reducers/output/macroExpansion.ts +++ b/ui/frontend/reducers/output/macroExpansion.ts @@ -21,6 +21,7 @@ interface State { interface MacroExpansionRequestBody { code: string; edition: string; + cargoScript: boolean; } const MacroExpansionResponseBody = z.object({ diff --git a/ui/frontend/reducers/output/miri.ts b/ui/frontend/reducers/output/miri.ts index 0c52f12d5..d8cbd8618 100644 --- a/ui/frontend/reducers/output/miri.ts +++ b/ui/frontend/reducers/output/miri.ts @@ -21,6 +21,7 @@ interface State { interface MiriRequestBody { code: string; edition: string; + cargoScript: boolean; } const MiriResponseBody = z.object({ diff --git a/ui/frontend/selectors/index.ts b/ui/frontend/selectors/index.ts index 8c53cbfe2..417f17075 100644 --- a/ui/frontend/selectors/index.ts +++ b/ui/frontend/selectors/index.ts @@ -4,6 +4,7 @@ import { createSelector } from '@reduxjs/toolkit'; import { State } from '../reducers'; import { Backtrace, + CargoScript, Channel, Edition, Focus, @@ -16,6 +17,7 @@ import { export const codeSelector = (state: State) => state.code; export const positionSelector = (state: State) => state.position; export const selectionSelector = (state: State) => state.selection; +export const cargoScriptSelector = (state: State) => state.configuration.cargoScript === CargoScript.Enabled const HAS_TESTS_RE = /^\s*#\s*\[\s*test\s*([^"]*)]/m; export const hasTestsSelector = createSelector(codeSelector, code => !!code.match(HAS_TESTS_RE)); @@ -375,26 +377,30 @@ export const clippyRequestSelector = createSelector( getCrateType, editionSelector, codeSelector, - (channel, crateType, edition, code) => ({ channel, crateType, edition, code }), + cargoScriptSelector, + (channel, crateType, edition, code, cargoScript) => ({ channel, crateType, edition, code, cargoScript }), ); export const formatRequestSelector = createSelector( channelSelector, editionSelector, codeSelector, - (channel, edition, code) => ({ channel, edition, code }), + cargoScriptSelector, + (channel, edition, code, cargoScript) => ({ channel, edition, code, cargoScript }), ); export const miriRequestSelector = createSelector( editionSelector, codeSelector, - (edition, code) => ({ edition, code }), + cargoScriptSelector, + (edition, code, cargoScript) => ({ edition, code, cargoScript }), ); export const macroExpansionRequestSelector = createSelector( editionSelector, codeSelector, - (edition, code) => ({ edition, code }) + cargoScriptSelector, + (edition, code, cargoScript) => ({ edition, code, cargoScript }) ); const focus = (state: State) => state.output.meta.focus; @@ -472,7 +478,8 @@ export const executeRequestPayloadSelector = createSelector( (state: State) => state.configuration, getBacktraceSet, (_state: State, { crateType, tests }: { crateType: string, tests: boolean }) => ({ crateType, tests }), - (code, channel, configuration, backtrace, { crateType, tests }) => ({ + cargoScriptSelector, + (code, channel, configuration, backtrace, { crateType, tests }, cargoScript) => ({ channel, mode: configuration.mode, edition: configuration.edition, @@ -480,6 +487,7 @@ export const executeRequestPayloadSelector = createSelector( tests, code, backtrace, + cargoScript }), ); @@ -491,7 +499,8 @@ export const compileRequestPayloadSelector = createSelector( runAsTest, getBacktraceSet, (_state: State, { target }: { target: string }) => ({ target }), - (code, channel, configuration, crateType, tests, backtrace, { target }) => ({ + cargoScriptSelector, + (code, channel, configuration, crateType, tests, backtrace, { target }, cargoScript) => ({ channel, mode: configuration.mode, edition: configuration.edition, @@ -503,5 +512,6 @@ export const compileRequestPayloadSelector = createSelector( demangleAssembly: configuration.demangleAssembly, processAssembly: configuration.processAssembly, backtrace, + cargoScript }), ); diff --git a/ui/frontend/types.ts b/ui/frontend/types.ts index 0f1721a8f..92c01ab6a 100644 --- a/ui/frontend/types.ts +++ b/ui/frontend/types.ts @@ -161,3 +161,8 @@ export enum Focus { export enum Notification { RustSurvey2023 = 'rust-survey-2023', } + +export enum CargoScript { + Enabled = 'enabled', + Disabled = 'disabled' +} \ No newline at end of file diff --git a/ui/src/main.rs b/ui/src/main.rs index d73d5b0f8..379b40682 100644 --- a/ui/src/main.rs +++ b/ui/src/main.rs @@ -335,24 +335,22 @@ struct ErrorJson { } #[derive(Debug, Clone, Serialize, Deserialize)] +#[serde(rename_all = "camelCase")] struct CompileRequest { target: String, - #[serde(rename = "assemblyFlavor")] assembly_flavor: Option, - #[serde(rename = "demangleAssembly")] demangle_assembly: Option, - #[serde(rename = "processAssembly")] process_assembly: Option, channel: String, mode: String, #[serde(default)] edition: String, - #[serde(rename = "crateType")] crate_type: String, tests: bool, #[serde(default)] backtrace: bool, code: String, + cargo_script: bool, } #[derive(Debug, Clone, Serialize)] @@ -366,6 +364,7 @@ struct CompileResponse { } #[derive(Debug, Clone, Serialize, Deserialize)] +#[serde(rename_all = "camelCase")] struct ExecuteRequest { channel: String, mode: String, @@ -377,6 +376,7 @@ struct ExecuteRequest { #[serde(default)] backtrace: bool, code: String, + cargo_script: bool, } #[derive(Debug, Clone, Serialize)] @@ -389,12 +389,14 @@ struct ExecuteResponse { } #[derive(Debug, Clone, Serialize, Deserialize)] +#[serde(rename_all = "camelCase")] struct FormatRequest { #[serde(default)] channel: Option, #[serde(default)] edition: String, code: String, + cargo_script: bool, } #[derive(Debug, Clone, Serialize)] @@ -408,14 +410,16 @@ struct FormatResponse { } #[derive(Debug, Clone, Serialize, Deserialize)] +#[serde(rename_all = "camelCase")] struct ClippyRequest { #[serde(default)] channel: Option, - #[serde(default = "default_crate_type", rename = "crateType")] + #[serde(default = "default_crate_type")] crate_type: String, #[serde(default)] edition: String, code: String, + cargo_script: bool, } #[derive(Debug, Clone, Serialize)] @@ -427,10 +431,12 @@ struct ClippyResponse { } #[derive(Debug, Clone, Serialize, Deserialize)] +#[serde(rename_all = "camelCase")] struct MiriRequest { code: String, #[serde(default)] edition: String, + cargo_script: bool, } #[derive(Debug, Clone, Serialize)] @@ -442,10 +448,12 @@ struct MiriResponse { } #[derive(Debug, Clone, Serialize, Deserialize)] +#[serde(rename_all = "camelCase")] struct MacroExpansionRequest { code: String, #[serde(default)] edition: String, + cargo_script: bool, } #[derive(Debug, Clone, Serialize)] @@ -504,6 +512,7 @@ struct MetaGistResponse { } #[derive(Debug, Clone, Serialize, Deserialize)] +#[serde(rename_all = "camelCase")] struct EvaluateRequest { version: String, optimize: String, @@ -512,6 +521,7 @@ struct EvaluateRequest { edition: String, #[serde(default)] tests: bool, + cargo_script: bool, } #[derive(Debug, Clone, Serialize)] diff --git a/ui/src/metrics.rs b/ui/src/metrics.rs index b530240e5..eaa05b8ee 100644 --- a/ui/src/metrics.rs +++ b/ui/src/metrics.rs @@ -82,6 +82,7 @@ pub(crate) struct LabelsCore { crate_type: Option, tests: Option, backtrace: Option, + cargo_script: Option, } #[derive(Debug, Copy, Clone)] @@ -187,6 +188,7 @@ impl Labels { crate_type, tests, backtrace, + cargo_script, } = labels_core; Self { endpoint, @@ -251,6 +253,7 @@ impl HasLabelsCore for coordinator::CompileRequest { tests, backtrace, code: _, + cargo_script, } = *self; LabelsCore { @@ -261,6 +264,7 @@ impl HasLabelsCore for coordinator::CompileRequest { crate_type: Some(crate_type), tests: Some(tests), backtrace: Some(backtrace), + cargo_script: Some(cargo_script), } } } @@ -275,6 +279,7 @@ impl HasLabelsCore for coordinator::ExecuteRequest { tests, backtrace, code: _, + cargo_script, } = *self; LabelsCore { @@ -285,6 +290,7 @@ impl HasLabelsCore for coordinator::ExecuteRequest { crate_type: Some(crate_type), tests: Some(tests), backtrace: Some(backtrace), + cargo_script: Some(cargo_script), } } } @@ -296,6 +302,7 @@ impl HasLabelsCore for coordinator::FormatRequest { crate_type, edition, code: _, + cargo_script, } = *self; LabelsCore { @@ -306,6 +313,7 @@ impl HasLabelsCore for coordinator::FormatRequest { crate_type: Some(crate_type), tests: None, backtrace: None, + cargo_script: Some(cargo_script), } } } @@ -317,6 +325,7 @@ impl HasLabelsCore for coordinator::ClippyRequest { crate_type, edition, code: _, + cargo_script, } = *self; LabelsCore { @@ -327,6 +336,7 @@ impl HasLabelsCore for coordinator::ClippyRequest { crate_type: Some(crate_type), tests: None, backtrace: None, + cargo_script: Some(cargo_script), } } } @@ -338,6 +348,7 @@ impl HasLabelsCore for coordinator::MiriRequest { crate_type, edition, code: _, + cargo_script, } = *self; LabelsCore { @@ -348,6 +359,7 @@ impl HasLabelsCore for coordinator::MiriRequest { crate_type: Some(crate_type), tests: None, backtrace: None, + cargo_script: Some(cargo_script), } } } @@ -359,6 +371,7 @@ impl HasLabelsCore for coordinator::MacroExpansionRequest { crate_type, edition, code: _, + cargo_script, } = *self; LabelsCore { @@ -369,6 +382,7 @@ impl HasLabelsCore for coordinator::MacroExpansionRequest { crate_type: Some(crate_type), tests: None, backtrace: None, + cargo_script: Some(cargo_script), } } } diff --git a/ui/src/server_axum.rs b/ui/src/server_axum.rs index f0ec1c43d..9e21e3602 100644 --- a/ui/src/server_axum.rs +++ b/ui/src/server_axum.rs @@ -1049,6 +1049,7 @@ pub(crate) mod api_orchestrator_integration_impls { code, edition, tests, + cargo_script, } = other; let mode = if optimize != "0" { @@ -1071,6 +1072,7 @@ pub(crate) mod api_orchestrator_integration_impls { tests, backtrace: false, code, + cargo_script, }) } } @@ -1132,6 +1134,7 @@ pub(crate) mod api_orchestrator_integration_impls { tests, backtrace, code, + cargo_script, } = other; Ok(Self { @@ -1148,6 +1151,7 @@ pub(crate) mod api_orchestrator_integration_impls { tests, backtrace, code, + cargo_script, }) } } @@ -1205,6 +1209,7 @@ pub(crate) mod api_orchestrator_integration_impls { tests, backtrace, code, + cargo_script, } = other; Ok(Self { @@ -1215,6 +1220,7 @@ pub(crate) mod api_orchestrator_integration_impls { tests, backtrace, code, + cargo_script, }) } } @@ -1263,6 +1269,7 @@ pub(crate) mod api_orchestrator_integration_impls { channel, edition, code, + cargo_script, } = other; let channel = match channel { @@ -1275,6 +1282,7 @@ pub(crate) mod api_orchestrator_integration_impls { crate_type: CrateType::Binary, // TODO: use what user has submitted edition: parse_edition(&edition)?, code, + cargo_script, }) } } @@ -1320,6 +1328,7 @@ pub(crate) mod api_orchestrator_integration_impls { crate_type, edition, code, + cargo_script, } = other; let channel = match channel { @@ -1332,6 +1341,7 @@ pub(crate) mod api_orchestrator_integration_impls { crate_type: parse_crate_type(&crate_type)?, edition: parse_edition(&edition)?, code, + cargo_script, }) } } @@ -1373,13 +1383,18 @@ pub(crate) mod api_orchestrator_integration_impls { type Error = ParseMiriRequestError; fn try_from(other: crate::MiriRequest) -> std::result::Result { - let crate::MiriRequest { code, edition } = other; + let crate::MiriRequest { + code, + edition, + cargo_script, + } = other; Ok(MiriRequest { channel: Channel::Nightly, // TODO: use what user has submitted crate_type: CrateType::Binary, // TODO: use what user has submitted edition: parse_edition(&edition)?, code, + cargo_script, }) } } @@ -1415,13 +1430,18 @@ pub(crate) mod api_orchestrator_integration_impls { type Error = ParseMacroExpansionRequestError; fn try_from(other: crate::MacroExpansionRequest) -> std::result::Result { - let crate::MacroExpansionRequest { code, edition } = other; + let crate::MacroExpansionRequest { + code, + edition, + cargo_script, + } = other; Ok(MacroExpansionRequest { channel: Channel::Nightly, // TODO: use what user has submitted crate_type: CrateType::Binary, // TODO: use what user has submitted edition: parse_edition(&edition)?, code, + cargo_script, }) } } diff --git a/ui/src/server_axum/websocket.rs b/ui/src/server_axum/websocket.rs index c54d13d5e..734e6738f 100644 --- a/ui/src/server_axum/websocket.rs +++ b/ui/src/server_axum/websocket.rs @@ -83,6 +83,7 @@ struct ExecuteRequest { tests: bool, code: String, backtrace: bool, + cargo_script: bool, } impl TryFrom for coordinator::ExecuteRequest { @@ -97,6 +98,7 @@ impl TryFrom for coordinator::ExecuteRequest { tests, code, backtrace, + cargo_script, } = value; Ok(coordinator::ExecuteRequest { @@ -107,6 +109,7 @@ impl TryFrom for coordinator::ExecuteRequest { tests, backtrace, code, + cargo_script, }) } } From 1957679eda3332d90f70436c6cc95a801f20a1cf Mon Sep 17 00:00:00 2001 From: AlexSherb Date: Sun, 10 Mar 2024 18:42:17 +0300 Subject: [PATCH 2/2] Lib crate types ignored when running with cargo_script option --- compiler/base/orchestrator/src/coordinator.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/compiler/base/orchestrator/src/coordinator.rs b/compiler/base/orchestrator/src/coordinator.rs index 99f5db117..d62047acb 100644 --- a/compiler/base/orchestrator/src/coordinator.rs +++ b/compiler/base/orchestrator/src/coordinator.rs @@ -375,7 +375,8 @@ impl ExecuteRequest { } fn execute_cargo_request(&self) -> ExecuteCommandRequest { - let is_cargo_script_enabled = self.channel == Channel::Nightly && self.cargo_script; + let is_cargo_script_enabled = + self.channel == Channel::Nightly && self.cargo_script && self.crate_type.is_binary(); let mut args = if is_cargo_script_enabled { vec!["-Zscript"] } else {