//! 检查真实 CLI 和 ELF;交叉执行由目标机器验收,不把宿主执行当作目标执行。 use super::*; use dever::compiler::build::Target; #[test] fn build_target_is_explicit_and_invalid_targets_stop_before_loading() { for arguments in [ vec![ "build", "missing", "--target", "windows", "--output", "unused", ], vec!["build", "missing", "--target"], vec!["run", "missing", "--target", "linux-aarch64"], vec![ "build", "missing", "--target", "linux-aarch64", "--target", "linux-x86_64", ], ] { let output = cli(&arguments); assert!(!output.status.success()); assert!(!String::from_utf8_lossy(&output.stderr).contains("No such file")); } let root = directory("native-target").join("hello"); let source = root.to_str().unwrap(); success(cli(&["new", source])); let target = format!("linux-{}", Target::host().unwrap().arch()); let binary = root.join("program"); success(cli(&[ "build", source, "--target", &target, "--profile", "dev", "--output", binary.to_str().unwrap(), ])); let response = success( Command::new(&binary) .args(["hello.greeting.greet", r#"{"name":"target"}"#]) .output() .unwrap(), ); assert_eq!( serde_json::from_str::(&response).unwrap()["data"], "Hello, target" ); let repeated = cli(&[ "build", source, "--target", &target, "--profile", "dev", "--output", binary.to_str().unwrap(), ]); assert!( !repeated.status.success(), "published files must not be overwritten" ); } #[test] #[ignore = "requires the official Rust 1.95 aarch64 standard library and a configured C cross linker"] fn aarch64_build_produces_target_elf_and_keeps_native_cache_separate() { assert_eq!(Target::host().unwrap(), Target::LinuxX86_64); let root = directory("cross-target").join("hello"); let source = root.to_str().unwrap(); success(cli(&["new", source])); let binary = root.join("arm-program"); success(cli(&[ "build", source, "--target", "linux-aarch64", "--profile", "dev", "--output", binary.to_str().unwrap(), ])); let bytes = fs::read(&binary).unwrap(); let elf = goblin::elf::Elf::parse(&bytes).unwrap(); assert_eq!(elf.header.e_machine, goblin::elf::header::EM_AARCH64); assert!(elf.is_64 && elf.little_endian && elf.entry != 0); let result = success(cli(&[ "run", source, "--", "hello.greeting.greet", r#"{"name":"native"}"#, ])); assert_eq!( serde_json::from_str::(&result).unwrap()["data"], "Hello, native" ); }