Skip to content

Commit 8e4c65c

Browse files
authored
Merge pull request #34 from ntoskrnl7/codex/add-github-release-assets
[codex] add GitHub release assets
2 parents f531b6f + 9602d91 commit 8e4c65c

7 files changed

Lines changed: 527 additions & 20 deletions

File tree

Lines changed: 96 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
name: NuGet
1+
name: Package
22

33
on:
44
pull_request:
55
branches: [ main ]
66
paths:
7-
- '.github/workflows/nuget.yml'
7+
- '.github/workflows/package.yml'
88
- 'nuget/**'
99
- 'scripts/nuget/**'
1010
- 'CMakeLists.txt'
@@ -22,7 +22,7 @@ on:
2222
tags:
2323
- 'v*'
2424
paths:
25-
- '.github/workflows/nuget.yml'
25+
- '.github/workflows/package.yml'
2626
- 'nuget/**'
2727
- 'scripts/nuget/**'
2828
- 'CMakeLists.txt'
@@ -46,6 +46,11 @@ on:
4646
required: true
4747
type: boolean
4848
default: false
49+
github_release:
50+
description: Upload release assets to GitHub Releases
51+
required: true
52+
type: boolean
53+
default: false
4954

5055
permissions:
5156
contents: read
@@ -154,12 +159,22 @@ jobs:
154159
shell: pwsh
155160
run: ./scripts/nuget/Pack-CrtSysNuGet.ps1 -Version '${{ steps.version.outputs.package_version }}'
156161

