Skip to content

Commit 55a791f

Browse files
authored
Merge pull request #3 from tonyroberts/cmake
- Make it possible to build the native dlls again, and invoke cmake directly from mvn for easier rebuilding. - Build the native libraries in a github action. Fixes kohsuke#97
2 parents 597764d + 6dbe079 commit 55a791f

27 files changed

Lines changed: 494 additions & 82 deletions

File tree

‎.github/workflows/build.yml‎

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
name: Build
2+
3+
on:
4+
push:
5+
branches: [ master ]
6+
pull_request:
7+
workflow_dispatch:
8+
9+
jobs:
10+
build:
11+
# windows-2022 ships Visual Studio 2022 (with the C++ ATL and MFC
12+
# components the native build needs) and CMake preinstalled.
13+
runs-on: windows-2022
14+
15+
steps:
16+
- name: Check out repository (with submodules)
17+
uses: actions/checkout@v7
18+
with:
19+
submodules: recursive
20+
21+
- name: Set up JDK
22+
uses: actions/setup-java@v5
23+
with:
24+
distribution: temurin
25+
java-version: '17'
26+
cache: maven
27+
28+
- name: Show build tool versions
29+
shell: pwsh
30+
run: |
31+
cmake --version
32+
java -version
33+
34+
# -DbuildNative=true forces a real rebuild instead of packaging the
35+
# committed bin/ DLLs (JitPack's only option, since it can't run
36+
# MSVC). package-only, run first, just to catch Release-only compile
37+
# regressions before the Debug build below becomes the installed jar.
38+
- name: Build native (Release)
39+
shell: pwsh
40+
run: mvn -B -pl "!test" package -DbuildNative=true -Dmode=Release
41+
42+
# TestObject (needed by tests) only compiles into Debug builds.
43+
# install, not package, so "Run tests" below can resolve com4j from
44+
# the local repo without rebuilding or needing -am.
45+
- name: Build native (Debug)
46+
shell: pwsh
47+
run: mvn -B -pl "!test" install -DbuildNative=true -Dmode=Debug
48+
49+
# Registers com4j.dll as TestObject's COM server. Plain regsvr32
50+
# works unelevated: GitHub's Windows runners run as Administrator
51+
# with UAC disabled (actions/runner-images discussion #6557).
52+
- name: Register COM test object
53+
shell: pwsh
54+
run: |
55+
$dll = Resolve-Path "bin\x64\Debug\com4j.dll"
56+
$p = Start-Process -FilePath "$env:SystemRoot\System32\regsvr32.exe" -ArgumentList "/s", "$dll" -Wait -PassThru -NoNewWindow
57+
if ($p.ExitCode -ne 0) {
58+
throw "regsvr32 failed with exit code $($p.ExitCode)"
59+
}
60+
61+
- name: Run tests
62+
shell: pwsh
63+
run: mvn -B test -pl test

‎.github/workflows/release.yml‎

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
name: Release
2+
3+
on:
4+
release:
5+
types: [published]
6+
7+
permissions:
8+
contents: write
9+
10+
jobs:
11+
build-and-upload:
12+
runs-on: windows-2022
13+
14+
steps:
15+
- name: Check out repository (with submodules) at the release tag
16+
uses: actions/checkout@v7
17+
with:
18+
submodules: recursive
19+
ref: ${{ github.event.release.tag_name }}
20+
21+
- name: Set up JDK
22+
uses: actions/setup-java@v5
23+
with:
24+
distribution: temurin
25+
java-version: '17'
26+
cache: maven
27+
28+
# Sets the version to the release tag
29+
- name: Set version to release tag
30+
shell: pwsh
31+
run: mvn -B versions:set "-DnewVersion=${{ github.event.release.tag_name }}" -DgenerateBackupPoms=false
32+
33+
# Rebuilds native/com4j.dll (Release, x86+x64) from source rather than
34+
# trusting whatever's committed, so the uploaded jar always reflects
35+
# the exact code at this tag.
36+
- name: Build native (Release) and package
37+
shell: pwsh
38+
run: mvn -B -pl "!test" package -DbuildNative=true -Dmode=Release
39+
40+
# Uploads all modules' built artifacts as release assets
41+
- name: Upload build artifacts to the release
42+
shell: pwsh
43+
env:
44+
GH_TOKEN: ${{ github.token }}
45+
run: |
46+
function Latest($pattern) {
47+
(Get-ChildItem $pattern | Sort-Object LastWriteTime -Descending | Select-Object -First 1).FullName
48+
}
49+
$files = @(
50+
Latest "runtime/target/com4j-*.jar"
51+
Latest "tlbimp/target/tlbimp-*.jar"
52+
Latest "maven-com4j-plugin/target/maven-com4j-plugin-*.jar"
53+
Latest "distribution/target/com4j-dist-*-all.zip"
54+
)
55+
gh release upload "${{ github.event.release.tag_name }}" $files --repo ${{ github.repository }} --clobber

‎.gitignore‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,8 @@
1010
*.tli
1111
vc90.idb
1212
vc90.pdb
13+
native/cmake-build*/
14+
15+
# bin/ holds the prebuilt com4j.dll (x86 and x64, Release and Debug) that the
16+
# Java build packages by default and that JitPack relies on, since it can't
17+
# build native/ itself - these are intentionally committed, do not ignore.

‎.gitmodules‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
[submodule "jnitl"]
22
path = jnitl
3-
url = git://github.com/kohsuke/jnitl.git
3+
url = https://github.com/kohsuke/jnitl.git

0 commit comments

Comments
 (0)