diff --git a/programs/bpf/tests/programs.rs b/programs/bpf/tests/programs.rs index 4b8a07a1ff..853f85d163 100644 --- a/programs/bpf/tests/programs.rs +++ b/programs/bpf/tests/programs.rs @@ -1369,19 +1369,19 @@ fn assert_instruction_count() { #[cfg(feature = "bpf_c")] { programs.extend_from_slice(&[ - ("alloc", 1137), - ("bpf_to_bpf", 13), - ("multiple_static", 8), - ("noop", 42), - ("noop++", 42), - ("relative_call", 10), - ("return_data", 480), - ("sanity", 174), - ("sanity++", 174), - ("secp256k1_recover", 357), - ("sha", 694), - ("struct_pass", 8), - ("struct_ret", 22), + ("alloc", 1237), + ("bpf_to_bpf", 96), + ("multiple_static", 52), + ("noop", 5), + ("noop++", 5), + ("relative_call", 26), + ("return_data", 980), + ("sanity", 1255), + ("sanity++", 1260), + ("secp256k1_recover", 25383), + ("sha", 1328), + ("struct_pass", 108), + ("struct_ret", 28), ]); } #[cfg(feature = "bpf_rust")] diff --git a/sdk/bpf/scripts/install.sh b/sdk/bpf/scripts/install.sh index 6e88c1c463..c94d51edab 100755 --- a/sdk/bpf/scripts/install.sh +++ b/sdk/bpf/scripts/install.sh @@ -92,7 +92,7 @@ if [[ ! -e criterion-$version.md || ! -e criterion ]]; then fi # Install Rust-BPF -version=v1.12 +version=v1.19 if [[ ! -e bpf-tools-$version.md || ! -e bpf-tools ]]; then ( set -e diff --git a/sdk/cargo-build-bpf/src/main.rs b/sdk/cargo-build-bpf/src/main.rs index a86fb167a9..247e4b8a8d 100644 --- a/sdk/cargo-build-bpf/src/main.rs +++ b/sdk/cargo-build-bpf/src/main.rs @@ -58,7 +58,7 @@ where S: AsRef, { let args = args.into_iter().collect::>(); - print!("Running: {}", program.display()); + print!("cargo-build-bpf child: {}", program.display()); for arg in args.iter() { print!(" {}", arg.as_ref().to_str().unwrap_or("?")); } @@ -92,19 +92,24 @@ fn install_if_missing( version: &str, url: &str, download_file_name: &str, + target_path: &Path, ) -> Result<(), String> { + // Check whether the target path is an empty directory. This can + // happen if package download failed on previous run of + // cargo-build-bpf. Remove the target_path directory in this + // case. + if target_path.is_dir() + && target_path + .read_dir() + .map_err(|err| err.to_string())? + .next() + .is_none() + { + fs::remove_dir(&target_path).map_err(|err| err.to_string())?; + } + // Check whether the package is already in ~/.cache/solana. // Download it and place in the proper location if not found. - let home_dir = PathBuf::from(env::var("HOME").unwrap_or_else(|err| { - eprintln!("Can't get home directory path: {}", err); - exit(1); - })); - let target_path = home_dir - .join(".cache") - .join("solana") - .join(version) - .join(package); - if !target_path.is_dir() && !target_path .symlink_metadata() @@ -142,7 +147,7 @@ fn install_if_missing( let source_path = source_base.join(package); // Check whether the correct symbolic link exists. let invalid_link = if let Ok(link_target) = source_path.read_link() { - if link_target != target_path { + if link_target.ne(target_path) { fs::remove_file(&source_path).map_err(|err| err.to_string())?; true } else { @@ -430,14 +435,41 @@ fn build_bpf_package(config: &Config, target_directory: &Path, package: &cargo_m } else { "solana-bpf-tools-linux.tar.bz2" }; + + let home_dir = PathBuf::from(env::var("HOME").unwrap_or_else(|err| { + eprintln!("Can't get home directory path: {}", err); + exit(1); + })); + let version = "v1.19"; + let package = "bpf-tools"; + let target_path = home_dir + .join(".cache") + .join("solana") + .join(version) + .join(package); install_if_missing( config, - "bpf-tools", - "v1.12", + package, + version, "https://github.com/solana-labs/bpf-tools/releases/download", bpf_tools_download_file_name, + &target_path, ) - .expect("Failed to install bpf-tools"); + .unwrap_or_else(|err| { + // The package version directory doesn't contain a valid + // installation, and it should be removed. + let target_path_parent = target_path.parent().expect("Invalid package path"); + fs::remove_dir_all(&target_path_parent).unwrap_or_else(|err| { + eprintln!( + "Failed to remove {} while recovering from installation failure: {}", + target_path_parent.to_string_lossy(), + err, + ); + exit(1); + }); + eprintln!("Failed to install bpf-tools: {}", err); + exit(1); + }); link_bpf_toolchain(config); let llvm_bin = config @@ -450,9 +482,20 @@ fn build_bpf_package(config: &Config, target_directory: &Path, package: &cargo_m env::set_var("AR", llvm_bin.join("llvm-ar")); env::set_var("OBJDUMP", llvm_bin.join("llvm-objdump")); env::set_var("OBJCOPY", llvm_bin.join("llvm-objcopy")); - let mut rust_flags = String::from("-C lto=no"); - rust_flags.push_str(" -C opt-level=2"); - env::set_var("RUSTFLAGS", rust_flags); + let rustflags = match env::var("RUSTFLAGS") { + Ok(rf) => { + if rf.contains("-C lto=no") { + rf + } else { + rf + &" -C lto=no".to_string() + } + } + _ => "-C lto=no".to_string(), + }; + if config.verbose { + println!("RUSTFLAGS={}", rustflags); + } + env::set_var("RUSTFLAGS", rustflags); let cargo_build = PathBuf::from("cargo"); let mut cargo_build_args = vec![ "+bpf",