Skip to content
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
65 changes: 60 additions & 5 deletions crates/intrinsic-test/src/common/gen_rust.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,11 @@ pub fn run_rustfmt(source_path: &str) {
/// [workspace]
/// members = [ "mod_0", "mod_1" ]
/// ```
pub fn write_bin_cargo_toml(
///
/// Also writes the common dependencies to `lockfile`.
pub fn write_workspace_cargo_toml(
w: &mut impl std::io::Write,
lockfile: &mut impl std::io::Write,
module_count: usize,
) -> std::io::Result<()> {
write!(
Expand All @@ -66,17 +69,57 @@ pub fn write_bin_cargo_toml(
members = [{members}]
"#,
members = (0..module_count).format_with(",", |i, fmt| fmt(&format_args!("\"mod_{i}\"")))
)?;
write!(
lockfile,
r#"# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 4

[[package]]
name = "cc"
version = "1.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5add81bb678e6cb321aff7fa0dc7689ad82b112dbc032cea19f91d6b8e3582b9"
dependencies = [
"find-msvc-tools",
"shlex",
]

[[package]]
name = "core_arch"
version = "0.1.5"

[[package]]
name = "find-msvc-tools"
version = "0.1.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5baebc0774151f905a1a2cc41989300b1e6fbb29aff0ceffa1064fdd3088d582"

[[package]]
name = "shlex"
version = "2.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f8fadd59c855ef2080decdef8ff161eb6661b86933c9d82e5ba29dc602a55aba"
"#
)
}

/// Writes a `Cargo.toml` for a crate with name `name` to `w` that will contain a single Rust source
/// file with a subset of the testing being generated.
pub fn write_lib_cargo_toml(w: &mut impl std::io::Write, name: &str) -> std::io::Result<()> {
/// file with a subset of the testing being generated. And writes an entry for the library to
/// `lockfile`.
pub fn write_lib_cargo_toml(
w: &mut impl std::io::Write,
lockfile: &mut impl std::io::Write,
name: &str,
) -> std::io::Result<()> {
let version = env!("CARGO_PKG_VERSION");

write!(
w,
r#"
[package]
name = "{name}"
name = "zzz_{name}"
version = "{version}"
authors = [{authors}]
license = "{license}"
Expand All @@ -88,11 +131,23 @@ core_arch = {{ path = "../../crates/core_arch" }}
[build-dependencies]
cc = "1"
"#,
version = env!("CARGO_PKG_VERSION"),
authors = env!("CARGO_PKG_AUTHORS")
.split(":")
.format_with(", ", |author, fmt| fmt(&format_args!("\"{author}\""))),
license = env!("CARGO_PKG_LICENSE"),
)?;

write!(
lockfile,
r#"
[[package]]
name = "zzz_{name}"
version = "{version}"
dependencies = [
"cc",
"core_arch",
]
"#,
)
}

Expand Down
17 changes: 13 additions & 4 deletions crates/intrinsic-test/src/common/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use crate::common::{
argument::Argument,
gen_c::write_wrapper_c,
gen_rust::{
run_rustfmt, write_bin_cargo_toml, write_build_rs, write_lib_cargo_toml, write_lib_rs,
run_rustfmt, write_build_rs, write_lib_cargo_toml, write_lib_rs, write_workspace_cargo_toml,
},
intrinsic::Intrinsic,
intrinsic_helpers::TypeDefinition,
Expand Down Expand Up @@ -75,11 +75,20 @@ pub trait SupportedArchitecture: Sized {
let (max_chunk_size, chunk_count) = manual_chunk(self.intrinsics().len());

let mut cargo = File::create("rust_programs/Cargo.toml").unwrap();
write_bin_cargo_toml(&mut cargo, chunk_count).unwrap();
let mut lockfile = File::create("rust_programs/Cargo.lock").unwrap();
write_workspace_cargo_toml(&mut cargo, &mut lockfile, chunk_count).unwrap();

self.intrinsics()
let mut crates_ = self
.intrinsics()
.chunks(max_chunk_size)
.enumerate()
.collect::<Vec<_>>();

// Sort by stringified index to match cargo's lockfile order
crates_.sort_by_key(|&(i, _)| format!("{i}"));

crates_
.into_iter()
.map(|(i, chunk)| {
std::fs::create_dir_all(format!("rust_programs/mod_{i}/src"))?;

Expand All @@ -94,7 +103,7 @@ pub trait SupportedArchitecture: Sized {
trace!("generating `{toml_filename}`");
let mut file = File::create(toml_filename).unwrap();

write_lib_cargo_toml(&mut file, &format!("mod_{i}"))?;
write_lib_cargo_toml(&mut file, &mut lockfile, &format!("mod_{i}"))?;

let build_rs_filename = format!("rust_programs/mod_{i}/build.rs");
trace!("generating `{build_rs_filename}`");
Expand Down
Loading