Skip to content

Commit f985bf1

Browse files
authored
Support releasing for Windows (#6)
Task/Issue URL: https://app.asana.com/1/137249556945/project/72649045549333/task/1211671201492810?focus=true ### Description * Remove `scripts/build_windows_gitbash.sh`. * Modify `scripts/build_windows.ps1` to build x64, x86 (32 bit) and arm64 versions of the library. * Add `.github/workflows/release_windows.yml` that builds the library and publishes it as a NuGet package. ### Steps to test this PR Check [this](https://github.com/duckduckgo/url_predictor/actions/runs/19570306840) workflow run that was successful.
1 parent 8786d0e commit f985bf1

File tree

5 files changed

+92
-61
lines changed

5 files changed

+92
-61
lines changed

.github/workflows/release.yml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,17 @@ jobs:
1616
tag: ${{ github.ref_name }}
1717

1818
# Add other platform-specific release jobs here as they are added.
19-
# release_windows:
20-
# uses: ./.github/workflows/release_windows.yml
21-
# with:
22-
# tag: ${{ github.ref_name }}
19+
release_windows:
20+
uses: ./.github/workflows/release_windows.yml
21+
with:
22+
tag: ${{ github.ref_name }}
2323

2424
release:
2525

2626
runs-on: ubuntu-latest
27-
# Wait for the Apple release workflow to complete
27+
# Wait for the Apple and Windows release workflows to complete
2828
# Add more platform-specific jobs here as they are added.
29-
needs: release_apple
29+
needs: [release_apple, release_windows]
3030

3131
steps:
3232

.github/workflows/release_windows.yml

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,36 @@ jobs:
2525
timeout-minutes: 20
2626
steps:
2727
- name: Checkout code
28-
uses: actions/checkout@v4
28+
uses: actions/checkout@v4
29+
30+
- name: Setup .NET
31+
uses: actions/setup-dotnet@v3
32+
with:
33+
dotnet-version: '6.0.x'
34+
source-url: 'https://pkgs.dev.azure.com/ddgwindows/windows-nuget/_packaging/windows-nuget-feed/nuget/v3/index.json'
35+
env:
36+
NUGET_AUTH_TOKEN: ${{ secrets.AZURE_DEVOPS_TOKEN }}
37+
38+
- name: Install Rust toolchain
39+
uses: dtolnay/rust-toolchain@stable
40+
41+
- name: Run unit tests
42+
env:
43+
CARGO_TERM_COLOR: always
44+
run: cargo test
45+
46+
- name: Run unit tests (with PSL)
47+
env:
48+
CARGO_TERM_COLOR: always
49+
run: cargo test --features real-psl
50+
51+
- name: Build Windows artifacts
52+
run: |
53+
.\scripts\build_windows.ps1
54+
55+
- name: Create and publish NuGet package
56+
run: |
57+
$version = "${{ inputs.tag }}" -replace '^v', ''
58+
nuget pack windows\windows.nuspec -Version $version -OutputDirectory dist\windows\nuget
59+
dotnet nuget push --skip-duplicate --api-key AzureArtifacts dist\windows\nuget\*.nupkg
60+

scripts/build_windows.ps1

Lines changed: 36 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,29 +4,52 @@ $crate = "url_predictor"
44
$features = ${env:FEATURES}
55
if (-not $features) { $features = "real-psl" }
66

7-
# Ensure target
8-
rustup target add x86_64-pc-windows-msvc
7+
# Define targets
8+
$targets = @(
9+
@{ name = "i686-pc-windows-msvc"; arch = "x86" },
10+
@{ name = "x86_64-pc-windows-msvc"; arch = "x64" },
11+
@{ name = "aarch64-pc-windows-msvc"; arch = "arm64" }
12+
)
13+
14+
# Ensure targets
15+
Write-Host "Installing targets..."
16+
foreach ($target in $targets) {
17+
rustup target add $target.name
18+
}
919

10-
# Build
11-
cargo build --release --features $features --target x86_64-pc-windows-msvc
20+
# Build all targets
21+
Write-Host "Building all architectures..."
22+
foreach ($target in $targets) {
23+
Write-Host "Building $($target.arch) version..."
24+
cargo build --release --features $features --target $target.name
25+
}
1226

13-
# Layout
27+
# Layout - Clean and create directories
1428
Remove-Item -Recurse -Force dist\windows -ErrorAction SilentlyContinue
1529
New-Item -ItemType Directory -Force dist\windows\bin | Out-Null
1630
New-Item -ItemType Directory -Force dist\windows\lib | Out-Null
1731
New-Item -ItemType Directory -Force dist\include | Out-Null
1832

19-
Copy-Item target\x86_64-pc-windows-msvc\release\$crate.dll dist\windows\bin\
20-
Copy-Item target\x86_64-pc-windows-msvc\release\$crate.lib dist\windows\lib\
21-
if (Test-Path target\x86_64-pc-windows-msvc\release\$crate.pdb) {
22-
Copy-Item target\x86_64-pc-windows-msvc\release\$crate.pdb dist\windows\bin\
33+
# Copy artifacts for each architecture with arch suffix
34+
foreach ($target in $targets) {
35+
$targetPath = "target\$($target.name)\release"
36+
$arch = $target.arch
37+
38+
Write-Host "Copying $arch artifacts..."
39+
Copy-Item $targetPath\$crate.dll dist\windows\bin\$crate-$arch.dll
40+
Copy-Item $targetPath\$crate.lib dist\windows\lib\$crate-$arch.lib
41+
if (Test-Path $targetPath\$crate.pdb) {
42+
Copy-Item $targetPath\$crate.pdb dist\windows\bin\$crate-$arch.pdb
43+
}
2344
}
2445

25-
# Header
46+
# Header (architecture-independent)
2647
if (-not (Get-Command cbindgen -ErrorAction SilentlyContinue)) {
27-
cargo install cbindgen
48+
cargo install cbindgen
2849
}
2950
cbindgen --config cbindgen.toml --crate $crate --output dist\include\ddg_url_predictor.h
3051

31-
Write-Host "✅ Windows artifacts at dist\windows\ (dll/lib/pdb) and header in dist\include"
32-
52+
Write-Host "✅ Windows artifacts built for all architectures:"
53+
Write-Host " - DLLs: dist\windows\bin\ ($crate-x86.dll, $crate-x64.dll, $crate-arm64.dll)"
54+
Write-Host " - LIBs: dist\windows\lib\ ($crate-x86.lib, $crate-x64.lib, $crate-arm64.lib)"
55+
Write-Host " - Header: dist\include\ddg_url_predictor.h"

scripts/build_windows_gitbash.sh

Lines changed: 0 additions & 41 deletions
This file was deleted.

windows/windows.nuspec

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<package xmlns="http://schemas.microsoft.com/packaging/2013/05/nuspec.xsd">
3+
<metadata>
4+
<id>DdgUrlPredictor</id>
5+
<version>0.0.0-dev</version>
6+
<title>DdgUrlPredictor</title>
7+
<authors>DuckDuckGo</authors>
8+
<requireLicenseAcceptance>false</requireLicenseAcceptance>
9+
<description>Distributable files of DDG's url predictor</description>
10+
<dependencies />
11+
</metadata>
12+
<files>
13+
<file src="..\dist\windows\bin\url_predictor-x64.dll" target="runtimes\win-x64\native\url_predictor.dll" />
14+
<file src="..\dist\windows\bin\url_predictor-x86.dll" target="runtimes\win-x86\native\url_predictor.dll" />
15+
<file src="..\dist\windows\bin\url_predictor-arm64.dll" target="runtimes\win-arm64\native\url_predictor.dll" />
16+
</files>
17+
</package>

0 commit comments

Comments
 (0)