Build self-contained Convert-BpfToNative.ps1 (#1097)
* Build self-contained Convert-BpfToNative.ps1 Signed-off-by: Alan Jowett <alan.jowett@microsoft.com> * Update cmake build with code to generate Convert-BpfToNative.ps1 Signed-off-by: Alan Jowett <alan.jowett@microsoft.com> Co-authored-by: Alan Jowett <alan.jowett@microsoft.com>
This commit is contained in:
Родитель
eab141f47c
Коммит
fc5792f969
|
@ -40,6 +40,7 @@ jobs:
|
|||
with:
|
||||
build_artifact: Build-x64-vcxproj
|
||||
generate_release_package: true
|
||||
build_nuget: true
|
||||
|
||||
cmake:
|
||||
# Always run this job.
|
||||
|
|
|
@ -22,6 +22,9 @@ on:
|
|||
build_codeql:
|
||||
required: false
|
||||
type: boolean
|
||||
build_nuget:
|
||||
required: false
|
||||
type: boolean
|
||||
|
||||
permissions:
|
||||
contents: read
|
||||
|
@ -166,6 +169,18 @@ jobs:
|
|||
name: ebpf-for-windows.msi
|
||||
path: ${{ steps.packages.outputs.REL_MSI_PACKAGE_PATH }}
|
||||
|
||||
- name: Build nuget package
|
||||
if: matrix.configurations == 'Release' && inputs.build_nuget == true
|
||||
working-directory: ${{env.GITHUB_WORKSPACE}}
|
||||
run: msbuild /m /p:Configuration=${{env.BUILD_CONFIGURATION}} /p:Platform=${{env.BUILD_PLATFORM}} ${{env.SOLUTION_FILE_PATH}} ${{env.BUILD_OPTIONS}} /t:tools\nuget
|
||||
|
||||
- name: Upload the nuget package
|
||||
if: matrix.configurations == 'Release' && inputs.build_nuget == true
|
||||
uses: actions/upload-artifact@6673cd052c4cd6fcf4b4e6e60ea986c889389535
|
||||
with:
|
||||
name: ebpf-for-windows nuget
|
||||
path: ${{github.workspace}}/${{env.BUILD_PLATFORM}}/${{env.BUILD_CONFIGURATION}}/*.nupkg
|
||||
|
||||
- name: Perform CodeQL Analysis
|
||||
if: inputs.build_codeql == true
|
||||
uses: github/codeql-action/analyze@2f58583a1b24a7d3c7034f6bf9fa506d23b1183b
|
||||
|
|
|
@ -11,7 +11,7 @@ function(add_bpftonative_command file_name kernel_mode unsafe_program)
|
|||
set (output_file ${output_dir}/${file_name}_um.dll)
|
||||
endif()
|
||||
|
||||
set(command_line ${powershell_path} -NonInteractive -ExecutionPolicy Unrestricted ${CMAKE_SOURCE_DIR}/scripts/Convert-BpfToNative.ps1 -ProgramName ${file_name} -SolutionDir ${CMAKE_SOURCE_DIR} -OutputDir ${output_dir} -Platform x64 -Configuration $(Configuration) -KernelMode ${kernel_mode})
|
||||
set(command_line ${powershell_path} -NonInteractive -ExecutionPolicy Unrestricted ${output_dir}/Convert-BpfToNative.ps1 -IncludeDir ${CMAKE_SOURCE_DIR}/include -ProgramName ${file_name} -OutDir ${output_dir} -Platform x64 -Configuration $(Configuration) -KernelMode ${kernel_mode})
|
||||
|
||||
set (input_file ${output_dir}/${file_name}.o)
|
||||
if (${unsafe_program})
|
||||
|
|
|
@ -0,0 +1,29 @@
|
|||
# Copyright (c) Microsoft Corporation
|
||||
# SPDX-License-Identifier: MIT
|
||||
|
||||
# Process-File Reads $InputFile and $ConfigFile and performs replacement of strings in the content of $InputFile based
|
||||
# on the Files key in the $ConfigFile.
|
||||
# $ConfigFile is a json document containing the following elements:
|
||||
# Array called "Files" that contains objects with properties "Symbol" and "Filename".
|
||||
# Array called "EscapeCharacters" that contains objects with properties "Char" and "Escape".
|
||||
#
|
||||
# Each string with the value from "Symbol" is replaced with the contents from the corresponding "FileName" after
|
||||
# each occurence of "Char" in the file is replaced with "Escape".
|
||||
|
||||
param ([Parameter(Mandatory=$True)] [string] $InputFile,
|
||||
[Parameter(Mandatory=$True)] [string] $OutputFile,
|
||||
[Parameter(Mandatory=$True)] [string] $ConfigFile)
|
||||
|
||||
$Config = Get-Content -Path $ConfigFile | ConvertFrom-Json
|
||||
$Data = Get-Content -Path $InputFile
|
||||
|
||||
$Config.Files | ForEach-Object {
|
||||
$InsertString = Get-Content -Path $_.FileName
|
||||
$Config.EscapeCharacters | ForEach-Object {
|
||||
$InsertString = $InsertString.Replace($_.Char, $_.Escape)
|
||||
}
|
||||
|
||||
$Data = $Data.Replace($_.Symbol, $InsertString)
|
||||
}
|
||||
|
||||
Set-Content -Path $OutputFile -Value $Data
|
|
@ -0,0 +1,10 @@
|
|||
# Copyright (c) Microsoft Corporation
|
||||
# SPDX-License-Identifier: MIT
|
||||
|
||||
param ($InputFile, $OutputFile, $TemplateText, $Replacement)
|
||||
|
||||
$lines = Get-Content $InputFile
|
||||
|
||||
|
||||
|
||||
$lines | Out-File $OutputFile
|
|
@ -40,11 +40,7 @@ division_by_zero(uint32_t address)
|
|||
if (std::string(NAME) == #X) \
|
||||
return &X;
|
||||
|
||||
metadata_table_t*
|
||||
get_metadata_table()
|
||||
{
|
||||
return &metadata_table;
|
||||
}
|
||||
__declspec(dllexport) metadata_table_t* get_metadata_table() { return &metadata_table; }
|
||||
|
||||
#include "bpf2c.h"
|
||||
|
||||
|
|
|
@ -40,11 +40,7 @@ division_by_zero(uint32_t address)
|
|||
if (std::string(NAME) == #X) \
|
||||
return &X;
|
||||
|
||||
metadata_table_t*
|
||||
get_metadata_table()
|
||||
{
|
||||
return &metadata_table;
|
||||
}
|
||||
__declspec(dllexport) metadata_table_t* get_metadata_table() { return &metadata_table; }
|
||||
|
||||
#include "bpf2c.h"
|
||||
|
||||
|
|
|
@ -40,11 +40,7 @@ division_by_zero(uint32_t address)
|
|||
if (std::string(NAME) == #X) \
|
||||
return &X;
|
||||
|
||||
metadata_table_t*
|
||||
get_metadata_table()
|
||||
{
|
||||
return &metadata_table;
|
||||
}
|
||||
__declspec(dllexport) metadata_table_t* get_metadata_table() { return &metadata_table; }
|
||||
|
||||
#include "bpf2c.h"
|
||||
|
||||
|
|
|
@ -40,11 +40,7 @@ division_by_zero(uint32_t address)
|
|||
if (std::string(NAME) == #X) \
|
||||
return &X;
|
||||
|
||||
metadata_table_t*
|
||||
get_metadata_table()
|
||||
{
|
||||
return &metadata_table;
|
||||
}
|
||||
__declspec(dllexport) metadata_table_t* get_metadata_table() { return &metadata_table; }
|
||||
|
||||
#include "bpf2c.h"
|
||||
|
||||
|
|
|
@ -40,11 +40,7 @@ division_by_zero(uint32_t address)
|
|||
if (std::string(NAME) == #X) \
|
||||
return &X;
|
||||
|
||||
metadata_table_t*
|
||||
get_metadata_table()
|
||||
{
|
||||
return &metadata_table;
|
||||
}
|
||||
__declspec(dllexport) metadata_table_t* get_metadata_table() { return &metadata_table; }
|
||||
|
||||
#include "bpf2c.h"
|
||||
|
||||
|
|
|
@ -40,11 +40,7 @@ division_by_zero(uint32_t address)
|
|||
if (std::string(NAME) == #X) \
|
||||
return &X;
|
||||
|
||||
metadata_table_t*
|
||||
get_metadata_table()
|
||||
{
|
||||
return &metadata_table;
|
||||
}
|
||||
__declspec(dllexport) metadata_table_t* get_metadata_table() { return &metadata_table; }
|
||||
|
||||
#include "bpf2c.h"
|
||||
|
||||
|
|
|
@ -40,11 +40,7 @@ division_by_zero(uint32_t address)
|
|||
if (std::string(NAME) == #X) \
|
||||
return &X;
|
||||
|
||||
metadata_table_t*
|
||||
get_metadata_table()
|
||||
{
|
||||
return &metadata_table;
|
||||
}
|
||||
__declspec(dllexport) metadata_table_t* get_metadata_table() { return &metadata_table; }
|
||||
|
||||
#include "bpf2c.h"
|
||||
|
||||
|
|
|
@ -40,11 +40,7 @@ division_by_zero(uint32_t address)
|
|||
if (std::string(NAME) == #X) \
|
||||
return &X;
|
||||
|
||||
metadata_table_t*
|
||||
get_metadata_table()
|
||||
{
|
||||
return &metadata_table;
|
||||
}
|
||||
__declspec(dllexport) metadata_table_t* get_metadata_table() { return &metadata_table; }
|
||||
|
||||
#include "bpf2c.h"
|
||||
|
||||
|
|
|
@ -40,11 +40,7 @@ division_by_zero(uint32_t address)
|
|||
if (std::string(NAME) == #X) \
|
||||
return &X;
|
||||
|
||||
metadata_table_t*
|
||||
get_metadata_table()
|
||||
{
|
||||
return &metadata_table;
|
||||
}
|
||||
__declspec(dllexport) metadata_table_t* get_metadata_table() { return &metadata_table; }
|
||||
|
||||
#include "bpf2c.h"
|
||||
|
||||
|
|
|
@ -40,11 +40,7 @@ division_by_zero(uint32_t address)
|
|||
if (std::string(NAME) == #X) \
|
||||
return &X;
|
||||
|
||||
metadata_table_t*
|
||||
get_metadata_table()
|
||||
{
|
||||
return &metadata_table;
|
||||
}
|
||||
__declspec(dllexport) metadata_table_t* get_metadata_table() { return &metadata_table; }
|
||||
|
||||
#include "bpf2c.h"
|
||||
|
||||
|
|
|
@ -40,11 +40,7 @@ division_by_zero(uint32_t address)
|
|||
if (std::string(NAME) == #X) \
|
||||
return &X;
|
||||
|
||||
metadata_table_t*
|
||||
get_metadata_table()
|
||||
{
|
||||
return &metadata_table;
|
||||
}
|
||||
__declspec(dllexport) metadata_table_t* get_metadata_table() { return &metadata_table; }
|
||||
|
||||
#include "bpf2c.h"
|
||||
|
||||
|
|
|
@ -40,11 +40,7 @@ division_by_zero(uint32_t address)
|
|||
if (std::string(NAME) == #X) \
|
||||
return &X;
|
||||
|
||||
metadata_table_t*
|
||||
get_metadata_table()
|
||||
{
|
||||
return &metadata_table;
|
||||
}
|
||||
__declspec(dllexport) metadata_table_t* get_metadata_table() { return &metadata_table; }
|
||||
|
||||
#include "bpf2c.h"
|
||||
|
||||
|
|
|
@ -40,11 +40,7 @@ division_by_zero(uint32_t address)
|
|||
if (std::string(NAME) == #X) \
|
||||
return &X;
|
||||
|
||||
metadata_table_t*
|
||||
get_metadata_table()
|
||||
{
|
||||
return &metadata_table;
|
||||
}
|
||||
__declspec(dllexport) metadata_table_t* get_metadata_table() { return &metadata_table; }
|
||||
|
||||
#include "bpf2c.h"
|
||||
|
||||
|
|
|
@ -40,11 +40,7 @@ division_by_zero(uint32_t address)
|
|||
if (std::string(NAME) == #X) \
|
||||
return &X;
|
||||
|
||||
metadata_table_t*
|
||||
get_metadata_table()
|
||||
{
|
||||
return &metadata_table;
|
||||
}
|
||||
__declspec(dllexport) metadata_table_t* get_metadata_table() { return &metadata_table; }
|
||||
|
||||
#include "bpf2c.h"
|
||||
|
||||
|
|
|
@ -40,11 +40,7 @@ division_by_zero(uint32_t address)
|
|||
if (std::string(NAME) == #X) \
|
||||
return &X;
|
||||
|
||||
metadata_table_t*
|
||||
get_metadata_table()
|
||||
{
|
||||
return &metadata_table;
|
||||
}
|
||||
__declspec(dllexport) metadata_table_t* get_metadata_table() { return &metadata_table; }
|
||||
|
||||
#include "bpf2c.h"
|
||||
|
||||
|
|
|
@ -40,11 +40,7 @@ division_by_zero(uint32_t address)
|
|||
if (std::string(NAME) == #X) \
|
||||
return &X;
|
||||
|
||||
metadata_table_t*
|
||||
get_metadata_table()
|
||||
{
|
||||
return &metadata_table;
|
||||
}
|
||||
__declspec(dllexport) metadata_table_t* get_metadata_table() { return &metadata_table; }
|
||||
|
||||
#include "bpf2c.h"
|
||||
|
||||
|
|
|
@ -40,11 +40,7 @@ division_by_zero(uint32_t address)
|
|||
if (std::string(NAME) == #X) \
|
||||
return &X;
|
||||
|
||||
metadata_table_t*
|
||||
get_metadata_table()
|
||||
{
|
||||
return &metadata_table;
|
||||
}
|
||||
__declspec(dllexport) metadata_table_t* get_metadata_table() { return &metadata_table; }
|
||||
|
||||
#include "bpf2c.h"
|
||||
|
||||
|
|
|
@ -40,11 +40,7 @@ division_by_zero(uint32_t address)
|
|||
if (std::string(NAME) == #X) \
|
||||
return &X;
|
||||
|
||||
metadata_table_t*
|
||||
get_metadata_table()
|
||||
{
|
||||
return &metadata_table;
|
||||
}
|
||||
__declspec(dllexport) metadata_table_t* get_metadata_table() { return &metadata_table; }
|
||||
|
||||
#include "bpf2c.h"
|
||||
|
||||
|
|
|
@ -40,11 +40,7 @@ division_by_zero(uint32_t address)
|
|||
if (std::string(NAME) == #X) \
|
||||
return &X;
|
||||
|
||||
metadata_table_t*
|
||||
get_metadata_table()
|
||||
{
|
||||
return &metadata_table;
|
||||
}
|
||||
__declspec(dllexport) metadata_table_t* get_metadata_table() { return &metadata_table; }
|
||||
|
||||
#include "bpf2c.h"
|
||||
|
||||
|
|
|
@ -40,11 +40,7 @@ division_by_zero(uint32_t address)
|
|||
if (std::string(NAME) == #X) \
|
||||
return &X;
|
||||
|
||||
metadata_table_t*
|
||||
get_metadata_table()
|
||||
{
|
||||
return &metadata_table;
|
||||
}
|
||||
__declspec(dllexport) metadata_table_t* get_metadata_table() { return &metadata_table; }
|
||||
|
||||
#include "bpf2c.h"
|
||||
|
||||
|
|
|
@ -40,11 +40,7 @@ division_by_zero(uint32_t address)
|
|||
if (std::string(NAME) == #X) \
|
||||
return &X;
|
||||
|
||||
metadata_table_t*
|
||||
get_metadata_table()
|
||||
{
|
||||
return &metadata_table;
|
||||
}
|
||||
__declspec(dllexport) metadata_table_t* get_metadata_table() { return &metadata_table; }
|
||||
|
||||
#include "bpf2c.h"
|
||||
|
||||
|
|
|
@ -40,11 +40,7 @@ division_by_zero(uint32_t address)
|
|||
if (std::string(NAME) == #X) \
|
||||
return &X;
|
||||
|
||||
metadata_table_t*
|
||||
get_metadata_table()
|
||||
{
|
||||
return &metadata_table;
|
||||
}
|
||||
__declspec(dllexport) metadata_table_t* get_metadata_table() { return &metadata_table; }
|
||||
|
||||
#include "bpf2c.h"
|
||||
|
||||
|
|
|
@ -40,11 +40,7 @@ division_by_zero(uint32_t address)
|
|||
if (std::string(NAME) == #X) \
|
||||
return &X;
|
||||
|
||||
metadata_table_t*
|
||||
get_metadata_table()
|
||||
{
|
||||
return &metadata_table;
|
||||
}
|
||||
__declspec(dllexport) metadata_table_t* get_metadata_table() { return &metadata_table; }
|
||||
|
||||
#include "bpf2c.h"
|
||||
|
||||
|
|
|
@ -40,11 +40,7 @@ division_by_zero(uint32_t address)
|
|||
if (std::string(NAME) == #X) \
|
||||
return &X;
|
||||
|
||||
metadata_table_t*
|
||||
get_metadata_table()
|
||||
{
|
||||
return &metadata_table;
|
||||
}
|
||||
__declspec(dllexport) metadata_table_t* get_metadata_table() { return &metadata_table; }
|
||||
|
||||
#include "bpf2c.h"
|
||||
|
||||
|
|
|
@ -40,11 +40,7 @@ division_by_zero(uint32_t address)
|
|||
if (std::string(NAME) == #X) \
|
||||
return &X;
|
||||
|
||||
metadata_table_t*
|
||||
get_metadata_table()
|
||||
{
|
||||
return &metadata_table;
|
||||
}
|
||||
__declspec(dllexport) metadata_table_t* get_metadata_table() { return &metadata_table; }
|
||||
|
||||
#include "bpf2c.h"
|
||||
|
||||
|
|
|
@ -97,8 +97,10 @@
|
|||
<FileType>CppCode</FileType>
|
||||
<Command>
|
||||
clang $(ClangFlags) -I../xdp -I../socket -I./ext/inc -c %(Filename).c -o $(OutputPath)%(Filename).o
|
||||
powershell -NonInteractive -ExecutionPolicy Unrestricted $(SolutionDir)scripts\Convert-BpfToNative.ps1 -ProgramName %(Filename) -SolutionDir $(SolutionDir) -OutputDir $(OutDir) -Platform $(Platform) -Configuration $(Configuration) -KernelMode $true
|
||||
powershell -NonInteractive -ExecutionPolicy Unrestricted $(SolutionDir)scripts\Convert-BpfToNative.ps1 -ProgramName %(Filename) -SolutionDir $(SolutionDir) -OutputDir $(OutDir) -Platform $(Platform) -Configuration $(Configuration) -KernelMode $false
|
||||
pushd $(OutDir)
|
||||
powershell -NonInteractive -ExecutionPolicy Unrestricted .\Convert-BpfToNative.ps1 -ProgramName %(Filename) -IncludeDir $(SolutionDir)\include -Platform $(Platform) -Configuration $(Configuration) -KernelMode $true
|
||||
powershell -NonInteractive -ExecutionPolicy Unrestricted .\Convert-BpfToNative.ps1 -ProgramName %(Filename) -IncludeDir $(SolutionDir)\include -Platform $(Platform) -Configuration $(Configuration) -KernelMode $false
|
||||
popd
|
||||
</Command>
|
||||
<Outputs>$(OutputPath)%(Filename).o;$(OutputPath)%(Filename)_um.dll;$(OutputPath)%(Filename).sys</Outputs>
|
||||
</CustomBuild>
|
||||
|
@ -110,8 +112,10 @@
|
|||
<Command>clang $(ClangFlags) -c %(Filename).c -o $(OutputPath)%(Filename).o</Command>
|
||||
<Command>
|
||||
clang $(ClangFlags) -I../xdp -I../socket -I./ext/inc -c unsafe\%(Filename).c -o $(OutputPath)%(Filename).o
|
||||
powershell -NonInteractive -ExecutionPolicy Unrestricted $(SolutionDir)scripts\Convert-BpfToNative.ps1 -ProgramName %(Filename) -SolutionDir $(SolutionDir) -OutputDir $(OutDir) -Platform $(Platform) -Configuration $(Configuration) -KernelMode $true -SkipVerification $true
|
||||
powershell -NonInteractive -ExecutionPolicy Unrestricted $(SolutionDir)scripts\Convert-BpfToNative.ps1 -ProgramName %(Filename) -SolutionDir $(SolutionDir) -OutputDir $(OutDir) -Platform $(Platform) -Configuration $(Configuration) -KernelMode $false -SkipVerification $true
|
||||
pushd $(OutDir)
|
||||
powershell -NonInteractive -ExecutionPolicy Unrestricted .\Convert-BpfToNative.ps1 -ProgramName %(Filename) -IncludeDir $(SolutionDir)\include -Platform $(Platform) -Configuration $(Configuration) -KernelMode $true -SkipVerification $true
|
||||
powershell -NonInteractive -ExecutionPolicy Unrestricted .\Convert-BpfToNative.ps1 -ProgramName %(Filename) -IncludeDir $(SolutionDir)\include -Platform $(Platform) -Configuration $(Configuration) -KernelMode $false -SkipVerification $true
|
||||
popd
|
||||
</Command>
|
||||
<Outputs>$(OutputPath)%(Filename).o</Outputs>
|
||||
</CustomBuild>
|
||||
|
|
|
@ -65,6 +65,44 @@ function(generateTemplate source_file_name)
|
|||
)
|
||||
endfunction()
|
||||
|
||||
function(processFile source_file_name config_file)
|
||||
find_program(powershell_path "powershell" REQUIRED)
|
||||
|
||||
set(input_file_name "${CMAKE_CURRENT_LIST_DIR}/${source_file_name}.ps1.template")
|
||||
set(output_file_name "${output_dir}/${source_file_name}.ps1")
|
||||
set(config_file_name "${CMAKE_CURRENT_LIST_DIR}/${config_file}")
|
||||
|
||||
add_custom_command(
|
||||
OUTPUT
|
||||
"${output_file_name}"
|
||||
|
||||
COMMAND
|
||||
"${powershell_path}" powershell -NonInteractive -ExecutionPolicy Unrestricted "${CMAKE_SOURCE_DIR}/scripts/Process-File.ps1" -InputFile "${input_file_name}" -OutputFile "${output_file_name}" -ConfigFile "${config_file_name}"
|
||||
|
||||
VERBATIM
|
||||
|
||||
COMMENT
|
||||
"ebpf-for-windows - Generating: ${source_file_name}.ps1"
|
||||
|
||||
WORKING_DIRECTORY
|
||||
"${CMAKE_CURRENT_LIST_DIR}"
|
||||
|
||||
)
|
||||
|
||||
add_custom_target("${source_file_name}_builder"
|
||||
DEPENDS "${output_file_name}"
|
||||
)
|
||||
|
||||
add_library("${source_file_name}" INTERFACE)
|
||||
target_include_directories("${source_file_name}" INTERFACE
|
||||
"${CMAKE_CURRENT_BINARY_DIR}"
|
||||
)
|
||||
|
||||
add_dependencies("${source_file_name}"
|
||||
"${source_file_name}_builder"
|
||||
)
|
||||
endfunction()
|
||||
|
||||
generateTemplate("bpf2c_driver")
|
||||
target_link_libraries("bpf2c" PRIVATE
|
||||
"bpf2c_driver"
|
||||
|
@ -75,9 +113,14 @@ target_link_libraries("bpf2c" PRIVATE
|
|||
"bpf2c_dll"
|
||||
)
|
||||
|
||||
processFile("Convert-BpfToNative" "replacements.json")
|
||||
target_link_libraries("bpf2c" PRIVATE
|
||||
"Convert-BpfToNative"
|
||||
)
|
||||
|
||||
if(EBPFFORWINDOWS_ENABLE_INSTALL)
|
||||
install(
|
||||
TARGETS "bpf2c"
|
||||
TARGETS "bpf2c" "Convert-BpfToNative"
|
||||
DESTINATION "."
|
||||
)
|
||||
endif()
|
||||
|
|
|
@ -2,13 +2,19 @@
|
|||
# SPDX-License-Identifier: MIT
|
||||
|
||||
param([parameter(Mandatory = $true)] [string] $ProgramName,
|
||||
[parameter(Mandatory = $false)] [string] $SolutionDir = $Pwd,
|
||||
[parameter(Mandatory = $false)] [string] $OutputDir = $Pwd,
|
||||
[parameter(Mandatory = $false)] [string] $IncludeDir = "$PSScriptRoot\..\include",
|
||||
[parameter(Mandatory = $false)] [string] $BinDir = "$PSScriptRoot",
|
||||
[parameter(Mandatory = $false)] [string] $OutDir = "$PWD",
|
||||
[parameter(Mandatory = $false)] [string] $Platform = "x64",
|
||||
[ValidateSet("Release", "Debug")][parameter(Mandatory = $false)] [string] $Configuration = "Release",
|
||||
[parameter(Mandatory = $false)] [bool] $SkipVerification = $false,
|
||||
[parameter(Mandatory = $false)] [bool] $KernelMode = $true)
|
||||
|
||||
Push-Location $OutDir
|
||||
|
||||
$KernelModeProject = '___KERNEL_MODE_VCXPROJ___'
|
||||
$UserModeProject = '___USER_MODE_VCXPROJ___'
|
||||
|
||||
# If program name ends with .o, remove the suffix
|
||||
if ($ProgramName.EndsWith(".o")) {
|
||||
$ProgramName = $ProgramName.Substring(0, $ProgramName.Length - 2)
|
||||
|
@ -23,25 +29,28 @@ if ($null -eq (Get-Command 'msbuild.exe' -ErrorAction SilentlyContinue)) {
|
|||
throw "Unable to locate msbuild.exe. This command needs to run within a 'Developer Command Prompt'"
|
||||
}
|
||||
|
||||
$fileExists = Test-Path -Path ("$OutputDir\$ProgramName.o")
|
||||
$fileExists = Test-Path -Path ("$ProgramName.o")
|
||||
if (!$fileExists) {
|
||||
$errorString = "Can't find program file: " + "$OutputDir\$ProgramName.o"
|
||||
$errorString = "Can't find program file: " + "$ProgramName.o"
|
||||
throw $errorString
|
||||
}
|
||||
|
||||
Push-Location $SolutionDir
|
||||
|
||||
$ProjectFile = "$SolutionDir\tools\bpf2c\templates\kernel_mode_bpf2c.vcxproj"
|
||||
if (!$KernelMode) {
|
||||
$ProjectFile = "$SolutionDir\tools\bpf2c\templates\user_mode_bpf2c.vcxproj"
|
||||
if ($KernelMode) {
|
||||
$ProjectFile = "$ProgramName.vcxproj"
|
||||
Set-Content -Path $ProjectFile -Value $KernelModeProject
|
||||
}
|
||||
else {
|
||||
$ProjectFile = "$ProgramName_um.vcxproj"
|
||||
Set-Content -Path $ProjectFile -Value $UserModeProject
|
||||
}
|
||||
|
||||
$AdditionalOptions = If ($SkipVerification) {"--no-verify"} Else {""}
|
||||
|
||||
msbuild /p:SolutionDir="$SolutionDir\" /p:OutDir="$OutputDir" /p:Configuration="$Configuration" /p:Platform="$Platform" /p:ProgramName="$ProgramName" /p:AdditionalOptions="$AdditionalOptions" $ProjectFile
|
||||
msbuild /p:BinDir="$BinDir\" /p:OutDir="$PWD\" /p:IncludeDir="$IncludeDir" /p:Configuration="$Configuration" /p:Platform="$Platform" /p:ProgramName="$ProgramName" /p:AdditionalOptions="$AdditionalOptions" $ProjectFile
|
||||
|
||||
if ($LASTEXITCODE -ne 0) {
|
||||
throw "Build failed for $ProgramName.o"
|
||||
}
|
||||
|
||||
Pop-Location
|
||||
Pop-Location
|
|
@ -121,6 +121,9 @@
|
|||
<SubSystem>Console</SubSystem>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
</Link>
|
||||
<PreBuildEvent>
|
||||
<Command>powershell -NonInteractive -ExecutionPolicy Unrestricted $(SolutionDir)scripts\Process-File.ps1 -InputFile Convert-BpfToNative.ps1.template -OutputFile $(OutDir)Convert-BpfToNative.ps1 -ConfigFile replacements.json</Command>
|
||||
</PreBuildEvent>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<ClCompile>
|
||||
|
@ -135,6 +138,9 @@
|
|||
<OptimizeReferences>true</OptimizeReferences>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
</Link>
|
||||
<PreBuildEvent>
|
||||
<Command>powershell -NonInteractive -ExecutionPolicy Unrestricted $(SolutionDir)scripts\Process-File.ps1 -InputFile Convert-BpfToNative.ps1.template -OutputFile $(OutDir)Convert-BpfToNative.ps1 -ConfigFile replacements.json</Command>
|
||||
</PreBuildEvent>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="bpf2c.cpp" />
|
||||
|
@ -190,13 +196,13 @@
|
|||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="templates\kernel_mode_bpf2c.vcxproj">
|
||||
<DeploymentContent Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</DeploymentContent>
|
||||
<FileType>Document</FileType>
|
||||
</None>
|
||||
<None Include="templates\sources.def">
|
||||
<DeploymentContent Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</DeploymentContent>
|
||||
</None>
|
||||
<None Include="templates\user_mode_bpf2c.vcxproj">
|
||||
<DeploymentContent Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</DeploymentContent>
|
||||
<FileType>Document</FileType>
|
||||
</None>
|
||||
</ItemGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||
|
|
|
@ -37,8 +37,4 @@ division_by_zero(uint32_t address)
|
|||
if (std::string(NAME) == #X) \
|
||||
return &X;
|
||||
|
||||
metadata_table_t*
|
||||
get_metadata_table()
|
||||
{
|
||||
return &metadata_table;
|
||||
}
|
||||
__declspec(dllexport) metadata_table_t* get_metadata_table() { return &metadata_table; }
|
||||
|
|
|
@ -0,0 +1,23 @@
|
|||
{
|
||||
"Copyright Notice" : [
|
||||
"Copyright (c) Microsoft Corporation",
|
||||
"SPDX-License-Identifier: MIT"
|
||||
],
|
||||
"Description" : "This file controls the replacement of symbols with escaped strings",
|
||||
"Files": [
|
||||
{
|
||||
"Symbol": "___KERNEL_MODE_VCXPROJ___",
|
||||
"FileName": "templates\\kernel_mode_bpf2c.vcxproj"
|
||||
},
|
||||
{
|
||||
"Symbol": "___USER_MODE_VCXPROJ___",
|
||||
"FileName": "templates\\user_mode_bpf2c.vcxproj"
|
||||
}
|
||||
],
|
||||
"EscapeCharacters": [
|
||||
{
|
||||
"Char": "'",
|
||||
"Escape": "''"
|
||||
}
|
||||
]
|
||||
}
|
|
@ -72,10 +72,10 @@
|
|||
</PropertyGroup>
|
||||
<ItemDefinitionGroup>
|
||||
<PreBuildEvent>
|
||||
<Command>$(OutDir)bpf2c --bpf $(OutDir)$(ProgramName).o --sys $(AdditionalOptions) >$(OutDir)$(ProgramName)_driver.c</Command>
|
||||
<Command>$(BinDir)bpf2c --bpf $(ProgramName).o --sys $(AdditionalOptions) >$(ProgramName)_driver.c</Command>
|
||||
</PreBuildEvent>
|
||||
<ClCompile>
|
||||
<AdditionalIncludeDirectories>$(SolutionDir)include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
<AdditionalIncludeDirectories>$(IncludeDir);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
<DisableSpecificWarnings>4189;4245;%(DisableSpecificWarnings)</DisableSpecificWarnings>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
|
@ -89,7 +89,7 @@
|
|||
<FilesToPackage Include="$(TargetPath)" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="$(OutDir)$(ProgramName)_driver.c" />
|
||||
<ClCompile Include="$(ProgramName)_driver.c" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||
<ImportGroup Label="ExtensionTargets">
|
||||
|
|
|
@ -1,8 +0,0 @@
|
|||
;
|
||||
; Copyright (c) Microsoft Corporation
|
||||
; SPDX-License-Identifier: MIT
|
||||
;
|
||||
|
||||
LIBRARY
|
||||
EXPORTS
|
||||
get_metadata_table
|
|
@ -23,7 +23,7 @@
|
|||
</ProjectConfiguration>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="$(OutDir)$(ProgramName)_dll.c" />
|
||||
<ClCompile Include="$(ProgramName)_dll.c" />
|
||||
</ItemGroup>
|
||||
<PropertyGroup Label="Globals">
|
||||
<VCProjectVersion>16.0</VCProjectVersion>
|
||||
|
@ -59,17 +59,16 @@
|
|||
<ConformanceMode>true</ConformanceMode>
|
||||
<PrecompiledHeader>NotUsing</PrecompiledHeader>
|
||||
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
|
||||
<AdditionalIncludeDirectories>$(SolutionDir)include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
<AdditionalIncludeDirectories>$(IncludeDir);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
<DisableSpecificWarnings>4189;4245;%(DisableSpecificWarnings)</DisableSpecificWarnings>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Windows</SubSystem>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<EnableUAC>false</EnableUAC>
|
||||
<ModuleDefinitionFile>$(SolutionDir)tools\bpf2c\templates\sources.def</ModuleDefinitionFile>
|
||||
</Link>
|
||||
<PreBuildEvent>
|
||||
<Command>$(OutDir)bpf2c.exe --bpf $(OutDir)$(ProgramName).o --dll $(AdditionalOptions) >$(OutDir)$(ProgramName)_dll.c</Command>
|
||||
<Command>$(BinDir)bpf2c.exe --bpf $(ProgramName).o --dll $(AdditionalOptions) >$(ProgramName)_dll.c</Command>
|
||||
</PreBuildEvent>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
|
@ -78,7 +77,7 @@
|
|||
<ConformanceMode>true</ConformanceMode>
|
||||
<PrecompiledHeader>NotUsing</PrecompiledHeader>
|
||||
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
|
||||
<AdditionalIncludeDirectories>$(SolutionDir)include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
<AdditionalIncludeDirectories>$(IncludeDir);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
<DisableSpecificWarnings>4189;4245;%(DisableSpecificWarnings)</DisableSpecificWarnings>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
|
@ -87,10 +86,9 @@
|
|||
<OptimizeReferences>true</OptimizeReferences>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<EnableUAC>false</EnableUAC>
|
||||
<ModuleDefinitionFile>$(SolutionDir)tools\bpf2c\templates\sources.def</ModuleDefinitionFile>
|
||||
</Link>
|
||||
<PreBuildEvent>
|
||||
<Command>$(OutDir)bpf2c.exe --bpf $(OutDir)$(ProgramName).o --dll $(AdditionalOptions) >$(OutDir)$(ProgramName)_dll.c</Command>
|
||||
<Command>$(BinDir)bpf2c.exe --bpf $(ProgramName).o --dll $(AdditionalOptions) >$(ProgramName)_dll.c</Command>
|
||||
</PreBuildEvent>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
|
@ -99,17 +97,16 @@
|
|||
<ConformanceMode>true</ConformanceMode>
|
||||
<PrecompiledHeader>NotUsing</PrecompiledHeader>
|
||||
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
|
||||
<AdditionalIncludeDirectories>$(SolutionDir)include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
<AdditionalIncludeDirectories>$(IncludeDir);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
<DisableSpecificWarnings>4189;4245;%(DisableSpecificWarnings)</DisableSpecificWarnings>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Windows</SubSystem>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<EnableUAC>false</EnableUAC>
|
||||
<ModuleDefinitionFile>$(SolutionDir)tools\bpf2c\templates\sources.def</ModuleDefinitionFile>
|
||||
</Link>
|
||||
<PreBuildEvent>
|
||||
<Command>$(OutDir)bpf2c.exe --bpf $(OutDir)$(ProgramName).o --dll $(AdditionalOptions) >$(OutDir)$(ProgramName)_dll.c</Command>
|
||||
<Command>$(BinDir)bpf2c.exe --bpf $(ProgramName).o --dll $(AdditionalOptions) >$(ProgramName)_dll.c</Command>
|
||||
</PreBuildEvent>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
|
@ -118,7 +115,7 @@
|
|||
<ConformanceMode>true</ConformanceMode>
|
||||
<PrecompiledHeader>NotUsing</PrecompiledHeader>
|
||||
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
|
||||
<AdditionalIncludeDirectories>$(SolutionDir)include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
<AdditionalIncludeDirectories>$(IncludeDir);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
<DisableSpecificWarnings>4189;4245;%(DisableSpecificWarnings)</DisableSpecificWarnings>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
|
@ -127,10 +124,9 @@
|
|||
<OptimizeReferences>true</OptimizeReferences>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<EnableUAC>false</EnableUAC>
|
||||
<ModuleDefinitionFile>$(SolutionDir)tools\bpf2c\templates\sources.def</ModuleDefinitionFile>
|
||||
</Link>
|
||||
<PreBuildEvent>
|
||||
<Command>$(OutDir)bpf2c.exe --bpf $(OutDir)$(ProgramName).o --dll $(AdditionalOptions) >$(OutDir)$(ProgramName)_dll.c</Command>
|
||||
<Command>$(BinDir)bpf2c.exe --bpf $(ProgramName).o --dll $(AdditionalOptions) >$(ProgramName)_dll.c</Command>
|
||||
</PreBuildEvent>
|
||||
</ItemDefinitionGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
<metadata>
|
||||
<title>eBPF for Windows SDK</title>
|
||||
<id>eBPF-for-Windows</id>
|
||||
<version>0.1.3</version>
|
||||
<version>0.1.4</version>
|
||||
<authors>eBPF for Windows Contributors</authors>
|
||||
<owners>eBPF for Windows Contributors</owners>
|
||||
<requireLicenseAcceptance>false</requireLicenseAcceptance>
|
||||
|
@ -18,8 +18,9 @@
|
|||
</metadata>
|
||||
|
||||
<files>
|
||||
<file src="..\..\scripts\Convert-BpfToNative.ps1" target="build\native\bin" />
|
||||
<file src="..\..\x64\Release\Convert-BpfToNative.ps1" target="build\native\bin" />
|
||||
<file src="..\..\x64\Release\bpf2c.exe" target="build\native\bin" />
|
||||
<file src="..\..\x64\Release\ebpfapi.dll" target="build\native\bin" />
|
||||
<file src="..\..\x64\Release\ebpfapi.lib" target="build\native\lib" />
|
||||
<file src="..\..\include\**\*.*" target="build\native\include" />
|
||||
<file src="..\..\external\bpftool\libbpf\include\**\*.*" target="build\native\include\libbpf\include" />
|
||||
|
|
|
@ -14,6 +14,8 @@
|
|||
<PropertyGroup>
|
||||
<EbpfLibraries>@(EbpfLibs)</EbpfLibraries>
|
||||
<ClangIncludes>-I $(MSBuildThisFileDirectory)include -I $(MSBuildThisFileDirectory)include/uapi</ClangIncludes>
|
||||
<EbpfBinPath>$(MSBuildThisFileDirectory)bin</EbpfBinPath>
|
||||
<EbpfIncludePath>$(MSBuildThisFileDirectory)include</EbpfIncludePath>
|
||||
</PropertyGroup>
|
||||
<ItemDefinitionGroup>
|
||||
<ClCompile>
|
||||
|
|
Загрузка…
Ссылка в новой задаче