From 6825e1e8f706de2bd96cebcbccae964d97fc0484 Mon Sep 17 00:00:00 2001 From: linjsh <15622383059@163.com> Date: Wed, 6 Nov 2024 22:55:29 +0800 Subject: [PATCH] change ns3 compilation workflow. Do not need to cp files anymore. --- .gitignore | 3 + simulation/scratch/CMakeLists.txt | 132 +++++---------------- simulation/src/applications/CMakeLists.txt | 18 --- 3 files changed, 31 insertions(+), 122 deletions(-) diff --git a/.gitignore b/.gitignore index 224da3e..d4c9d82 100644 --- a/.gitignore +++ b/.gitignore @@ -18,5 +18,8 @@ simulation/core.* simulation/.waf*-* simulation/cmake-cache/* simulation/cmake-cache/* +simulation/build/ +cmake-build-*/ +.lock-ns3_linux_build !simulation/cmake-cache/.gitkeep \ No newline at end of file diff --git a/simulation/scratch/CMakeLists.txt b/simulation/scratch/CMakeLists.txt index 638a004..412d95f 100644 --- a/simulation/scratch/CMakeLists.txt +++ b/simulation/scratch/CMakeLists.txt @@ -1,112 +1,36 @@ -set(target_prefix scratch_) - # set(ASTRA_PATH /workspace/astra-sim/) # set(ASTRA_LIB_PATH "/workspace/astra-sim/extern/network_backend/ns3-interface/simulation/scratch") # message(STATUS "The value of MY_VARIABLE is: ${ASTRA_PATH}") # include_directories(${ASTRA_PATH}) # link_libraries("${ASTRA_LIB_PATH}/libAstraSim.a") -# link astra-sim -set(ASTRA_PATH "../src/applications") -include_directories(${ASTRA_PATH}) - - -function(create_scratch source_files) - # Return early if no sources in the subdirectory - list(LENGTH source_files number_sources) - if(number_sources EQUAL 0) - return() - endif() - - # If the scratch has more than a source file, we need to find the source with - # the main function - set(scratch_src) - foreach(source_file ${source_files}) - file(READ ${source_file} source_file_contents) - string(REGEX MATCHALL "main[(| (]" main_position "${source_file_contents}") - if(CMAKE_MATCH_0) - set(scratch_src ${source_file}) - endif() - endforeach() - - if(NOT scratch_src) - return() - endif() - - # Get parent directory name - get_filename_component(scratch_dirname ${scratch_src} DIRECTORY) - string(REPLACE "${CMAKE_CURRENT_SOURCE_DIR}" "" scratch_dirname - "${scratch_dirname}" - ) - string(REPLACE "/" "_" scratch_dirname "${scratch_dirname}") - - # Get source name - get_filename_component(scratch_name ${scratch_src} NAME_WE) - - set(target_prefix scratch_) - if(scratch_dirname) - # Join the names together if dirname is not the scratch folder - set(target_prefix scratch${scratch_dirname}_) - endif() - - # Get source absolute path and transform into relative path - get_filename_component(scratch_src ${scratch_src} ABSOLUTE) - get_filename_component(scratch_absolute_directory ${scratch_src} DIRECTORY) - string(REPLACE "${PROJECT_SOURCE_DIR}" "${CMAKE_OUTPUT_DIRECTORY}" - scratch_directory ${scratch_absolute_directory} - ) - add_executable(${target_prefix}${scratch_name} "${source_files}") - if(${NS3_STATIC}) - target_link_libraries( - ${target_prefix}${scratch_name} ${LIB_AS_NEEDED_PRE_STATIC} - ${lib-ns3-static} - ${ASTRA_LIB_PATH} - ) - else() - target_link_libraries( - ${target_prefix}${scratch_name} "${ns3-libs}" "${ns3-contrib-libs}" - "${ns3-external-libs}" - ) - endif() - set_runtime_outputdirectory( - ${scratch_name} ${scratch_directory}/ ${target_prefix} - ) -endfunction() - -# Scan *.cc files in ns-3-dev/scratch and build a target for each -file(GLOB single_source_file_scratches CONFIGURE_DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/*.cc) -foreach(scratch_src ${single_source_file_scratches}) - create_scratch(${scratch_src}) -endforeach() - -# Scan *.cc files in ns-3-dev/scratch subdirectories and build a target for each -# subdirectory -file( - GLOB_RECURSE scratch_subdirectories - CONFIGURE_DEPENDS - LIST_DIRECTORIES true - ${CMAKE_CURRENT_SOURCE_DIR}/** +set(ASTRA_PATH "../../../astra-sim-alibabacloud/") +include_directories(${ASTRA_PATH} "${ASTRA_PATH}/astra-sim/network_frontend/ns3") + +file(GLOB ASTRA_SIM_SOURCE_FILES + "${ASTRA_PATH}/astra-sim/system/*.cc" + "${ASTRA_PATH}/astra-sim/workload/*.cc" + "${ASTRA_PATH}/astra-sim/system/collective/*.cc" + "${ASTRA_PATH}/astra-sim/system/topology/*.cc" + "${ASTRA_PATH}/astra-sim/system/memory/*.cc" + "${ASTRA_PATH}/astra-sim/system/fast-backend/*.cc" + "${ASTRA_PATH}/astra-sim/system/scheduling/*.cc") + +list(FILTER ASTRA_SIM_SOURCE_FILES EXCLUDE REGEX ".*BootStrapnet\\.cc") +list(FILTER ASTRA_SIM_SOURCE_FILES EXCLUDE REGEX ".*SimAiFlowModelRdma\\.cc") +list(FILTER ASTRA_SIM_SOURCE_FILES EXCLUDE REGEX ".*PhyMultiThread\\.cc") + +add_library(AstraSim ${ASTRA_SIM_SOURCE_FILES}) + +set(astra-sim-ns3-libs-list + "libapplications" + "libcore" + "libcsma" + "libinternet" + "libpoint-to-point" + "libnetwork" ) -# Filter out files -foreach(entry ${scratch_subdirectories}) - if(NOT (IS_DIRECTORY ${entry})) - list(REMOVE_ITEM scratch_subdirectories ${entry}) - endif() -endforeach() - -foreach(subdir ${scratch_subdirectories}) - if(EXISTS ${subdir}/CMakeLists.txt) - # If the subdirectory contains a CMakeLists.txt file - # we let the CMake file manage the source files - # - # Use this if you want to link to external libraries - # without creating a module - add_subdirectory(${subdir}) - else() - # Otherwise we pick all the files in the subdirectory - # and create a scratch for them automatically - file(GLOB scratch_sources CONFIGURE_DEPENDS ${subdir}/*.cc) - create_scratch("${scratch_sources}") - endif() -endforeach() +list(JOIN astra-sim-ns3-libs-list " " astra-sim-ns3-libs) +add_executable(AstraSimNetworkNs3 "${ASTRA_PATH}/astra-sim/network_frontend/ns3/AstraSimNetwork.cc") +target_link_libraries(AstraSimNetworkNs3 ${astra-sim-ns3-libs-list} AstraSim) diff --git a/simulation/src/applications/CMakeLists.txt b/simulation/src/applications/CMakeLists.txt index 4983083..c307ad9 100644 --- a/simulation/src/applications/CMakeLists.txt +++ b/simulation/src/applications/CMakeLists.txt @@ -1,19 +1,3 @@ -file(GLOB ASTRA_SIM_SOURCE_FILES - "${CMAKE_CURRENT_SOURCE_DIR}/astra-sim/system/*.cc" - "${CMAKE_CURRENT_SOURCE_DIR}/astra-sim/workload/*.cc" - "${CMAKE_CURRENT_SOURCE_DIR}/astra-sim/system/collective/*.cc" - "${CMAKE_CURRENT_SOURCE_DIR}/astra-sim/system/topology/*.cc" - "${CMAKE_CURRENT_SOURCE_DIR}/astra-sim/system/memory/*.cc" - "${CMAKE_CURRENT_SOURCE_DIR}/astra-sim/system/fast-backend/*.cc" - "${CMAKE_CURRENT_SOURCE_DIR}/astra-sim/system/scheduling/*.cc") - -list(FILTER ASTRA_SIM_SOURCE_FILES EXCLUDE REGEX ".*BootStrapnet\\.cc") -list(FILTER ASTRA_SIM_SOURCE_FILES EXCLUDE REGEX ".*SimAiFlowModelRdma\\.cc") -list(FILTER ASTRA_SIM_SOURCE_FILES EXCLUDE REGEX ".*PhyMultiThread\\.cc") - - -include_directories(${CMAKE_CURRENT_SOURCE_DIR}) - build_lib( LIBNAME applications SOURCE_FILES @@ -43,7 +27,6 @@ build_lib( model/udp-trace-client.cc model/rdma-client.cc model/simple-seq-ts-header.cc - ${ASTRA_SIM_SOURCE_FILES} HEADER_FILES helper/bulk-send-helper.h helper/on-off-helper.h @@ -71,7 +54,6 @@ build_lib( model/udp-trace-client.h model/rdma-client.h model/simple-seq-ts-header.h - # ${ASTRA_SIM_HEADER_FILES} LIBRARIES_TO_LINK ${libinternet} ${libstats} TEST_SOURCES