Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- use std::env;
- use std::fs;
- use std::path::{Path, PathBuf};
- use std::collections::HashMap;
- fn main() {
- println!("cargo:rerun-if-changed=build.rs");
- println!("cargo:rerun-if-changed=VERSION");
- println!("cargo:rerun-if-changed=ABI_VERSION");
- let manifest_dir = env::var("CARGO_MANIFEST_DIR").unwrap();
- let out_dir = env::var("OUT_DIR").unwrap();
- let target_arch = env::var("CARGO_CFG_TARGET_ARCH").unwrap();
- let target_os = env::var("CARGO_CFG_TARGET_OS").unwrap();
- // Check for developer mode
- let developer_mode = if env::var("DPDK_DEVELOPER_MODE").is_ok() {
- env::var("DPDK_DEVELOPER_MODE") == Ok("true".to_string())
- } else {
- Path::new(&format!("{}/.git", manifest_dir)).exists()
- };
- if developer_mode {
- println!("cargo:warning=## Building in Developer Mode ##");
- }
- // Set up global configuration
- let dpdk_source_root = manifest_dir.clone();
- let dpdk_build_root = out_dir.clone();
- let mut dpdk_conf = HashMap::new();
- let mut dpdk_includes = Vec::new();
- let mut dpdk_libraries = Vec::new();
- let mut dpdk_static_libraries = Vec::new();
- let mut dpdk_shared_lib_deps = Vec::new();
- let mut dpdk_static_lib_deps = Vec::new();
- let mut dpdk_chkinc_headers = Vec::new();
- let mut dpdk_driver_classes = Vec::new();
- let mut dpdk_drivers = Vec::new();
- let mut dpdk_extra_ldflags = Vec::new();
- let mut dpdk_libs_deprecated = Vec::new();
- let mut dpdk_apps_disabled = Vec::new();
- let mut dpdk_apps_enabled = Vec::new();
- let mut dpdk_libs_disabled = Vec::new();
- let mut dpdk_libs_enabled = Vec::new();
- let mut dpdk_drvs_disabled = Vec::new();
- let mut testpmd_drivers_sources = Vec::new();
- let mut testpmd_drivers_deps = Vec::new();
- // Determine architecture subdirectory
- let arch_subdir = match target_arch.as_str() {
- arch if arch.starts_with("x86") => "x86",
- arch if arch.starts_with("arm") || arch.starts_with("aarch") => "arm",
- arch if arch.starts_with("loongarch") => "loongarch",
- arch if arch.starts_with("powerpc") => "ppc",
- arch if arch.starts_with("riscv") => "riscv",
- _ => "unknown",
- };
- // Configure global include directories
- let global_inc = vec![
- format!("{}", dpdk_source_root),
- format!("{}/config", dpdk_source_root),
- format!("{}/lib/eal/include", dpdk_source_root),
- format!("{}/lib/eal/{}/include", dpdk_source_root, target_os),
- format!("{}/lib/eal/{}/include", dpdk_source_root, arch_subdir),
- ];
- for inc_dir in &global_inc {
- println!("cargo:include={}", inc_dir);
- }
- // Add Linux-specific includes
- if target_os == "linux" {
- println!("cargo:include={}/kernel/linux", dpdk_source_root);
- }
- // Configure build tools
- configure_buildtools(&dpdk_source_root, &mut dpdk_conf);
- // Configure main build options
- configure_build(&dpdk_source_root, &mut dpdk_conf, arch_subdir, &target_os);
- // Build libraries
- build_libraries(&dpdk_source_root, &mut dpdk_libs_enabled, &mut dpdk_libs_disabled);
- // Build drivers
- build_drivers(&dpdk_source_root, &mut dpdk_driver_classes, &mut dpdk_drivers, &mut dpdk_drvs_disabled);
- // Build user tools
- build_usertools(&dpdk_source_root, &mut dpdk_apps_enabled, &mut dpdk_apps_disabled);
- // Build applications
- build_applications(&dpdk_source_root, &mut dpdk_apps_enabled, &mut dpdk_apps_disabled);
- // Build documentation (stub)
- build_documentation(&dpdk_source_root);
- // Build examples (stub)
- build_examples(&dpdk_source_root);
- // Build kernel modules (stub)
- build_kernel_modules(&dpdk_source_root);
- // Check header includes if requested
- if env::var("DPDK_CHECK_INCLUDES").is_ok() {
- check_header_includes(&dpdk_source_root);
- }
- // Generate build configuration header
- generate_build_config(&out_dir, &dpdk_conf);
- // Generate pkg-config files
- generate_pkg_config(&dpdk_source_root, &out_dir);
- // Print final build summary
- print_build_summary(&dpdk_apps_enabled, &dpdk_libs_enabled, &dpdk_driver_classes,
- &dpdk_apps_disabled, &dpdk_libs_disabled, &dpdk_drvs_disabled);
- println!("DPDK build config complete:");
- println!(" source path = \"{}\"", dpdk_source_root);
- println!(" build path = \"{}\"", dpdk_build_root);
- }
- fn configure_buildtools(source_root: &str, conf: &mut HashMap<String, String>) {
- // Stub for buildtools configuration
- conf.insert("BUILDTOOLS_CONFIGURED".to_string(), "true".to_string());
- }
- fn configure_build(source_root: &str, conf: &mut HashMap<String, String>, arch: &str, os: &str) {
- // Read VERSION file
- if let Ok(version) = fs::read_to_string(format!("{}/VERSION", source_root)) {
- conf.insert("RTE_VERSION".to_string(), version.trim().to_string());
- }
- // Read ABI_VERSION file
- if let Ok(abi_version) = fs::read_to_string(format!("{}/ABI_VERSION", source_root)) {
- conf.insert("RTE_ABI_VERSION".to_string(), abi_version.trim().to_string());
- }
- // Set architecture and OS specific configurations
- conf.insert("RTE_ARCH".to_string(), arch.to_string());
- conf.insert("RTE_OS".to_string(), os.to_string());
- conf.insert("RTE_COMPILE_TIME_CPUFLAGS".to_string(), "0".to_string());
- }
- fn build_libraries(source_root: &str, enabled: &mut Vec<String>, disabled: &mut Vec<String>) {
- // Stub implementation - would scan lib/ directory and determine which libraries to build
- let lib_dirs = ["eal", "ring", "mempool", "mbuf", "timer", "pci", "cmdline"];
- for lib in &lib_dirs {
- let lib_path = format!("{}/lib/{}", source_root, lib);
- if Path::new(&lib_path).exists() {
- enabled.push(lib.to_string());
- println!("cargo:rustc-link-lib=static=dpdk_{}", lib);
- } else {
- disabled.push(lib.to_string());
- }
- }
- }
- fn build_drivers(source_root: &str, classes: &mut Vec<String>, drivers: &mut Vec<String>, disabled: &mut Vec<String>) {
- // Stub implementation - would scan drivers/ directory and build driver classes
- let driver_classes = ["net", "crypto", "compress", "vdpa", "event", "baseband", "raw"];
- for class in &driver_classes {
- let class_path = format!("{}/drivers/{}", source_root, class);
- if Path::new(&class_path).exists() {
- classes.push(class.to_string());
- // Scan for individual drivers in each class
- if let Ok(entries) = fs::read_dir(&class_path) {
- for entry in entries.flatten() {
- if entry.file_type().map(|ft| ft.is_dir()).unwrap_or(false) {
- let driver_name = entry.file_name().to_string_lossy().to_string();
- drivers.push(format!("{}_{}", class, driver_name));
- println!("cargo:rustc-link-lib=static=dpdk_{}_{}", class, driver_name);
- }
- }
- }
- }
- }
- }
- fn build_usertools(source_root: &str, enabled: &mut Vec<String>, disabled: &mut Vec<String>) {
- // Stub for usertools build
- let usertools_path = format!("{}/usertools", source_root);
- if Path::new(&usertools_path).exists() {
- enabled.push("usertools".to_string());
- }
- }
- fn build_applications(source_root: &str, enabled: &mut Vec<String>, disabled: &mut Vec<String>) {
- // Stub implementation - would scan app/ directory
- let app_dirs = ["testpmd", "proc-info", "pdump", "test"];
- for app in &app_dirs {
- let app_path = format!("{}/app/{}", source_root, app);
- if Path::new(&app_path).exists() {
- enabled.push(app.to_string());
- } else {
- disabled.push(app.to_string());
- }
- }
- }
- fn build_documentation(source_root: &str) {
- // Stub for documentation build
- }
- fn build_examples(source_root: &str) {
- // Stub for examples build
- }
- fn build_kernel_modules(source_root: &str) {
- // Stub for kernel modules build
- }
- fn check_header_includes(source_root: &str) {
- // Stub for header include checking
- }
- fn generate_build_config(out_dir: &str, conf: &HashMap<String, String>) {
- let config_path = format!("{}/rte_build_config.h", out_dir);
- let mut config_content = String::new();
- config_content.push_str("/* Auto-generated build configuration */\n");
- config_content.push_str("#ifndef RTE_BUILD_CONFIG_H\n");
- config_content.push_str("#define RTE_BUILD_CONFIG_H\n\n");
- for (key, value) in conf {
- config_content.push_str(&format!("#define {} {}\n", key, value));
- }
- config_content.push_str("\n#endif /* RTE_BUILD_CONFIG_H */\n");
- fs::write(config_path, config_content).expect("Failed to write build config");
- }
- fn generate_pkg_config(source_root: &str, out_dir: &str) {
- // Stub for pkg-config generation
- }
- fn print_build_summary(apps_enabled: &[String], libs_enabled: &[String],
- driver_classes: &[String], apps_disabled: &[String],
- libs_disabled: &[String], drivers_disabled: &[String]) {
- println!("\n=================");
- println!("Applications Enabled");
- println!("=================");
- print!("\napps:\n\t");
- for (i, app) in apps_enabled.iter().enumerate() {
- print!("{}, ", app);
- if (i + 1) % 8 == 0 {
- print!("\n\t");
- }
- }
- println!();
- println!("\n=================");
- println!("Libraries Enabled");
- println!("=================");
- print!("\nlibs:\n\t");
- for (i, lib) in libs_enabled.iter().enumerate() {
- print!("{}, ", lib);
- if (i + 1) % 8 == 0 {
- print!("\n\t");
- }
- }
- println!();
- println!("\n===============");
- println!("Drivers Enabled");
- println!("===============");
- for class in driver_classes {
- println!("\n{}:", class);
- print!("\t");
- // Would iterate through actual drivers in each class
- println!("(drivers would be listed here)");
- }
- println!("\n=================");
- println!("Content Skipped");
- println!("=================");
- if !apps_disabled.is_empty() {
- print!("\napps:\n\t");
- for app in apps_disabled {
- println!("{}:\t(reason would be shown here)", app);
- }
- }
- if !libs_disabled.is_empty() {
- print!("\nlibs:\n\t");
- for lib in libs_disabled {
- println!("{}:\t(reason would be shown here)", lib);
- }
- }
- if !drivers_disabled.is_empty() {
- print!("\ndrivers:\n\t");
- for driver in drivers_disabled {
- println!("{}:\t(reason would be shown here)", driver);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment