diff --git a/.azure/obtemplates/build-linux.yml b/.azure/obtemplates/build-linux.yml index f99cd88bd6..02705f917b 100644 --- a/.azure/obtemplates/build-linux.yml +++ b/.azure/obtemplates/build-linux.yml @@ -29,10 +29,11 @@ jobs: target: ubuntu_2004_x86_64 ${{ else }}: target: ubuntu_2204_x86_64 + xdp: true inputs: pwsh: true filePath: scripts/build.ps1 - arguments: -Tls ${{ parameters.tls }} -Config ${{ parameters.config }} -Platform ${{ parameters.platform }} -Arch x64 -CI -UseSystemOpenSSLCrypto -OneBranch -OfficialRelease + arguments: -Tls ${{ parameters.tls }} -Config ${{ parameters.config }} -Platform ${{ parameters.platform }} -EnableLinuxXDP ${{ xdp }} -Arch x64 -CI -UseSystemOpenSSLCrypto -OneBranch -OfficialRelease - task: PowerShell@2 displayName: arm64 ${{ if eq(parameters.tls, 'openssl') }}: diff --git a/CMakeLists.txt b/CMakeLists.txt index cebf8ec14e..3f8f4d58fe 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -64,9 +64,6 @@ elseif (APPLE) set(CX_PLATFORM "darwin") elseif (UNIX) set(CX_PLATFORM "linux") - file(STRINGS "/etc/lsb-release" LSB_RELEASE_CONTENT) - string(REGEX MATCH "DISTRIB_RELEASE=([0-9]+\\.[0-9]+)" _ ${LSB_RELEASE_CONTENT}) - set(UBUNTU_VERSION ${CMAKE_MATCH_1}) endif() message(STATUS "QUIC Platform: ${CX_PLATFORM}") @@ -93,6 +90,7 @@ option(QUIC_STATIC_LINK_PARTIAL_CRT "Statically links the compiler-specific port option(QUIC_UWP_BUILD "Build for UWP" OFF) option(QUIC_GAMECORE_BUILD "Build for GameCore" OFF) option(QUIC_PGO "Enables profile guided optimizations" OFF) +option(QUIC_LINUX_XDP_ENABLED "Enables XDP support" OFF) option(QUIC_SOURCE_LINK "Enables source linking on MSVC" ON) option(QUIC_EMBED_GIT_HASH "Embed git commit hash in the binary" ON) option(QUIC_PDBALTPATH "Enable PDBALTPATH setting on MSVC" ON) diff --git a/docs/BUILD.md b/docs/BUILD.md index 35a4983c94..a7ff17ce8e 100644 --- a/docs/BUILD.md +++ b/docs/BUILD.md @@ -186,7 +186,7 @@ Linux XDP is experimentally supported on amd64 && Ubuntu 22.04LTS. Commands below automatically install dependencies and setup runtime environment. ```sh pwsh ./scripts/prepare-machine.ps1 -UseXdp -pwsh ./scripts/build.ps1 +pwsh ./scripts/build.ps1 -EnableLinuxXDP ``` `./scripts/prepare-machine.ps1` internally does the below commands: diff --git a/scripts/build.ps1 b/scripts/build.ps1 index 531a513f36..d03e54ec3a 100644 --- a/scripts/build.ps1 +++ b/scripts/build.ps1 @@ -57,6 +57,9 @@ This script provides helpers for building msquic. .PARAMETER PGO Builds msquic with profile guided optimization support (Windows-only). +.PARAMETER EnableLinuxXDP + Enables XDP support (Linux-only). + .PARAMETER Generator Specifies a specific cmake generator (Only supported on unix) @@ -166,6 +169,9 @@ param ( [Parameter(Mandatory = $false)] [switch]$PGO = $false, + [Parameter(Mandatory = $false)] + [switch]$EnableLinuxXDP = $false, + [Parameter(Mandatory = $false)] [string]$Generator = "", @@ -265,6 +271,12 @@ if ($Arch -eq "arm64ec") { } } +if ($IsLinux -And $Arch -ne "x64") { + if ($EnableLinuxXDP) { + Write-Error "Linux XDP is supported only on x64 platforms" + } +} + if ($Platform -eq "ios" -and !$Static) { $Static = $true Write-Host "iOS can only be built as static" @@ -457,6 +469,9 @@ function CMake-Generate { if ($PGO) { $Arguments += " -DQUIC_PGO=on" } + if ($EnableLinuxXDP) { + $Arguments += " -DQUIC_LINUX_XDP_ENABLED=on" + } if ($Platform -eq "uwp") { $Arguments += " -DCMAKE_SYSTEM_NAME=WindowsStore -DCMAKE_SYSTEM_VERSION=10.0 -DQUIC_UWP_BUILD=on" } diff --git a/scripts/build.rs b/scripts/build.rs index c42cda5d9c..355d263d65 100644 --- a/scripts/build.rs +++ b/scripts/build.rs @@ -19,8 +19,7 @@ fn main() { config .define("QUIC_ENABLE_LOGGING", logging_enabled) .define("QUIC_TLS", "openssl") - .define("QUIC_OUTPUT_DIR", "../lib") - .define("QUIC_CARGO_BUILD", "on"); + .define("QUIC_OUTPUT_DIR", "../lib"); match target.as_str() { "x86_64-apple-darwin" => config diff --git a/src/platform/CMakeLists.txt b/src/platform/CMakeLists.txt index 5b01fdc891..d79d16841d 100644 --- a/src/platform/CMakeLists.txt +++ b/src/platform/CMakeLists.txt @@ -23,20 +23,13 @@ if("${CX_PLATFORM}" STREQUAL "windows") set(SOURCES ${SOURCES} datapath_raw.c datapath_raw_win.c datapath_raw_socket.c datapath_raw_socket_win.c datapath_raw_xdp_win.c) endif() else() - set(LINUX_XDP_ENABLED FALSE) set(SOURCES ${SOURCES} inline.c platform_posix.c storage_posix.c cgroup.c datapath_unix.c) if(CX_PLATFORM STREQUAL "linux" AND NOT CMAKE_SYSTEM_NAME STREQUAL "FreeBSD") set(SOURCES ${SOURCES} datapath_linux.c datapath_epoll.c) - if ((${UBUNTU_VERSION} STREQUAL "20.04") OR - (${CMAKE_TARGET_ARCHITECTURE} STREQUAL "arm64") OR - (${CMAKE_TARGET_ARCHITECTURE} STREQUAL "arm") OR - (${CMAKE_SYSTEM_PROCESSOR} STREQUAL "arm") OR - (ANDROID) OR - (QUIC_CARGO_BUILD)) - set(SOURCES ${SOURCES} datapath_xplat.c datapath_raw_dummy.c) - else() - set(LINUX_XDP_ENABLED TRUE) + if (QUIC_LINUX_XDP_ENABLED) set(SOURCES ${SOURCES} datapath_xplat.c datapath_raw.c datapath_raw_linux.c datapath_raw_socket.c datapath_raw_socket_linux.c datapath_raw_xdp_linux.c) + else() + set(SOURCES ${SOURCES} datapath_xplat.c datapath_raw_dummy.c) endif() else() set(SOURCES ${SOURCES} datapath_kqueue.c) @@ -68,7 +61,7 @@ if("${CX_PLATFORM}" STREQUAL "windows") PUBLIC wbemuuid) target_link_libraries(platform PUBLIC winmm) -elseif(LINUX_XDP_ENABLED) +elseif(QUIC_LINUX_XDP_ENABLED) find_library(NL_LIB nl-3) find_library(NL_ROUTE_LIB nl-route-3) find_library(XDP_LIB libxdp.so) @@ -118,7 +111,7 @@ if ("${CX_PLATFORM}" STREQUAL "windows") PRIVATE ${EXTRA_PLATFORM_INCLUDE_DIRECTORIES} ${PROJECT_SOURCE_DIR}/submodules/xdp-for-windows/published/external) -elseif(LINUX_XDP_ENABLED) +elseif(QUIC_LINUX_XDP_ENABLED) include_directories(/usr/include/libnl3) target_include_directories(platform PRIVATE ${EXTRA_PLATFORM_INCLUDE_DIRECTORIES}) endif()