Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added cargo-script support #1050

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
37 changes: 34 additions & 3 deletions compiler/base/orchestrator/src/coordinator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,7 @@ pub struct ExecuteRequest {
pub tests: bool,
pub backtrace: bool,
pub code: String,
pub cargo_script: bool,
}

impl ExecuteRequest {
Expand All @@ -374,7 +375,13 @@ impl ExecuteRequest {
}

fn execute_cargo_request(&self) -> ExecuteCommandRequest {
let mut args = vec![];
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 {
vec![]
};

let cmd = match (self.tests, self.crate_type.is_binary()) {
(true, _) => "test",
Expand All @@ -387,6 +394,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());
Expand Down Expand Up @@ -452,6 +464,7 @@ pub struct CompileRequest {
pub tests: bool,
pub backtrace: bool,
pub code: String,
pub cargo_script: bool,
}

impl CompileRequest {
Expand Down Expand Up @@ -558,6 +571,7 @@ pub struct FormatRequest {
pub crate_type: CrateType,
pub edition: Edition,
pub code: String,
pub cargo_script: bool,
}

impl FormatRequest {
Expand Down Expand Up @@ -607,6 +621,7 @@ pub struct ClippyRequest {
pub crate_type: CrateType,
pub edition: Edition,
pub code: String,
pub cargo_script: bool,
}

impl ClippyRequest {
Expand Down Expand Up @@ -655,6 +670,7 @@ pub struct MiriRequest {
pub crate_type: CrateType,
pub edition: Edition,
pub code: String,
pub cargo_script: bool,
}

impl MiriRequest {
Expand Down Expand Up @@ -703,6 +719,7 @@ pub struct MacroExpansionRequest {
pub crate_type: CrateType,
pub edition: Edition,
pub code: String,
pub cargo_script: bool,
}

impl MacroExpansionRequest {
Expand Down Expand Up @@ -2592,8 +2609,6 @@ fn basic_secure_docker_command() -> Command {
"--platform",
DOCKER_ARCH,
"--cap-drop=ALL",
"--net",
"none",
"--memory",
"512m",
"--memory-swap",
Expand Down Expand Up @@ -2635,6 +2650,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"])
Expand Down Expand Up @@ -2908,6 +2924,7 @@ mod tests {
tests: false,
backtrace: false,
code: String::new(),
cargo_script: false,
};

fn new_execute_request() -> ExecuteRequest {
Expand Down Expand Up @@ -3357,6 +3374,7 @@ mod tests {
tests: false,
backtrace: false,
code: String::new(),
cargo_script: false,
};

#[tokio::test]
Expand Down Expand Up @@ -3455,6 +3473,7 @@ mod tests {
tests: false,
backtrace: false,
code: String::new(),
cargo_script: false,
};

const DEFAULT_ASSEMBLY_FLAVOR: AssemblyFlavor = AssemblyFlavor::Intel;
Expand Down Expand Up @@ -3601,6 +3620,7 @@ mod tests {
tests: false,
backtrace: false,
code: String::new(),
cargo_script: false,
};

#[tokio::test]
Expand Down Expand Up @@ -3637,6 +3657,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();
Expand Down Expand Up @@ -3664,6 +3685,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();
Expand All @@ -3684,6 +3706,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;}";
Expand Down Expand Up @@ -3772,6 +3795,7 @@ mod tests {
crate_type: CrateType::Library(LibraryType::Rlib),
edition: Edition::Rust2021,
code: String::new(),
cargo_script: false,
};

#[tokio::test]
Expand Down Expand Up @@ -3846,6 +3870,7 @@ mod tests {
crate_type: CrateType::Binary,
edition: Edition::Rust2021,
code: String::new(),
cargo_script: false,
};

#[tokio::test]
Expand Down Expand Up @@ -3885,6 +3910,7 @@ mod tests {
crate_type: CrateType::Library(LibraryType::Cdylib),
edition: Edition::Rust2018,
code: String::new(),
cargo_script: false,
};

#[tokio::test]
Expand Down Expand Up @@ -3935,6 +3961,7 @@ mod tests {
tests: false,
backtrace: false,
code: "pub fn alpha() {}".into(),
cargo_script: false,
};

let response = coordinator
Expand All @@ -3955,6 +3982,7 @@ mod tests {
tests: req.tests,
backtrace: req.backtrace,
code: "pub fn beta() {}".into(),
cargo_script: false,
};

let response = coordinator
Expand Down Expand Up @@ -3985,6 +4013,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();
Expand Down Expand Up @@ -4013,6 +4042,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();
Expand All @@ -4034,6 +4064,7 @@ mod tests {
tests: false,
backtrace: false,
code: Default::default(),
cargo_script: false,
}
}

Expand Down
21 changes: 21 additions & 0 deletions ui/frontend/ConfigMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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]);
Expand All @@ -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 (
<Fragment>
Expand Down Expand Up @@ -142,6 +149,20 @@ const ConfigMenu: React.FC = () => {
onChange={changeProcessAssembly}
/>
</MenuGroup>

{isNightly && (
<MenuGroup title="Cargo">
<EitherConfig
id="cargo-script"
name="Cargo Script"
a={CargoScript.Enabled}
b={CargoScript.Disabled}
value={cargoScript}
onChange={changeCargoScript}
/>

</MenuGroup>
)}
</Fragment>
);
};
Expand Down
1 change: 1 addition & 0 deletions ui/frontend/compileActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ interface CompileRequestBody {
assemblyFlavor: string;
demangleAssembly: string;
processAssembly: string;
cargoScript: boolean;
}

const CompileResponseBody = z.object({
Expand Down
19 changes: 13 additions & 6 deletions ui/frontend/reducers/configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { ThunkAction } from '../actions';
import {
AssemblyFlavor,
Backtrace,
CargoScript,
Channel,
DemangleAssembly,
Edition,
Expand Down Expand Up @@ -35,6 +36,7 @@ interface State {
mode: Mode;
edition: Edition;
backtrace: Backtrace;
cargoScript: CargoScript
}

const initialState: State = {
Expand All @@ -56,6 +58,7 @@ const initialState: State = {
mode: Mode.Debug,
edition: Edition.Rust2021,
backtrace: Backtrace.Disabled,
cargoScript: CargoScript.Enabled
};

const slice = createSlice({
Expand Down Expand Up @@ -117,6 +120,9 @@ const slice = createSlice({
changeProcessAssembly: (state, action: PayloadAction<ProcessAssembly>) => {
state.processAssembly = action.payload;
},
changeCargoScript: (state, action: PayloadAction<CargoScript>) => {
state.cargoScript = action.payload;
},
},
});

Expand All @@ -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;
1 change: 1 addition & 0 deletions ui/frontend/reducers/output/clippy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ interface ClippyRequestBody {
crateType: string;
edition: string;
code: string;
cargoScript: boolean;
}

const ClippyResponseBody = z.object({
Expand Down
Loading