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

Support testing alternative rustc codegen backends #5

Merged
merged 1 commit into from
Jun 28, 2022
Merged
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
17 changes: 9 additions & 8 deletions src/abis/rust.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ static STRUCT_128: bool = false; // cfg!(target_arch="x86_64");
#[allow(dead_code)]
pub struct RustcAbiImpl {
is_nightly: bool,
codegen_backend: Option<String>,
}

impl AbiImpl for RustcAbiImpl {
Expand Down Expand Up @@ -199,13 +200,12 @@ impl AbiImpl for RustcAbiImpl {
}

fn compile_callee(&self, src_path: &Path, lib_name: &str) -> Result<String, BuildError> {
let out = Command::new("rustc")
.arg("--crate-type")
.arg("staticlib")
.arg("--out-dir")
.arg("target/temp/")
.arg(src_path)
.output()?;
let mut cmd = Command::new("rustc");
cmd.arg("--crate-type").arg("staticlib").arg("--out-dir").arg("target/temp/").arg(src_path);
if let Some(codegen_backend) = &self.codegen_backend {
cmd.arg(format!("-Zcodegen-backend={codegen_backend}"));
}
let out = cmd.output()?;

if !out.status.success() {
Err(BuildError::RustCompile(out))
Expand All @@ -220,9 +220,10 @@ impl AbiImpl for RustcAbiImpl {
}

impl RustcAbiImpl {
pub fn new(_system_info: &Config) -> Self {
pub fn new(_system_info: &Config, codegen_backend: Option<String>) -> Self {
Self {
is_nightly: built_info::RUSTC_VERSION.contains("nightly"),
codegen_backend,
}
}

Expand Down
37 changes: 35 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ pub enum BuildError {
width=.2.position.col.saturating_sub(1),
)]
ParseError(String, String, ron::error::Error),
#[error("rust compile error \n{} \n{}",
#[error("rust compile error \n{} \n{}",
std::str::from_utf8(&.0.stdout).unwrap(),
std::str::from_utf8(&.0.stderr).unwrap())]
RustCompile(std::process::Output),
Expand Down Expand Up @@ -93,6 +93,7 @@ pub struct Config {
run_impls: Vec<String>,
run_pairs: Vec<(String, String)>,
run_tests: Vec<String>,
rustc_codegen_backends: Vec<(String, String)>,
}

fn make_app() -> Config {
Expand Down Expand Up @@ -157,6 +158,13 @@ fn make_app() -> Config {
.multiple_values(true)
.takes_value(true),
)
.arg(
Arg::new("add-rustc-codegen-backend")
.long("add-rustc-codegen-backend")
.long_help("Add a rustc codegen backend, in the form of impl_name:path/to/backend")
.multiple_values(true)
.takes_value(true),
)
.after_help("");

let matches = app.get_matches();
Expand Down Expand Up @@ -205,12 +213,30 @@ fn make_app() -> Config {
.map(String::from)
.collect();

let rustc_codegen_backends = matches.values_of("add-rustc-codegen-backend").into_iter()
.flatten()
.map(|pair| {
pair.split_once(':')
.expect("invalid syntax, must be 'impl_name:path/to/backend'")
})
.map(|(a, b)| (String::from(a), String::from(b)))
.collect();

for &(ref name, ref _path) in &rustc_codegen_backends {
if !run_pairs.iter().any(|(a, b)| a == name || b == name) {
eprintln!("Warning: Rustc codegen backend `{name}` is not tested.");
eprintln!("Hint: Try using `--pairs {name}_calls_rustc` or `--pairs rustc_calls_{name}`.");
eprintln!();
}
}

Config {
procgen_tests,
run_conventions,
run_impls,
run_tests,
run_pairs,
rustc_codegen_backends,
}
}

Expand All @@ -231,7 +257,7 @@ fn main() -> Result<(), Box<dyn Error>> {
env::set_var("OPT_LEVEL", "0");

let mut abi_impls: HashMap<&str, Box<dyn AbiImpl>> = HashMap::new();
abi_impls.insert(ABI_IMPL_RUSTC, Box::new(abis::RustcAbiImpl::new(&cfg)));
abi_impls.insert(ABI_IMPL_RUSTC, Box::new(abis::RustcAbiImpl::new(&cfg, None)));
abi_impls.insert(
ABI_IMPL_CC,
Box::new(abis::CcAbiImpl::new(&cfg, ABI_IMPL_CC)),
Expand All @@ -249,6 +275,13 @@ fn main() -> Result<(), Box<dyn Error>> {
Box::new(abis::CcAbiImpl::new(&cfg, ABI_IMPL_MSVC)),
);

for &(ref name, ref path) in &cfg.rustc_codegen_backends {
abi_impls.insert(
name,
Box::new(abis::RustcAbiImpl::new(&cfg, Some(path.to_owned()))),
);
}

let mut reports = Vec::new();
let mut skips = 0;

Expand Down