162+
- name: Pack GitHub release assets
163+
shell: pwsh
164+
run: ./scripts/nuget/Pack-CrtSysReleaseAssets.ps1 -Version '${{ steps.version.outputs.package_version }}'
165+
157166
- uses: actions/upload-artifact@v7
158167
with:
159168
name: crtsys-nuget-${{ steps.version.outputs.package_version }}
160169
path: artifacts/nuget/*.nupkg
161170
if-no-files-found: error
162171

172+
- uses: actions/upload-artifact@v7
173+
with:
174+
name: crtsys-release-assets-${{ steps.version.outputs.package_version }}
175+
path: artifacts/release/*
176+
if-no-files-found: error
177+
163178
test-package-driver:
164179
name: Test NuGet driver package ${{ matrix.arch }} ${{ matrix.config }}
165180
needs: pack
@@ -222,6 +237,34 @@ jobs:
222237
-Configuration '${{ matrix.config }}'
223238
-WindowsSdkVersion '10.0.22621.0'
224239
240+
test-release-native-cmake:
241+
name: Test release native CMake asset ${{ matrix.arch }} ${{ matrix.config }}
242+
needs: pack
243+
runs-on: windows-2022
244+
strategy:
245+
fail-fast: false
246+
matrix:
247+
arch: [x64, ARM64]
248+
config: [Debug, Release]
249+
250+
steps:
251+
- uses: actions/checkout@v5
252+
253+
- uses: actions/download-artifact@v7
254+
with:
255+
name: crtsys-release-assets-${{ needs.pack.outputs.package_version }}
256+
path: artifacts/release
257+
258+
- name: Build native release CMake consumer test
259+
shell: pwsh
260+
run: >
261+
./scripts/nuget/Test-CrtSysReleaseAssets.ps1
262+
-ReleaseDirectory artifacts/release
263+
-Version '${{ needs.pack.outputs.package_version }}'
264+
-Architecture '${{ matrix.arch }}'
265+
-Configuration '${{ matrix.config }}'
266+
-WindowsSdkVersion '10.0.22621.0'
267+
225268
publish:
226269
name: Publish NuGet
227270
needs: [pack, test-package-driver, test-package-app]
@@ -261,3 +304,53 @@ jobs:
261304
env:
262305
NUGET_API_KEY: ${{ steps.nuget-login.outputs.NUGET_API_KEY }}
263306
run: ./scripts/nuget/Push-CrtSysNuGet.ps1 -SkipDuplicate
307+
308+
github-release:
309+
name: Upload GitHub Release Assets
310+
needs: [pack, test-package-driver, test-package-app, test-release-native-cmake]
311+
if: startsWith(github.ref, 'refs/tags/v') || (github.event_name == 'workflow_dispatch' && inputs.github_release)
312+
runs-on: windows-2022
313+
permissions:
314+
contents: write
315+
316+
steps:
317+
- uses: actions/download-artifact@v7
318+
with:
319+
name: crtsys-release-assets-${{ needs.pack.outputs.package_version }}
320+
path: artifacts/release
321+
322+
- name: Create or update GitHub release
323+
shell: pwsh
324+
env:
325+
GH_TOKEN: ${{ github.token }}
326+
run: |
327+
$version = '${{ needs.pack.outputs.package_version }}'
328+
$tagName = "v$version"
329+
if ('${{ github.ref_type }}' -eq 'tag') {
330+
$tagName = '${{ github.ref_name }}'
331+
}
332+
333+
$assets = @(Get-ChildItem -Path artifacts\release -File | Sort-Object FullName | ForEach-Object { $_.FullName })
334+
if ($assets.Count -eq 0) {
335+
throw 'No GitHub Release assets were found.'
336+
}
337+
338+
& gh release view $tagName *> $null
339+
if ($LASTEXITCODE -eq 0) {
340+
Write-Host "Uploading assets to existing GitHub Release $tagName"
341+
& gh release upload $tagName @assets --clobber
342+
} else {
343+
Write-Host "Creating GitHub Release $tagName"
344+
$notes = @(
345+
"crtsys $version release assets."
346+
""
347+
"- crtsys.$version.nupkg: offline NuGet package"
348+
"- crtsys-$version-native.zip: headers, docs, CMake helpers, native MSBuild imports, and prebuilt x64/ARM64 Debug/Release libraries"
349+
"- crtsys-$version-SHA256SUMS.txt: SHA-256 checksums"
350+
) -join [Environment]::NewLine
351+
& gh release create $tagName @assets --target '${{ github.sha }}' --title "crtsys $version" --notes $notes
352+
}
353+
354+
if ($LASTEXITCODE -ne 0) {
355+
throw "GitHub Release upload failed with exit code $LASTEXITCODE."
356+
}

README.md

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# crtsys
22

3-
**C**/C++ Run**t**ime support for Windows kernel **sys** drivers.
3+
**C**/C++ **R**un**t**ime support for Windows kernel drivers (`.sys`).
44

