diff --git a/Cargo.lock b/Cargo.lock index c335bbb3..2bd4b735 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -109,7 +109,7 @@ dependencies = [ "regex", "rustc-hash", "shlex", - "syn 2.0.63", + "syn 2.0.96", "which", ] @@ -231,7 +231,7 @@ dependencies = [ "heck", "proc-macro2", "quote", - "syn 2.0.63", + "syn 2.0.96", ] [[package]] @@ -279,7 +279,16 @@ version = "5.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "44c45a9d03d6676652bcb5e724c7e988de1acad23a711b5217ab9cbecbec2225" dependencies = [ - "dirs-sys", + "dirs-sys 0.4.1", +] + +[[package]] +name = "dirs" +version = "6.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c3e8aa94d75141228480295a7d0e7feb620b1a5ad9f12bc40be62411e38cce4e" +dependencies = [ + "dirs-sys 0.5.0", ] [[package]] @@ -290,10 +299,22 @@ checksum = "520f05a5cbd335fae5a99ff7a6ab8627577660ee5cfd6a94a6a929b52ff0321c" dependencies = [ "libc", "option-ext", - "redox_users", + "redox_users 0.4.6", "windows-sys 0.48.0", ] +[[package]] +name = "dirs-sys" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e01a3366d27ee9890022452ee61b2b63a67e6f13f58900b651ff5665f0bb1fab" +dependencies = [ + "libc", + "option-ext", + "redox_users 0.5.0", + "windows-sys 0.59.0", +] + [[package]] name = "doom-host" version = "0.1.0" @@ -602,6 +623,7 @@ dependencies = [ "polkavm-common", "polkavm-linker", "polkavm-linux-raw", + "polkavm-test-data", "ruzstd", "schnellru", ] @@ -638,7 +660,7 @@ dependencies = [ "polkavm-common", "proc-macro2", "quote", - "syn 2.0.63", + "syn 2.0.96", ] [[package]] @@ -646,7 +668,7 @@ name = "polkavm-derive-impl-macro" version = "0.19.0" dependencies = [ "polkavm-derive-impl", - "syn 2.0.63", + "syn 2.0.96", ] [[package]] @@ -666,7 +688,7 @@ name = "polkavm-linker" version = "0.19.0" dependencies = [ "diff", - "dirs", + "dirs 5.0.1", "env_logger", "gimli", "hashbrown 0.14.1", @@ -692,6 +714,14 @@ dependencies = [ "bindgen", ] +[[package]] +name = "polkavm-test-data" +version = "0.19.0" +dependencies = [ + "dirs 6.0.0", + "polkavm-linker", +] + [[package]] name = "ppv-lite86" version = "0.2.17" @@ -705,14 +735,14 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6c64d9ba0963cdcea2e1b2230fbae2bab30eb25a174be395c41e764bfb65dd62" dependencies = [ "proc-macro2", - "syn 2.0.63", + "syn 2.0.96", ] [[package]] name = "proc-macro2" -version = "1.0.82" +version = "1.0.93" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8ad3d49ab951a01fbaafe34f2ec74122942fe18a3f9814c3268f1bb72042131b" +checksum = "60946a68e5f9d28b0dc1c21bb8a97ee7d018a8b322fa57838ba31cc878e22d99" dependencies = [ "unicode-ident", ] @@ -808,7 +838,18 @@ checksum = "ba009ff324d1fc1b900bd1fdb31564febe58a8ccc8a6fdbb93b543d33b13ca43" dependencies = [ "getrandom", "libredox", - "thiserror", + "thiserror 1.0.65", +] + +[[package]] +name = "redox_users" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dd6f9d3d47bdd2ad6945c5015a226ec6155d0bcdfd8f7cd29f86b71f8de99d2b" +dependencies = [ + "getrandom", + "libredox", + "thiserror 2.0.11", ] [[package]] @@ -957,7 +998,7 @@ checksum = "500cbc0ebeb6f46627f50f3f5811ccf6bf00643be300b4c3eabc0ef55dc5b5ba" dependencies = [ "proc-macro2", "quote", - "syn 2.0.63", + "syn 2.0.96", ] [[package]] @@ -1037,9 +1078,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.63" +version = "2.0.96" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bf5be731623ca1a1fb7d8be6f261a3be6d3e2337b8a1f97be944d020c8fcb704" +checksum = "d5d0adab1ae378d7f53bdebc67a39f1f151407ef230f0ce2883572f5d8985c80" dependencies = [ "proc-macro2", "quote", @@ -1065,7 +1106,16 @@ version = "1.0.65" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5d11abd9594d9b38965ef50805c5e469ca9cc6f197f883f717e0269a3057b3d5" dependencies = [ - "thiserror-impl", + "thiserror-impl 1.0.65", +] + +[[package]] +name = "thiserror" +version = "2.0.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d452f284b73e6d76dd36758a0c8684b1d5be31f92b89d07fd5822175732206fc" +dependencies = [ + "thiserror-impl 2.0.11", ] [[package]] @@ -1096,7 +1146,18 @@ checksum = "ae71770322cbd277e69d762a16c444af02aa0575ac0d174f0b9562d3b37f8602" dependencies = [ "proc-macro2", "quote", - "syn 2.0.63", + "syn 2.0.96", +] + +[[package]] +name = "thiserror-impl" +version = "2.0.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "26afc1baea8a989337eeb52b6e72a039780ce45c3edfcc9c5b9d112feeb173c2" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.96", ] [[package]] @@ -1222,7 +1283,16 @@ version = "0.52.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" dependencies = [ - "windows-targets 0.52.4", + "windows-targets 0.52.6", +] + +[[package]] +name = "windows-sys" +version = "0.59.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e38bc4d79ed67fd075bcc251a1c39b32a1776bbe92e5bef1f0bf1f8c531853b" +dependencies = [ + "windows-targets 0.52.6", ] [[package]] @@ -1242,17 +1312,18 @@ dependencies = [ [[package]] name = "windows-targets" -version = "0.52.4" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7dd37b7e5ab9018759f893a1952c9420d060016fc19a472b4bb20d1bdd694d1b" +checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973" dependencies = [ - "windows_aarch64_gnullvm 0.52.4", - "windows_aarch64_msvc 0.52.4", - "windows_i686_gnu 0.52.4", - "windows_i686_msvc 0.52.4", - "windows_x86_64_gnu 0.52.4", - "windows_x86_64_gnullvm 0.52.4", - "windows_x86_64_msvc 0.52.4", + "windows_aarch64_gnullvm 0.52.6", + "windows_aarch64_msvc 0.52.6", + "windows_i686_gnu 0.52.6", + "windows_i686_gnullvm", + "windows_i686_msvc 0.52.6", + "windows_x86_64_gnu 0.52.6", + "windows_x86_64_gnullvm 0.52.6", + "windows_x86_64_msvc 0.52.6", ] [[package]] @@ -1263,9 +1334,9 @@ checksum = "91ae572e1b79dba883e0d315474df7305d12f569b400fcf90581b06062f7e1bc" [[package]] name = "windows_aarch64_gnullvm" -version = "0.52.4" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bcf46cf4c365c6f2d1cc93ce535f2c8b244591df96ceee75d8e83deb70a9cac9" +checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3" [[package]] name = "windows_aarch64_msvc" @@ -1275,9 +1346,9 @@ checksum = "b2ef27e0d7bdfcfc7b868b317c1d32c641a6fe4629c171b8928c7b08d98d7cf3" [[package]] name = "windows_aarch64_msvc" -version = "0.52.4" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "da9f259dd3bcf6990b55bffd094c4f7235817ba4ceebde8e6d11cd0c5633b675" +checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469" [[package]] name = "windows_i686_gnu" @@ -1287,9 +1358,15 @@ checksum = "622a1962a7db830d6fd0a69683c80a18fda201879f0f447f065a3b7467daa241" [[package]] name = "windows_i686_gnu" -version = "0.52.4" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b" + +[[package]] +name = "windows_i686_gnullvm" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b474d8268f99e0995f25b9f095bc7434632601028cf86590aea5c8a5cb7801d3" +checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66" [[package]] name = "windows_i686_msvc" @@ -1299,9 +1376,9 @@ checksum = "4542c6e364ce21bf45d69fdd2a8e455fa38d316158cfd43b3ac1c5b1b19f8e00" [[package]] name = "windows_i686_msvc" -version = "0.52.4" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1515e9a29e5bed743cb4415a9ecf5dfca648ce85ee42e15873c3cd8610ff8e02" +checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66" [[package]] name = "windows_x86_64_gnu" @@ -1311,9 +1388,9 @@ checksum = "ca2b8a661f7628cbd23440e50b05d705db3686f894fc9580820623656af974b1" [[package]] name = "windows_x86_64_gnu" -version = "0.52.4" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5eee091590e89cc02ad514ffe3ead9eb6b660aedca2183455434b93546371a03" +checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78" [[package]] name = "windows_x86_64_gnullvm" @@ -1323,9 +1400,9 @@ checksum = "7896dbc1f41e08872e9d5e8f8baa8fdd2677f29468c4e156210174edc7f7b953" [[package]] name = "windows_x86_64_gnullvm" -version = "0.52.4" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "77ca79f2451b49fa9e2af39f0747fe999fcda4f5e241b2898624dca97a1f2177" +checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d" [[package]] name = "windows_x86_64_msvc" @@ -1335,9 +1412,9 @@ checksum = "1a515f5799fe4961cb532f983ce2b23082366b898e52ffbce459c86f67c8378a" [[package]] name = "windows_x86_64_msvc" -version = "0.52.4" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "32b752e52a2da0ddfbdbcc6fceadfeede4c939ed16d13e648833a61dfb611ed8" +checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" [[package]] name = "yansi" @@ -1362,5 +1439,5 @@ checksum = "15e934569e47891f7d9411f1a451d947a60e000ab3bd24fbb970f000387d1b3b" dependencies = [ "proc-macro2", "quote", - "syn 2.0.63", + "syn 2.0.96", ] diff --git a/Cargo.toml b/Cargo.toml index 3cbd8cf6..373f615b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -10,6 +10,7 @@ members = [ "crates/polkavm-common", "crates/polkavm-linux-raw", "crates/polkavm", + "crates/polkavm-test-data", "crates/simplealloc", @@ -39,10 +40,12 @@ polkavm-derive-impl = { version = "0.19.0", path = "crates/polkavm-derive- polkavm-derive-impl-macro = { version = "0.19.0", path = "crates/polkavm-derive-impl-macro" } polkavm-linker = { version = "0.19.0", path = "crates/polkavm-linker" } polkavm-linux-raw = { version = "0.19.0", path = "crates/polkavm-linux-raw" } +polkavm-test-data = { version = "0.19.0", path = "crates/polkavm-test-data" } blake3 = { version = "1.5.4", default-features = false } clap = "4.4.6" diff = "0.1.13" +dirs = "6.0.0" env_logger = { version = "0.10.0", default-features = false } gimli = { version = "0.31.1", default-features = false } hashbrown = { version = "0.14.1", default-features = false } diff --git a/crates/polkavm-test-data/Cargo.toml b/crates/polkavm-test-data/Cargo.toml new file mode 100644 index 00000000..d36cfea6 --- /dev/null +++ b/crates/polkavm-test-data/Cargo.toml @@ -0,0 +1,15 @@ +[package] +name = "polkavm-test-data" +version.workspace = true +authors.workspace = true +license.workspace = true +edition.workspace = true +rust-version.workspace = true +repository.workspace = true + +[build-dependencies] +dirs = { workspace = true } +polkavm-linker = { workspace = true } + +[lints] +workspace = true diff --git a/crates/polkavm-test-data/build.rs b/crates/polkavm-test-data/build.rs new file mode 100644 index 00000000..47a9d2f6 --- /dev/null +++ b/crates/polkavm-test-data/build.rs @@ -0,0 +1,53 @@ +#![allow(clippy::exit)] + +use std::path::PathBuf; +use std::process::Command; + +fn main() { + println!("cargo:rerun-if-env-changed=OUT_DIR"); + build("test-blob", "no-lto", false); + build("test-blob", "no-lto", true); + build("bench-pinky", "release", false); + build("bench-pinky", "release", true); +} + +fn build(project: &str, profile: &str, target_64bit: bool) { + let path = PathBuf::new().join(std::env!("CARGO_MANIFEST_DIR")).join("../../guest-programs"); + let home = dirs::home_dir().unwrap(); + let rust_flags = std::format!( + "--remap-path-prefix={}= --remap-path-prefix={}=~", + home.to_str().unwrap(), + path.to_str().unwrap() + ); + + let target = if target_64bit { + polkavm_linker::target_json_64_path().unwrap() + } else { + polkavm_linker::target_json_32_path().unwrap() + }; + + let mut cmd = Command::new("cargo"); + cmd.env_clear() + .current_dir(path.to_str().unwrap()) + .env("PATH", std::env!("PATH")) + .env("RUSTFLAGS", rust_flags) + .env("RUSTUP_HOME", std::env!("RUSTUP_HOME")) + .arg("build") + .arg("-q") + .arg("--profile") + .arg(profile) + .arg("--bin") + .arg(project) + .arg("-p") + .arg(project) + .arg("--target") + .arg(target) + .arg("-Zbuild-std=core,alloc"); + + let res = cmd.output().unwrap(); + if !res.status.success() { + let err = String::from_utf8_lossy(&res.stderr).to_string(); + println!("cargo::error={err}"); + std::process::exit(1); + } +} diff --git a/crates/polkavm-test-data/src/lib.rs b/crates/polkavm-test-data/src/lib.rs new file mode 100644 index 00000000..69e7316e --- /dev/null +++ b/crates/polkavm-test-data/src/lib.rs @@ -0,0 +1,4 @@ +pub const BENCH_PINKY_32: &[u8] = include_bytes!("../../../guest-programs/target/riscv64emac-unknown-none-polkavm/release/bench-pinky"); +pub const BENCH_PINKY_64: &[u8] = include_bytes!("../../../guest-programs/target/riscv64emac-unknown-none-polkavm/release/bench-pinky"); +pub const TEST_BLOB_32: &[u8] = include_bytes!("../../../guest-programs/target/riscv32emac-unknown-none-polkavm/no-lto/test-blob"); +pub const TEST_BLOB_64: &[u8] = include_bytes!("../../../guest-programs/target/riscv64emac-unknown-none-polkavm/no-lto/test-blob"); diff --git a/crates/polkavm/Cargo.toml b/crates/polkavm/Cargo.toml index 7e58bb43..139ec199 100644 --- a/crates/polkavm/Cargo.toml +++ b/crates/polkavm/Cargo.toml @@ -26,6 +26,7 @@ libc = { workspace = true } env_logger = { workspace = true } polkavm-common = { workspace = true, features = ["export-internals-for-testing"] } polkavm-linker = { workspace = true } +polkavm-test-data = { workspace = true } image = { workspace = true, features = ["tga"] } ruzstd = { workspace = true } paste = { workspace = true } diff --git a/crates/polkavm/src/tests.rs b/crates/polkavm/src/tests.rs index 68a7ecc1..7b009534 100644 --- a/crates/polkavm/src/tests.rs +++ b/crates/polkavm/src/tests.rs @@ -1319,18 +1319,18 @@ fn decompress_zstd(mut bytes: &[u8]) -> Vec { static BLOB_MAP: Mutex>> = Mutex::new(None); -fn get_blob(elf: &'static [u8]) -> ProgramBlob { - get_blob_impl(true, false, elf) +fn get_blob(elf: &'static [u8], decompress: bool) -> ProgramBlob { + get_blob_impl(true, false, decompress, elf) } -fn get_blob_impl(optimize: bool, strip: bool, elf: &'static [u8]) -> ProgramBlob { +fn get_blob_impl(optimize: bool, strip: bool, decompress: bool, elf: &'static [u8]) -> ProgramBlob { let mut blob_map = BLOB_MAP.lock(); let blob_map = blob_map.get_or_insert_with(BTreeMap::new); blob_map .entry((optimize, strip, elf)) .or_insert_with(|| { // This is slow, so cache it. - let elf = decompress_zstd(elf); + let elf = if decompress { decompress_zstd(elf) } else { elf.to_vec() }; let mut config = polkavm_linker::Config::default(); config.set_optimize(optimize); config.set_strip(strip); @@ -1355,7 +1355,7 @@ fn doom(config: Config, elf: &'static [u8]) { const DOOM_WAD: &[u8] = include_bytes!("../../../examples/doom/roms/doom1.wad"); let _ = env_logger::try_init(); - let blob = get_blob(elf); + let blob = get_blob(elf, true /* decompress */); let engine = Engine::new(&config).unwrap(); let mut module_config = ModuleConfig::default(); module_config.set_page_size(16 * 1024); // TODO: Also test with other page sizes. @@ -1507,9 +1507,9 @@ fn pinky_impl(config: Config, is_64_bit: bool) { let _ = env_logger::try_init(); let blob = if !is_64_bit { - get_blob(include_bytes!("../../../test-data/bench-pinky_32.elf.zst")) + get_blob(polkavm_test_data::BENCH_PINKY_32, false /* no decompress */) } else { - get_blob(include_bytes!("../../../test-data/bench-pinky_64.elf.zst")) + get_blob(polkavm_test_data::BENCH_PINKY_64, false /* no decompress */) }; let engine = Engine::new(&config).unwrap(); @@ -1998,14 +1998,15 @@ struct TestInstance { instance: crate::Instance, } -const TEST_BLOB_32_ELF_ZST: &[u8] = include_bytes!("../../../test-data/test-blob_32.elf.zst"); -const TEST_BLOB_64_ELF_ZST: &[u8] = include_bytes!("../../../test-data/test-blob_64.elf.zst"); - impl TestInstance { fn new(config: &Config, optimize: bool, is_64_bit: bool) -> Self { let _ = env_logger::try_init(); - let blob = if is_64_bit { TEST_BLOB_64_ELF_ZST } else { TEST_BLOB_32_ELF_ZST }; - let blob = get_blob_impl(optimize, is_64_bit, blob); + let blob = if is_64_bit { + polkavm_test_data::TEST_BLOB_64 + } else { + polkavm_test_data::TEST_BLOB_32 + }; + let blob = get_blob_impl(optimize, is_64_bit, false, blob); let engine = Engine::new(config).unwrap(); let module = Module::from_blob(&engine, &Default::default(), blob).unwrap(); @@ -2662,7 +2663,7 @@ fn trapping_preserves_all_registers_segfault(config: Config) { fn test_basic_debug_info(raw_blob: &'static [u8]) { let _ = env_logger::try_init(); - let program = get_blob(raw_blob); + let program = get_blob(raw_blob, false /* no decompress */); let entry_point = program.exports().find(|export| export == "read_u32").unwrap().program_counter(); let mut line_program = program.get_debug_line_program_at(entry_point).unwrap().unwrap(); let info = line_program.run().unwrap().unwrap(); @@ -2686,13 +2687,13 @@ fn test_basic_debug_info(raw_blob: &'static [u8]) { #[ignore] #[test] fn test_basic_debug_info_32() { - test_basic_debug_info(TEST_BLOB_32_ELF_ZST); + test_basic_debug_info(polkavm_test_data::TEST_BLOB_32); } #[ignore] #[test] fn test_basic_debug_info_64() { - test_basic_debug_info(TEST_BLOB_64_ELF_ZST); + test_basic_debug_info(polkavm_test_data::TEST_BLOB_64); } #[test] @@ -2759,7 +2760,7 @@ fn module_cache(_config: Config) {} #[cfg(feature = "module-cache")] fn module_cache(mut config: Config) { let _ = env_logger::try_init(); - let blob = get_blob(TEST_BLOB_32_ELF_ZST); + let blob = get_blob(polkavm_test_data::TEST_BLOB_32, false /* no decompress */); config.set_worker_count(0);