Rework rmake support library to have a weakly-typed API with helper methods

This commit is contained in:
许杰友 Jieyou Xu (Joe) 2024-03-13 21:52:23 +00:00
parent 6a92312a1e
commit 1f2178b9e7
No known key found for this signature in database
GPG Key ID: 95DDEBD74A1DC2C0
19 changed files with 404 additions and 282 deletions

View File

@ -1,19 +1,21 @@
pub mod run;
pub mod rustc;
pub mod rustdoc;
use std::env;
use std::path::{Path, PathBuf};
use std::process::{Command, Output};
use std::path::PathBuf;
use std::process::Output;
pub use object;
pub use wasmparser;
pub fn out_dir() -> PathBuf {
env::var_os("TMPDIR").unwrap().into()
}
pub use run::{run, run_fail};
pub use rustc::{aux_build, rustc, Rustc};
pub use rustdoc::{bare_rustdoc, rustdoc, Rustdoc};
fn setup_common_build_cmd(command: &str) -> Command {
let rustc = env::var(command).unwrap();
let mut cmd = Command::new(rustc);
cmd.arg("--out-dir").arg(out_dir()).arg("-L").arg(out_dir());
cmd
/// Path of `TMPDIR` (a temporary build directory, not under `/tmp`).
pub fn tmp_dir() -> PathBuf {
env::var_os("TMPDIR").unwrap().into()
}
fn handle_failed_output(cmd: &str, output: Output, caller_line_number: u32) -> ! {
@ -24,170 +26,3 @@ fn handle_failed_output(cmd: &str, output: Output, caller_line_number: u32) -> !
eprintln!("=== STDERR ===\n{}\n\n", String::from_utf8(output.stderr).unwrap());
std::process::exit(1)
}
pub fn rustc() -> RustcInvocationBuilder {
RustcInvocationBuilder::new()
}
pub fn aux_build() -> AuxBuildInvocationBuilder {
AuxBuildInvocationBuilder::new()
}
pub fn rustdoc() -> Rustdoc {
Rustdoc::new()
}
#[derive(Debug)]
pub struct RustcInvocationBuilder {
cmd: Command,
}
impl RustcInvocationBuilder {
fn new() -> Self {
let cmd = setup_common_build_cmd("RUSTC");
Self { cmd }
}
pub fn arg(&mut self, arg: &str) -> &mut RustcInvocationBuilder {
self.cmd.arg(arg);
self
}
pub fn args(&mut self, args: &[&str]) -> &mut RustcInvocationBuilder {
self.cmd.args(args);
self
}
#[track_caller]
pub fn run(&mut self) -> Output {
let caller_location = std::panic::Location::caller();
let caller_line_number = caller_location.line();
let output = self.cmd.output().unwrap();
if !output.status.success() {
handle_failed_output(&format!("{:#?}", self.cmd), output, caller_line_number);
}
output
}
}
#[derive(Debug)]
pub struct AuxBuildInvocationBuilder {
cmd: Command,
}
impl AuxBuildInvocationBuilder {
fn new() -> Self {
let mut cmd = setup_common_build_cmd("RUSTC");
cmd.arg("--crate-type=lib");
Self { cmd }
}
pub fn arg(&mut self, arg: &str) -> &mut AuxBuildInvocationBuilder {
self.cmd.arg(arg);
self
}
#[track_caller]
pub fn run(&mut self) -> Output {
let caller_location = std::panic::Location::caller();
let caller_line_number = caller_location.line();
let output = self.cmd.output().unwrap();
if !output.status.success() {
handle_failed_output(&format!("{:#?}", self.cmd), output, caller_line_number);
}
output
}
}
#[derive(Debug)]
pub struct Rustdoc {
cmd: Command,
}
impl Rustdoc {
fn new() -> Self {
let cmd = setup_common_build_cmd("RUSTDOC");
Self { cmd }
}
pub fn arg(&mut self, arg: &str) -> &mut Self {
self.cmd.arg(arg);
self
}
#[track_caller]
pub fn run(&mut self) -> Output {
let caller_location = std::panic::Location::caller();
let caller_line_number = caller_location.line();
let output = self.cmd.output().unwrap();
if !output.status.success() {
handle_failed_output(&format!("{:#?}", self.cmd), output, caller_line_number);
}
output
}
}
fn run_common(bin_name: &str) -> (Command, Output) {
let target = env::var("TARGET").unwrap();
let bin_name =
if target.contains("windows") { format!("{}.exe", bin_name) } else { bin_name.to_owned() };
let mut bin_path = PathBuf::new();
bin_path.push(env::var("TMPDIR").unwrap());
bin_path.push(&bin_name);
let ld_lib_path_envvar = env::var("LD_LIB_PATH_ENVVAR").unwrap();
let mut cmd = Command::new(bin_path);
cmd.env(&ld_lib_path_envvar, {
let mut paths = vec![];
paths.push(PathBuf::from(env::var("TMPDIR").unwrap()));
for p in env::split_paths(&env::var("TARGET_RPATH_ENV").unwrap()) {
paths.push(p.to_path_buf());
}
for p in env::split_paths(&env::var(&ld_lib_path_envvar).unwrap()) {
paths.push(p.to_path_buf());
}
env::join_paths(paths.iter()).unwrap()
});
if target.contains("windows") {
let mut paths = vec![];
for p in env::split_paths(&std::env::var("PATH").unwrap_or(String::new())) {
paths.push(p.to_path_buf());
}
paths.push(Path::new(&std::env::var("TARGET_RPATH_DIR").unwrap()).to_path_buf());
cmd.env("PATH", env::join_paths(paths.iter()).unwrap());
}
let output = cmd.output().unwrap();
(cmd, output)
}
/// Run a built binary and make sure it succeeds.
#[track_caller]
pub fn run(bin_name: &str) -> Output {
let caller_location = std::panic::Location::caller();
let caller_line_number = caller_location.line();
let (cmd, output) = run_common(bin_name);
if !output.status.success() {
handle_failed_output(&format!("{:#?}", cmd), output, caller_line_number);
}
output
}
/// Run a built binary and make sure it fails.
#[track_caller]
pub fn run_fail(bin_name: &str) -> Output {
let caller_location = std::panic::Location::caller();
let caller_line_number = caller_location.line();
let (cmd, output) = run_common(bin_name);
if output.status.success() {
handle_failed_output(&format!("{:#?}", cmd), output, caller_line_number);
}
output
}

View File

@ -0,0 +1,67 @@
use std::env;
use std::path::{Path, PathBuf};
use std::process::{Command, Output};
use super::handle_failed_output;
fn run_common(bin_name: &str) -> (Command, Output) {
let target = env::var("TARGET").unwrap();
let bin_name =
if target.contains("windows") { format!("{}.exe", bin_name) } else { bin_name.to_owned() };
let mut bin_path = PathBuf::new();
bin_path.push(env::var("TMPDIR").unwrap());
bin_path.push(&bin_name);
let ld_lib_path_envvar = env::var("LD_LIB_PATH_ENVVAR").unwrap();
let mut cmd = Command::new(bin_path);
cmd.env(&ld_lib_path_envvar, {
let mut paths = vec![];
paths.push(PathBuf::from(env::var("TMPDIR").unwrap()));
for p in env::split_paths(&env::var("TARGET_RPATH_ENV").unwrap()) {
paths.push(p.to_path_buf());
}
for p in env::split_paths(&env::var(&ld_lib_path_envvar).unwrap()) {
paths.push(p.to_path_buf());
}
env::join_paths(paths.iter()).unwrap()
});
if target.contains("windows") {
let mut paths = vec![];
for p in env::split_paths(&std::env::var("PATH").unwrap_or(String::new())) {
paths.push(p.to_path_buf());
}
paths.push(Path::new(&std::env::var("TARGET_RPATH_DIR").unwrap()).to_path_buf());
cmd.env("PATH", env::join_paths(paths.iter()).unwrap());
}
let output = cmd.output().unwrap();
(cmd, output)
}
/// Run a built binary and make sure it succeeds.
#[track_caller]
pub fn run(bin_name: &str) -> Output {
let caller_location = std::panic::Location::caller();
let caller_line_number = caller_location.line();
let (cmd, output) = run_common(bin_name);
if !output.status.success() {
handle_failed_output(&format!("{:#?}", cmd), output, caller_line_number);
}
output
}
/// Run a built binary and make sure it fails.
#[track_caller]
pub fn run_fail(bin_name: &str) -> Output {
let caller_location = std::panic::Location::caller();
let caller_line_number = caller_location.line();
let (cmd, output) = run_common(bin_name);
if output.status.success() {
handle_failed_output(&format!("{:#?}", cmd), output, caller_line_number);
}
output
}

View File

@ -0,0 +1,147 @@
use std::env;
use std::path::Path;
use std::process::{Command, Output};
use crate::{handle_failed_output, tmp_dir};
/// Construct a new `rustc` invocation.
pub fn rustc() -> Rustc {
Rustc::new()
}
/// Construct a new `rustc` aux-build invocation.
pub fn aux_build() -> Rustc {
Rustc::new_aux_build()
}
/// A `rustc` invocation builder.
#[derive(Debug)]
pub struct Rustc {
cmd: Command,
}
fn setup_common() -> Command {
let rustc = env::var("RUSTC").unwrap();
let mut cmd = Command::new(rustc);
cmd.arg("--out-dir").arg(tmp_dir()).arg("-L").arg(tmp_dir());
cmd
}
impl Rustc {
// `rustc` invocation constructor methods
/// Construct a new `rustc` invocation.
pub fn new() -> Self {
let cmd = setup_common();
Self { cmd }
}
/// Construct a new `rustc` invocation with `aux_build` preset (setting `--crate-type=lib`).
pub fn new_aux_build() -> Self {
let mut cmd = setup_common();
cmd.arg("--crate-type=lib");
Self { cmd }
}
// Argument provider methods
/// Configure the compilation environment.
pub fn cfg(&mut self, s: &str) -> &mut Self {
self.cmd.arg("--cfg");
self.cmd.arg(s);
self
}
/// Specify default optimization level `-O` (alias for `-C opt-level=2`).
pub fn opt(&mut self) -> &mut Self {
self.cmd.arg("-O");
self
}
/// Specify type(s) of output files to generate.
pub fn emit(&mut self, kinds: &str) -> &mut Self {
self.cmd.arg(format!("--emit={kinds}"));
self
}
/// Specify where an external library is located.
pub fn extern_<P: AsRef<Path>>(&mut self, crate_name: &str, path: P) -> &mut Self {
assert!(
!crate_name.contains(|c: char| c.is_whitespace() || c == '\\' || c == '/'),
"crate name cannot contain whitespace or path separators"
);
let path = path.as_ref().to_string_lossy();
self.cmd.arg("--extern");
self.cmd.arg(format!("{crate_name}={path}"));
self
}
/// Specify path to the input file.
pub fn input<P: AsRef<Path>>(&mut self, path: P) -> &mut Self {
self.cmd.arg(path.as_ref());
self
}
/// Specify target triple.
pub fn target(&mut self, target: &str) -> &mut Self {
assert!(!target.contains(char::is_whitespace), "target triple cannot contain spaces");
self.cmd.arg(format!("--target={target}"));
self
}
/// Generic command argument provider. Use `.arg("-Zname")` over `.arg("-Z").arg("arg")`.
/// This method will panic if a plain `-Z` or `-C` is passed, or if `-Z <name>` or `-C <name>`
/// is passed (note the space).
pub fn arg(&mut self, arg: &str) -> &mut Self {
assert!(
!(["-Z", "-C"].contains(&arg) || arg.starts_with("-Z ") || arg.starts_with("-C ")),
"use `-Zarg` or `-Carg` over split `-Z` `arg` or `-C` `arg`"
);
self.cmd.arg(arg);
self
}
/// Generic command arguments provider. Use `.arg("-Zname")` over `.arg("-Z").arg("arg")`.
/// This method will panic if a plain `-Z` or `-C` is passed, or if `-Z <name>` or `-C <name>`
/// is passed (note the space).
pub fn args(&mut self, args: &[&str]) -> &mut Self {
for arg in args {
assert!(
!(["-Z", "-C"].contains(&arg) || arg.starts_with("-Z ") || arg.starts_with("-C ")),
"use `-Zarg` or `-Carg` over split `-Z` `arg` or `-C` `arg`"
);
}
self.cmd.args(args);
self
}
// Command inspection, output and running helper methods
/// Get the [`Output`][std::process::Output] of the finished `rustc` process.
pub fn output(&mut self) -> Output {
self.cmd.output().unwrap()
}
/// Run the constructed `rustc` command and assert that it is successfully run.
#[track_caller]
pub fn run(&mut self) -> Output {
let caller_location = std::panic::Location::caller();
let caller_line_number = caller_location.line();
let output = self.cmd.output().unwrap();
if !output.status.success() {
handle_failed_output(&format!("{:#?}", self.cmd), output, caller_line_number);
}
output
}
/// Inspect what the underlying [`Command`] is up to the current construction.
pub fn inspect(&mut self, f: impl FnOnce(&Command)) -> &mut Self {
f(&self.cmd);
self
}
}

View File

@ -0,0 +1,80 @@
use std::env;
use std::path::Path;
use std::process::{Command, Output};
use crate::handle_failed_output;
/// Construct a plain `rustdoc` invocation with no flags set.
pub fn bare_rustdoc() -> Rustdoc {
Rustdoc::bare()
}
/// Construct a new `rustdoc` invocation with `-L $(TARGET_RPATH_DIR)` set.
pub fn rustdoc() -> Rustdoc {
Rustdoc::new()
}
#[derive(Debug)]
pub struct Rustdoc {
cmd: Command,
}
fn setup_common() -> Command {
let rustdoc = env::var("RUSTDOC").unwrap();
Command::new(rustdoc)
}
impl Rustdoc {
/// Construct a bare `rustdoc` invocation.
pub fn bare() -> Self {
let cmd = setup_common();
Self { cmd }
}
/// Construct a `rustdoc` invocation with `-L $(TARGET_RPATH_DIR)` set.
pub fn new() -> Self {
let mut cmd = setup_common();
let target_rpath_dir = env::var_os("TARGET_RPATH_DIR").unwrap();
cmd.arg(format!("-L{}", target_rpath_dir.to_string_lossy()));
Self { cmd }
}
/// Specify path to the input file.
pub fn input<P: AsRef<Path>>(&mut self, path: P) -> &mut Self {
self.cmd.arg(path.as_ref());
self
}
/// Specify output directory.
pub fn out_dir<P: AsRef<Path>>(&mut self, path: P) -> &mut Self {
self.cmd.arg("--out-dir").arg(path.as_ref());
self
}
/// Given a `path`, pass `@{path}` to `rustdoc` as an
/// [arg file](https://doc.rust-lang.org/rustdoc/command-line-arguments.html#path-load-command-line-flags-from-a-path).
pub fn arg_file<P: AsRef<Path>>(&mut self, path: P) -> &mut Self {
self.cmd.arg(format!("@{}", path.as_ref().display()));
self
}
/// Fallback argument provider. Consider adding meaningfully named methods instead of using
/// this method.
pub fn arg(&mut self, arg: &str) -> &mut Self {
self.cmd.arg(arg);
self
}
/// Run the build `rustdoc` command and assert that the run is successful.
#[track_caller]
pub fn run(&mut self) -> Output {
let caller_location = std::panic::Location::caller();
let caller_line_number = caller_location.line();
let output = self.cmd.output().unwrap();
if !output.status.success() {
handle_failed_output(&format!("{:#?}", self.cmd), output, caller_line_number);
}
output
}
}

View File

@ -1,24 +1,25 @@
// ignore-tidy-linelength
// Check that the `CURRENT_RUSTC_VERSION` placeholder is correctly replaced by the current
// `rustc` version and the `since` property in feature stability gating is properly respected.
extern crate run_make_support;
use std::path::PathBuf;
use run_make_support::{aux_build, rustc};
use run_make_support::{rustc, aux_build};
fn main() {
aux_build()
.arg("--emit=metadata")
.arg("stable.rs")
.run();
aux_build().input("stable.rs").emit("metadata").run();
let mut stable_path = PathBuf::from(env!("TMPDIR"));
stable_path.push("libstable.rmeta");
let output = rustc()
.arg("--emit=metadata")
.arg("--extern")
.arg(&format!("stable={}", &stable_path.to_string_lossy()))
.arg("main.rs")
.run();
.input("main.rs")
.emit("metadata")
.extern_("stable", &stable_path)
.output();
let stderr = String::from_utf8_lossy(&output.stderr);
let version = include_str!(concat!(env!("S"), "/src/version"));

View File

@ -1,44 +1,36 @@
// ignore-tidy-linelength
// Test that if we build `b` against a version of `a` that has one set of types, it will not run
// with a dylib that has a different set of types.
extern crate run_make_support;
use run_make_support::{run, run_fail, rustc};
fn main() {
rustc()
.arg("a.rs")
.arg("--cfg")
.arg("x")
.arg("-C")
.arg("prefer-dynamic")
.arg("-Z")
.arg("unstable-options")
.arg("-C")
.arg("symbol-mangling-version=legacy")
.input("a.rs")
.cfg("x")
.arg("-Zunstable-options")
.arg("-Cprefer-dynamic")
.arg("-Csymbol-mangling-version=legacy")
.run();
rustc()
.arg("b.rs")
.arg("-C")
.arg("prefer-dynamic")
.arg("-Z")
.arg("unstable-options")
.arg("-C")
.arg("symbol-mangling-version=legacy")
.run();
.input("b.rs")
.arg("-Zunstable-options")
.arg("-Cprefer-dynamic")
.arg("-Csymbol-mangling-version=legacy")
.run();
run("b");
rustc()
.arg("a.rs")
.arg("--cfg")
.arg("y")
.arg("-C")
.arg("prefer-dynamic")
.arg("-Z")
.arg("unstable-options")
.arg("-C")
.arg("symbol-mangling-version=legacy")
.input("a.rs")
.cfg("y")
.arg("-Zunstable-options")
.arg("-Cprefer-dynamic")
.arg("-Csymbol-mangling-version=legacy")
.run();
run_fail("b");

View File

@ -18,7 +18,7 @@ use run_make_support::object::read::Object;
use run_make_support::object::ObjectSection;
use run_make_support::object::ObjectSymbol;
use run_make_support::object::RelocationTarget;
use run_make_support::out_dir;
use run_make_support::tmp_dir;
use std::collections::HashSet;
const MANIFEST: &str = r#"
@ -31,7 +31,7 @@ edition = "2021"
path = "lib.rs""#;
fn main() {
let target_dir = out_dir().join("target");
let target_dir = tmp_dir().join("target");
let target = std::env::var("TARGET").unwrap();
if target.starts_with("wasm") || target.starts_with("nvptx") {
// wasm and nvptx targets don't produce rlib files that object can parse.
@ -41,9 +41,9 @@ fn main() {
println!("Testing compiler_builtins for {}", target);
// Set up the tiniest Cargo project: An empty no_std library. Just enough to run -Zbuild-std.
let manifest_path = out_dir().join("Cargo.toml");
let manifest_path = tmp_dir().join("Cargo.toml");
std::fs::write(&manifest_path, MANIFEST.as_bytes()).unwrap();
std::fs::write(out_dir().join("lib.rs"), b"#![no_std]").unwrap();
std::fs::write(tmp_dir().join("lib.rs"), b"#![no_std]").unwrap();
let path = std::env::var("PATH").unwrap();
let rustc = std::env::var("RUSTC").unwrap();

View File

@ -1,8 +1,8 @@
extern crate run_make_support;
use run_make_support::{out_dir, rustdoc};
use std::{fs, iter};
use run_make_support::{rustdoc, tmp_dir};
use std::path::Path;
use std::{fs, iter};
fn generate_a_lot_of_cfgs(path: &Path) {
let content = iter::repeat("--cfg=a\n").take(100_000).collect::<String>();
@ -10,9 +10,8 @@ fn generate_a_lot_of_cfgs(path: &Path) {
}
fn main() {
let arg_file = out_dir().join("args");
let arg_file = tmp_dir().join("args");
generate_a_lot_of_cfgs(&arg_file);
let arg_file = format!("@{}", arg_file.display());
rustdoc().arg("--test").arg(&arg_file).arg("foo.rs").run();
rustdoc().out_dir(tmp_dir()).input("foo.rs").arg_file(&arg_file).arg("--test").run();
}

View File

@ -1,6 +1,6 @@
extern crate run_make_support;
use run_make_support::{out_dir, rustc};
use run_make_support::{rustc, tmp_dir};
use std::path::Path;
use std::process::Command;
@ -9,8 +9,9 @@ fn main() {
return;
}
rustc().arg("foo.rs").arg("--target=wasm32-wasip1").run();
let file = out_dir().join("foo.wasm");
rustc().input("foo.rs").target("wasm32-wasip1").run();
let file = tmp_dir().join("foo.wasm");
let has_wasmtime = match Command::new("wasmtime").arg("--version").output() {
Ok(s) => s.status.success(),

View File

@ -1,6 +1,6 @@
extern crate run_make_support;
use run_make_support::{out_dir, rustc, wasmparser};
use run_make_support::{rustc, tmp_dir, wasmparser};
use std::collections::HashMap;
fn main() {
@ -8,10 +8,10 @@ fn main() {
return;
}
rustc().arg("foo.rs").arg("--target=wasm32-wasip1").run();
rustc().arg("bar.rs").arg("--target=wasm32-wasip1").arg("-Clto").arg("-O").run();
rustc().input("foo.rs").target("wasm32-wasip1").run();
rustc().input("bar.rs").target("wasm32-wasip1").arg("-Clto").opt().run();
let file = std::fs::read(&out_dir().join("bar.wasm")).unwrap();
let file = std::fs::read(&tmp_dir().join("bar.wasm")).unwrap();
let mut custom = HashMap::new();
for payload in wasmparser::Parser::new(0).parse_all(&file) {

View File

@ -1,6 +1,6 @@
extern crate run_make_support;
use run_make_support::{out_dir, rustc, wasmparser};
use run_make_support::{tmp_dir, wasmparser, rustc};
use std::collections::HashMap;
use std::path::Path;
@ -9,8 +9,9 @@ fn main() {
return;
}
rustc().arg("foo.rs").arg("--target=wasm32-wasip1").arg("-O").run();
verify(&out_dir().join("foo.wasm"));
rustc().input("foo.rs").target("wasm32-wasip1").opt().run();
verify(&tmp_dir().join("foo.wasm"));
}
fn verify(path: &Path) {

View File

@ -1,6 +1,6 @@
extern crate run_make_support;
use run_make_support::{out_dir, rustc, wasmparser};
use run_make_support::{tmp_dir, wasmparser, rustc};
use std::collections::HashMap;
use std::path::Path;
use wasmparser::ExternalKind::*;
@ -17,16 +17,17 @@ fn main() {
fn test(args: &[&str]) {
eprintln!("running with {args:?}");
rustc().arg("bar.rs").arg("--target=wasm32-wasip1").args(args).run();
rustc().arg("foo.rs").arg("--target=wasm32-wasip1").args(args).run();
rustc().arg("main.rs").arg("--target=wasm32-wasip1").args(args).run();
rustc().input("bar.rs").target("wasm32-wasip1").args(args).run();
rustc().input("foo.rs").target("wasm32-wasip1").args(args).run();
rustc().input("main.rs").target("wasm32-wasip1").args(args).run();
verify_exports(
&out_dir().join("foo.wasm"),
&tmp_dir().join("foo.wasm"),
&[("foo", Func), ("FOO", Global), ("memory", Memory)],
);
verify_exports(
&out_dir().join("main.wasm"),
&tmp_dir().join("main.wasm"),
&[
("foo", Func),
("FOO", Global),

View File

@ -1,6 +1,6 @@
extern crate run_make_support;
use run_make_support::{out_dir, rustc, wasmparser};
use run_make_support::{tmp_dir, wasmparser, rustc};
use std::collections::HashMap;
use wasmparser::TypeRef::Func;
@ -9,10 +9,15 @@ fn main() {
return;
}
rustc().arg("foo.rs").arg("--target=wasm32-wasip1").run();
rustc().arg("bar.rs").arg("--target=wasm32-wasip1").arg("-Clto").arg("-O").run();
rustc().input("foo.rs").target("wasm32-wasip1").run();
rustc()
.input("bar.rs")
.target("wasm32-wasip1")
.arg("-Clto")
.opt()
.run();
let file = std::fs::read(&out_dir().join("bar.wasm")).unwrap();
let file = std::fs::read(&tmp_dir().join("bar.wasm")).unwrap();
let mut imports = HashMap::new();
for payload in wasmparser::Parser::new(0).parse_all(&file) {

View File

@ -2,7 +2,7 @@
extern crate run_make_support;
use run_make_support::{out_dir, rustc};
use run_make_support::{rustc, tmp_dir};
fn main() {
if std::env::var("TARGET").unwrap() != "wasm32-wasip1" {
@ -17,16 +17,10 @@ fn main() {
fn test(cfg: &str) {
eprintln!("running cfg {cfg:?}");
rustc()
.arg("foo.rs")
.arg("--target=wasm32-wasip1")
.arg("-Clto")
.arg("-O")
.arg("--cfg")
.arg(cfg)
.run();
let bytes = std::fs::read(&out_dir().join("foo.wasm")).unwrap();
rustc().input("foo.rs").target("wasm32-wasip1").arg("-Clto").opt().cfg(cfg).run();
let bytes = std::fs::read(&tmp_dir().join("foo.wasm")).unwrap();
println!("{}", bytes.len());
assert!(bytes.len() < 40_000);
}

View File

@ -1,8 +1,7 @@
extern crate run_make_support;
use run_make_support::{out_dir, rustc, wasmparser};
use run_make_support::{rustc, tmp_dir, wasmparser};
use std::collections::HashMap;
use wasmparser::TypeRef::Func;
fn main() {
if std::env::var("TARGET").unwrap() != "wasm32-wasip1" {
@ -10,15 +9,15 @@ fn main() {
}
rustc()
.arg("main.rs")
.arg("--target=wasm32-wasip1")
.arg("-Coverflow-checks=yes")
.input("main.rs")
.target("wasm32-wasip1")
.arg("-Coverflow-checks")
.arg("-Cpanic=abort")
.arg("-Clto")
.arg("-Copt-level=z")
.run();
let file = std::fs::read(&out_dir().join("main.wasm")).unwrap();
let file = std::fs::read(&tmp_dir().join("main.wasm")).unwrap();
let mut imports = HashMap::new();
for payload in wasmparser::Parser::new(0).parse_all(&file) {

View File

@ -2,16 +2,16 @@
extern crate run_make_support;
use run_make_support::{out_dir, rustc};
use run_make_support::{rustc, tmp_dir};
fn main() {
if std::env::var("TARGET").unwrap() != "wasm32-wasip1" {
return;
}
rustc().arg("foo.rs").arg("--target=wasm32-wasip1").arg("-Clto").arg("-O").run();
rustc().input("foo.rs").target("wasm32-wasip1").arg("-Clto").opt().run();
let bytes = std::fs::read(&out_dir().join("foo.wasm")).unwrap();
let bytes = std::fs::read(&tmp_dir().join("foo.wasm")).unwrap();
println!("{}", bytes.len());
assert!(bytes.len() < 50_000);
}

View File

@ -1,6 +1,6 @@
extern crate run_make_support;
use run_make_support::{out_dir, rustc, wasmparser};
use run_make_support::{rustc, tmp_dir, wasmparser};
use std::collections::{HashMap, HashSet};
fn main() {
@ -24,9 +24,9 @@ fn test_file(file: &str, expected_imports: &[(&str, &[&str])]) {
fn test(file: &str, args: &[&str], expected_imports: &[(&str, &[&str])]) {
println!("test {file:?} {args:?} for {expected_imports:?}");
rustc().arg(file).arg("--target=wasm32-wasip1").args(args).run();
rustc().input(file).target("wasm32-wasip1").args(args).run();
let file = std::fs::read(&out_dir().join(file).with_extension("wasm")).unwrap();
let file = std::fs::read(&tmp_dir().join(file).with_extension("wasm")).unwrap();
let mut imports = HashMap::new();
for payload in wasmparser::Parser::new(0).parse_all(&file) {

View File

@ -1,6 +1,6 @@
extern crate run_make_support;
use run_make_support::{out_dir, rustc, wasmparser};
use run_make_support::{rustc, tmp_dir, wasmparser};
use std::path::Path;
fn main() {
@ -8,15 +8,15 @@ fn main() {
return;
}
rustc().arg("foo.rs").arg("--target=wasm32-wasip1").run();
verify_symbols(&out_dir().join("foo.wasm"));
rustc().arg("foo.rs").arg("--target=wasm32-wasip1").arg("-O").run();
verify_symbols(&out_dir().join("foo.wasm"));
rustc().input("foo.rs").target("wasm32-wasip1").run();
verify_symbols(&tmp_dir().join("foo.wasm"));
rustc().input("foo.rs").target("wasm32-wasip1").opt().run();
verify_symbols(&tmp_dir().join("foo.wasm"));
rustc().arg("bar.rs").arg("--target=wasm32-wasip1").run();
verify_symbols(&out_dir().join("bar.wasm"));
rustc().arg("bar.rs").arg("--target=wasm32-wasip1").arg("-O").run();
verify_symbols(&out_dir().join("bar.wasm"));
rustc().input("bar.rs").target("wasm32-wasip1").run();
verify_symbols(&tmp_dir().join("bar.wasm"));
rustc().input("bar.rs").target("wasm32-wasip1").opt().run();
verify_symbols(&tmp_dir().join("bar.wasm"));
}
fn verify_symbols(path: &Path) {

View File

@ -1,6 +1,6 @@
extern crate run_make_support;
use run_make_support::{out_dir, rustc, wasmparser};
use run_make_support::{rustc, tmp_dir, wasmparser};
use std::path::Path;
fn main() {
@ -8,14 +8,14 @@ fn main() {
return;
}
rustc().arg("foo.rs").arg("--target=wasm32-wasip1").run();
verify_symbols(&out_dir().join("foo.wasm"));
rustc().arg("foo.rs").arg("--target=wasm32-wasip1").arg("-Clto").run();
verify_symbols(&out_dir().join("foo.wasm"));
rustc().arg("foo.rs").arg("--target=wasm32-wasip1").arg("-O").run();
verify_symbols(&out_dir().join("foo.wasm"));
rustc().arg("foo.rs").arg("--target=wasm32-wasip1").arg("-Clto").arg("-O").run();
verify_symbols(&out_dir().join("foo.wasm"));
rustc().input("foo.rs").target("wasm32-wasip1").run();
verify_symbols(&tmp_dir().join("foo.wasm"));
rustc().input("foo.rs").target("wasm32-wasip1").arg("-Clto").run();
verify_symbols(&tmp_dir().join("foo.wasm"));
rustc().input("foo.rs").target("wasm32-wasip1").opt().run();
verify_symbols(&tmp_dir().join("foo.wasm"));
rustc().input("foo.rs").target("wasm32-wasip1").arg("-Clto").opt().run();
verify_symbols(&tmp_dir().join("foo.wasm"));
}
fn verify_symbols(path: &Path) {