55
[![CMake](https://github.com/ntoskrnl7/crtsys/actions/workflows/cmake.yml/badge.svg)](https://github.com/ntoskrnl7/crtsys/actions/workflows/cmake.yml)
66
![GitHub](https://img.shields.io/github/license/ntoskrnl7/crtsys)
@@ -185,6 +185,13 @@ Driver mode is enabled automatically when MSBuild sees a driver project
185185
console application, static library, or CMake project into a WDK driver project,
186186
and it does not install or replace the WDK toolset.
187187

188+
Driver builds may emit `LNK4088` because `crtsys` intentionally uses
189+
`/FORCE:MULTIPLE` for known duplicate CRT/runtime symbols between `libcntpr`,
190+
`Ldk`, `ntoskrnl`, and the runtime glue. Treat that as an expected build
191+
warning only when the remaining link output contains no unresolved symbols and
192+
the duplicate symbols are in the known runtime boundary. Final drivers still
193+
need load, verifier, signing, and target-OS validation.
194+
188195
The current binary package targets:
189196

190197
- Visual Studio 2022
@@ -236,10 +243,29 @@ $env:NUGET_API_KEY = '<nuget-api-key>'
236243
GitHub Actions builds the prebuilt libraries and package on pull requests and
237244
pushes. A tag such as `v0.1.12` publishes to nuget.org through NuGet Trusted
238245
Publishing when the tag version matches `include/.internal/version`.
246+
The same tag build also creates GitHub Release assets. Manual workflow runs can
247+
set `github_release=true` to create or update the matching GitHub Release
248+
without pushing a tag.
249+
250+
Release assets include:
251+
252+
- `crtsys.<version>.nupkg` for offline NuGet installation.
253+
- `crtsys-<version>-native.zip` with headers, docs, CMake helpers, native
254+
MSBuild imports, and prebuilt x64/ARM64 Debug/Release driver libraries.
255+
- `crtsys-<version>-SHA256SUMS.txt` for asset checksums.
256+
257+
The native zip includes `cmake/CrtSys.cmake`, and the same `crtsys_add_driver`
258+
API can consume the prebuilt driver libraries when it is included from the
259+
unpacked bundle. A WDK CMake project can unpack the zip and use:
260+
261+
```cmake
262+
include(path/to/crtsys-<version>/cmake/CrtSys.cmake)
263+
crtsys_add_driver(my_driver src/main.cpp)
264+
```
239265

240266
For GitHub Actions publishing, create a nuget.org Trusted Publishing policy
241267
with the package owner shown by nuget.org, repository owner `ntoskrnl7`,
242-
repository `crtsys`, workflow file `nuget.yml`, and no environment
268+
repository `crtsys`, workflow file `package.yml`, and no environment
243269
restriction. Set the GitHub Actions repository variable
244270
`NUGET_TRUSTED_PUBLISHING_USER` to the nuget.org user that created the policy.
245271

cmake/CrtSys.cmake

Lines changed: 108 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,28 @@ cmake_policy(SET CMP0021 OLD)
44
set(CMAKE_CXX_STANDARD_LIBRARIES " ")
55
set(CMAKE_C_STANDARD_LIBRARIES ${CMAKE_CXX_STANDARD_LIBRARIES})
66

7+
if(NOT DEFINED CRTSYS_NTL_MAIN)
8+
set(CRTSYS_NTL_MAIN ON)
9+
endif()
10+
11+
if(NOT DEFINED CRTSYS_USE_LIBCNTPR)
12+
set(CRTSYS_USE_LIBCNTPR ON)
13+
endif()
14+
15+
if(DEFINED crtsys_SOURCE_DIR)
16+
set(_CRTSYS_ROOT "${crtsys_SOURCE_DIR}")
17+
else()
18+
get_filename_component(_CRTSYS_ROOT "${CMAKE_CURRENT_LIST_DIR}/.." ABSOLUTE)
19+
endif()
20+
21+
if(NOT DEFINED CRTSYS_USE_PREBUILT)
22+
if(NOT TARGET crtsys AND EXISTS "${_CRTSYS_ROOT}/lib/native")
23+
set(CRTSYS_USE_PREBUILT ON)
24+
else()
25+
set(CRTSYS_USE_PREBUILT OFF)
26+
endif()
27+
endif()
28+
729
function(crtsys_scope_compile_options_to_c_cxx TARGET_NAME)
830
get_target_property(TARGET_COMPILE_OPTIONS ${TARGET_NAME} COMPILE_OPTIONS)
931
if(NOT TARGET_COMPILE_OPTIONS)
@@ -57,23 +79,100 @@ CPMAddPackage("gh:ntoskrnl7/FindWDK#master")
5779
list(APPEND CMAKE_MODULE_PATH "${FindWDK_SOURCE_DIR}/cmake")
5880
find_package(WDK REQUIRED)
5981

60-
function(crtsys_add_driver _target)
61-
cmake_parse_arguments(WDK "" "WINVER" "" ${ARGN})
62-
wdk_add_driver(${_target} ${WDK_UNPARSED_ARGUMENTS} CUSTOM_ENTRY_POINT CrtSysDriverEntry EXTENDED_CPP_FEATURES)
63-
crtsys_scope_compile_options_to_c_cxx(${_target})
82+
function(crtsys_get_prebuilt_arch _out_arch)
83+
if("${CMAKE_VS_PLATFORM_NAME}" STREQUAL "x64")
84+
set(_arch x64)
85+
elseif("${CMAKE_VS_PLATFORM_NAME}" STREQUAL "ARM64")
86+
set(_arch ARM64)
87+
elseif("${CMAKE_VS_PLATFORM_NAME}" STREQUAL "Win32")
88+
message(FATAL_ERROR "The crtsys prebuilt driver bundle does not include x86 driver libraries.")
89+
else()
90+
message(FATAL_ERROR "Unsupported crtsys prebuilt platform: ${CMAKE_VS_PLATFORM_NAME}")
91+
endif()
92+
93+
set(${_out_arch} "${_arch}" PARENT_SCOPE)
94+
endfunction()
95+
96+
function(crtsys_get_prebuilt_library _out_path _library _configuration)
97+
crtsys_get_prebuilt_arch(_arch)
98+
99+
if("${_configuration}" STREQUAL "Debug")
100+
set(_config_dir Debug)
101+
else()
102+
set(_config_dir Release)
103+
endif()
64104

65-
target_link_libraries(${_target} crtsys)
105+
set(_path "${_CRTSYS_ROOT}/lib/native/${_arch}/${_config_dir}/${_library}")
106+
file(TO_CMAKE_PATH "${_path}" _path)
107+
if(NOT EXISTS "${_path}")
108+
message(FATAL_ERROR "Required crtsys prebuilt library was not found: ${_path}")
109+
endif()
66110

111+
set(${_out_path} "${_path}" PARENT_SCOPE)
112+
endfunction()
113+
114+
function(crtsys_apply_driver_settings _target _root)
67115
get_target_property(INC_DIR_TMP ${_target} INCLUDE_DIRECTORIES)
68-
set_property(TARGET ${_target} PROPERTY INCLUDE_DIRECTORIES "${crtsys_SOURCE_DIR}/include;${crtsys_SOURCE_DIR}/include/.internal/msvc/$(VCToolsVersion);${crtsys_SOURCE_DIR}/include/.internal/msvc/${MSVC_TOOLSET_VERSION};${crtsys_SOURCE_DIR}/include/.internal/msvc/$(VCToolsVersion)/stl;${crtsys_SOURCE_DIR}/include/.internal/msvc/${MSVC_TOOLSET_VERSION}/stl;$(VC_IncludePath);$(WindowsSDK_IncludePath);${INC_DIR_TMP}")
116+
if(NOT INC_DIR_TMP)
117+
set(INC_DIR_TMP "")
118+
endif()
69119

70-
if(EXISTS "${crtsys_SOURCE_DIR}/include/.internal/winsdk/${CMAKE_VS_WINDOWS_TARGET_PLATFORM_VERSION}/wdk/${WDK_VERSION}/forced.h")
71-
target_compile_options(${_target} PRIVATE "$<$<COMPILE_LANGUAGE:C,CXX>:/FI${crtsys_SOURCE_DIR}/include/.internal/winsdk/${CMAKE_VS_WINDOWS_TARGET_PLATFORM_VERSION}/wdk/${WDK_VERSION}/forced.h>")
120+
set_property(TARGET ${_target} PROPERTY INCLUDE_DIRECTORIES "${_root}/include;${_root}/include/.internal/msvc/$(VCToolsVersion);${_root}/include/.internal/msvc/${MSVC_TOOLSET_VERSION};${_root}/include/.internal/msvc/$(VCToolsVersion)/stl;${_root}/include/.internal/msvc/${MSVC_TOOLSET_VERSION}/stl;$(VC_IncludePath);$(WindowsSDK_IncludePath);${INC_DIR_TMP}")
121+
122+
if(EXISTS "${_root}/include/.internal/winsdk/${CMAKE_VS_WINDOWS_TARGET_PLATFORM_VERSION}/wdk/${WDK_VERSION}/forced.h")
123+
target_compile_options(${_target} PRIVATE "$<$<COMPILE_LANGUAGE:C,CXX>:/FI${_root}/include/.internal/winsdk/${CMAKE_VS_WINDOWS_TARGET_PLATFORM_VERSION}/wdk/${WDK_VERSION}/forced.h>")
72124
endif()
73125

74-
target_compile_options(${_target} PRIVATE "$<$<COMPILE_LANGUAGE:C,CXX>:/FI${crtsys_SOURCE_DIR}/include/.internal/adjust_link_order>")
126+
target_compile_options(${_target} PRIVATE "$<$<COMPILE_LANGUAGE:C,CXX>:/FI${_root}/include/.internal/adjust_link_order>")
75127

76128
if(CRTSYS_NTL_MAIN)
77129
target_compile_definitions(${_target} PUBLIC CRTSYS_USE_NTL_MAIN)
78130
endif()
79131
endfunction()
132+
133+
function(crtsys_link_prebuilt_driver_libraries _target)
134+
crtsys_get_prebuilt_library(_crtsys_debug crtsys.lib Debug)
135+
crtsys_get_prebuilt_library(_ldk_debug Ldk.lib Debug)
136+
crtsys_get_prebuilt_library(_crtsys_release crtsys.lib Release)
137+
crtsys_get_prebuilt_library(_ldk_release Ldk.lib Release)
138+
139+
target_link_libraries(
140+
${_target}
141+
debug "${_crtsys_debug}"
142+
debug "${_ldk_debug}"
143+
optimized "${_crtsys_release}"
144+
optimized "${_ldk_release}"
145+
)
146+
147+
target_compile_definitions(${_target} PUBLIC "_KERNEL32_" "_ITERATOR_DEBUG_LEVEL=0" "_HAS_EXCEPTIONS")
148+
target_compile_options(${_target} PUBLIC "$<$<COMPILE_LANGUAGE:CXX>:/Zc:threadSafeInit->")
149+
target_compile_options(${_target} PUBLIC "$<$<COMPILE_LANGUAGE:C,CXX>:/MT>")
150+
151+
if(CRTSYS_USE_LIBCNTPR)
152+
if(NOT TARGET WDK::LIBCNTPR)
153+
message(FATAL_ERROR "WDK::LIBCNTPR is required for crtsys prebuilt driver support.")
154+
endif()
155+
156+
target_link_libraries(${_target} WDK::LIBCNTPR)
157+
target_compile_definitions(${_target} PUBLIC CRTSYS_USE_LIBCNTPR)
158+
target_link_options(${_target} PUBLIC "/FORCE:MULTIPLE")
159+
endif()
160+
endfunction()
161+
162+
function(crtsys_add_driver _target)
163+
cmake_parse_arguments(WDK "" "WINVER" "" ${ARGN})
164+
wdk_add_driver(${_target} ${WDK_UNPARSED_ARGUMENTS} CUSTOM_ENTRY_POINT CrtSysDriverEntry EXTENDED_CPP_FEATURES)
165+
crtsys_scope_compile_options_to_c_cxx(${_target})
166+
167+
crtsys_apply_driver_settings(${_target} "${_CRTSYS_ROOT}")
168+
169+
if(CRTSYS_USE_PREBUILT)
170+
crtsys_link_prebuilt_driver_libraries(${_target})
171+
else()
172+
if(NOT TARGET crtsys)
173+
message(FATAL_ERROR "crtsys target was not found. Add crtsys with CPMAddPackage or use an unpacked crtsys native release bundle.")
174+
endif()
175+
176+
target_link_libraries(${_target} crtsys)
177+
endif()
178+
endfunction()

docs/ko-kr.md

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# crtsys
22

3-
Windows 커널 드라이버(`.sys`)를 위한 **C**/C++ Run**t**ime 지원
3+
Windows 커널 드라이버(`.sys`)를 위한 **C**/C++ **R**un**t**ime 지원
44
라이브러리입니다.
55

66
[![CMake](https://github.com/ntoskrnl7/crtsys/actions/workflows/cmake.yml/badge.svg)](https://github.com/ntoskrnl7/crtsys/actions/workflows/cmake.yml)
@@ -185,6 +185,13 @@ Driver mode는 MSBuild가 driver 프로젝트를 감지할 때 자동으로 켜
185185
프로젝트, console application, static library, CMake 프로젝트를 WDK driver
186186
프로젝트로 변환하지 않으며 WDK toolset을 설치하거나 대체하지 않습니다.
187187

188+
driver build에서는 `LNK4088`이 보일 수 있습니다. `crtsys``libcntpr`,
189+
`Ldk`, `ntoskrnl`, runtime glue 사이의 알려진 CRT/runtime symbol 중복을
190+
처리하기 위해 의도적으로 `/FORCE:MULTIPLE`을 사용합니다. 이 경고는 남은
191+
link output에 unresolved symbol이 없고, 중복 symbol이 알려진 runtime 경계
192+
안에 있을 때만 예상 가능한 build warning으로 보아야 합니다. 최종 드라이버는
193+
여전히 load, verifier, signing, 대상 OS 검증이 필요합니다.
194+
188195
현재 binary 패키지 대상은 다음과 같습니다.
189196

190197
- Visual Studio 2022
@@ -237,10 +244,30 @@ GitHub Actions도 pull request와 push에서 prebuilt library와 패키지를
237244
생성합니다. `v0.1.12` 같은 태그를 push하면, 태그 버전이
238245
`include/.internal/version`과 일치할 때 NuGet Trusted Publishing을 통해
239246
nuget.org로 publish합니다.
247+
같은 태그 빌드는 GitHub Release asset도 생성합니다. 수동 workflow 실행에서
248+
`github_release=true`를 지정하면 태그를 새로 push하지 않고도 해당 버전의
249+
GitHub Release를 만들거나 갱신할 수 있습니다.
250+
251+
Release asset에는 다음 파일이 포함됩니다.
252+
253+
- 오프라인 NuGet 설치용 `crtsys.<version>.nupkg`.
254+
- 헤더, 문서, CMake helper, native MSBuild import, x64/ARM64 Debug/Release
255+
driver library가 포함된 `crtsys-<version>-native.zip`.
256+
- asset 검증용 `crtsys-<version>-SHA256SUMS.txt`.
257+
258+
native zip에는 `cmake/CrtSys.cmake`가 포함되며, 이 파일을 unpack된 bundle에서
259+
include하면 같은 `crtsys_add_driver` API가 prebuilt driver library를
260+
사용합니다. WDK CMake 프로젝트에서는 zip을 푼 뒤 다음처럼 사용할 수
261+
있습니다.
262+
263+
```cmake
264+
include(path/to/crtsys-<version>/cmake/CrtSys.cmake)
265+
crtsys_add_driver(my_driver src/main.cpp)
266+
```
240267

241268
GitHub Actions publish를 사용하려면 nuget.org Trusted Publishing policy를
242269
nuget.org에 표시되는 package owner, repository owner `ntoskrnl7`,
243-
repository `crtsys`, workflow file `nuget.yml`, environment 제한 없음으로
270+
repository `crtsys`, workflow file `package.yml`, environment 제한 없음으로
244271
생성합니다. GitHub Actions repository variable
245272
`NUGET_TRUSTED_PUBLISHING_USER`에는 policy를 생성한 nuget.org 사용자를
246273
설정합니다.

0 commit comments

Comments
 (0)