Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ jobs:
os: macos-15
- arch: ARM64
os: ubuntu-24.04-arm
- arch: ARM64
os: windows-11-arm
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v7
Expand Down
12 changes: 8 additions & 4 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,16 @@ Building PactNet
----------------

In order to build PactNet you must first download the native Rust FFI libraries. You can pull the current supported
version by executing the script in Bash (or Git Bash on Windows):
version by executing the script in Bash (or Git Bash on Windows). The script needs `curl`, `tar` with xz support, and
`unzip` (or `7z`) on the path, and verifies each archive against its `.sha256` file:

```bash
build/download-native-libs.sh
```

Alternatively you can download a particular FFI version from the [pact-reference] releases or build your own version
locally, and then copy the artifacts into the folders:
Alternatively you can download a particular FFI version from the [pact-reference] `pact_ffi-v<version>` releases (one
archive per Rust target, e.g. `pact_ffi-aarch64-apple-darwin.tar.xz`) or build your own version locally, and then copy
the shared libraries into the folders:

```
build/
Expand All @@ -69,12 +71,14 @@ build/
libpact_ffi.so
aarch64/
libpact_ffi.so
osx/
macos/
aarch64/
libpact_ffi.dylib
x86_64/
libpact_ffi.dylib
windows/
aarch64/
pact_ffi.dll
x86_64/
pact_ffi.dll
```
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,7 @@ Due to using a shared native library instead of C# for the main Pact logic only
| ------------ | ------------ | -------------------------------------------------------------------|
| Windows | x86 | ❌ No |
| Windows | x64 | ✔️ Yes |
| Windows | ARM64 | ✔️ Yes |
| Linux (libc) | ARM64 | ✔️ Yes |
| Linux (libc) | x64 | ✔️ Yes |
| Linux (libc) | x86 | ❌ No |
Expand Down
16 changes: 14 additions & 2 deletions build/PactNet.targets
Original file line number Diff line number Diff line change
@@ -1,7 +1,19 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<!-- This file supports .Net Framework, which doesn't automatically unpack the runtimes folder -->
<ItemGroup>
<!--
This file supports .Net Framework, which doesn't automatically unpack the runtimes folder.

The ARM64 library is used when the consuming project targets ARM64 explicitly, otherwise the x64 library is used
(which also runs under x64 emulation on Windows on ARM).
-->
<ItemGroup Condition="'$(PlatformTarget)' == 'ARM64'">
<Content Include="$(MSBuildThisFileDirectory)..\..\runtimes\win-arm64\native\pact_ffi.dll">
<Link>pact_ffi.dll</Link>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<Visible>false</Visible>
</Content>
</ItemGroup>
<ItemGroup Condition="'$(PlatformTarget)' != 'ARM64'">
<Content Include="$(MSBuildThisFileDirectory)..\..\runtimes\win-x64\native\pact_ffi.dll">
<Link>pact_ffi.dll</Link>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
Expand Down
72 changes: 44 additions & 28 deletions build/download-native-libs.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#!/usr/bin/env bash
set -euo pipefail

FFI_VERSION="0.4.27"
FFI_BASE_URL="https://github.com/pact-foundation/pact-reference/releases/download/libpact_ffi-v$FFI_VERSION"
FFI_VERSION="0.5.13"
FFI_BASE_URL="https://github.com/pact-foundation/pact-reference/releases/download/pact_ffi-v$FFI_VERSION"

GREEN="\e[32m"
YELLOW="\e[33m"
Expand All @@ -12,60 +12,76 @@ CLEAR="\e[0m"
base_path=$(dirname "$0")

download_native() {
file="$1"
os="$2"
platform="$3"
extension="$4"
os="$1"
platform="$2"
target="$3"
archive_ext="$4"
lib="$5"

# e.g.
# pact_ffi-windows-x86_64.dll.gz
# libpact_ffi-linux-x86_64.so.gz
# libpact_ffi-macos-x86_64.dylib.gz
src_file="$file-$os-$platform.$extension"
src_archive="$src_file.gz"
# pact_ffi-x86_64-pc-windows-msvc.zip (pact_ffi.dll at the archive root)
# pact_ffi-x86_64-unknown-linux-gnu.tar.xz (pact_ffi-<target>/libpact_ffi.so)
# pact_ffi-aarch64-apple-darwin.tar.xz (pact_ffi-<target>/libpact_ffi.dylib)
src_archive="pact_ffi-$target.$archive_ext"
src_sha="$src_archive.sha256"
dest_file="$file.$extension"
url="$FFI_BASE_URL/$src_archive"
sha="$url.sha256"

path="$base_path/$os/$platform"
mkdir -p "$path"
pushd $path > /dev/null
pushd "$path" > /dev/null

echo -e "Downloading FFI library for ${YELLOW}$os/$platform${CLEAR}"
echo -e " Destination: ${BLUE}$path/$src_archive${CLEAR}"
echo -e " Destination: ${BLUE}$path/$lib${CLEAR}"
echo -e " URL: ${BLUE}$url${CLEAR}"

echo -n " Downloading... "
curl --silent -L "$url" -o "$src_archive"
curl --silent -L "$sha" -o "$src_archive.sha256"
curl --silent --show-error --fail -L "$url" -o "$src_archive"
curl --silent --show-error --fail -L "$sha" -o "$src_sha"
echo -e "${GREEN}OK${CLEAR}"

echo -n " Verifying... "

if [[ "$OSTYPE" == "darwin"* ]]; then
shasum -a 256 --check --quiet "$src_sha"
sed '/^$/d' "$src_sha" | shasum -a 256 --check --quiet -
else
sha256sum --check --quiet "$src_sha"
sed '/^$/d' "$src_sha" | sha256sum --check --quiet -
fi

echo -e "${GREEN}OK${CLEAR}"

echo -n " Extracting... "
gunzip -f "$src_archive"
extract_dir=$(mktemp -d)
if [[ "$archive_ext" == "zip" ]]; then
extract_zip "$src_archive" "$extract_dir"
extracted="$extract_dir/$lib"
else
tar -xJf "$src_archive" -C "$extract_dir"
extracted="$extract_dir/pact_ffi-$target/$lib"
fi
mv -f "$extracted" "$lib"
rm -rf "$extract_dir" "$src_archive" "$src_sha"
echo -e "${GREEN}OK${CLEAR}"
echo ""

mv "$src_file" "$dest_file"
rm "$src_sha"

popd > /dev/null
}

download_native "pact_ffi" "windows" "x86_64" "dll"
download_native "libpact_ffi" "linux" "x86_64" "so"
download_native "libpact_ffi" "linux" "aarch64" "so"
download_native "libpact_ffi" "macos" "x86_64" "dylib"
download_native "libpact_ffi" "macos" "aarch64" "dylib"
extract_zip() {
if command -v unzip > /dev/null; then
unzip -q -o "$1" -d "$2"
elif command -v 7z > /dev/null; then
7z x -y -o"$2" "$1" > /dev/null
else
tar -xf "$1" -C "$2"
fi
}

download_native "windows" "x86_64" "x86_64-pc-windows-msvc" "zip" "pact_ffi.dll"
download_native "windows" "aarch64" "aarch64-pc-windows-msvc" "zip" "pact_ffi.dll"
download_native "linux" "x86_64" "x86_64-unknown-linux-gnu" "tar.xz" "libpact_ffi.so"
download_native "linux" "aarch64" "aarch64-unknown-linux-gnu" "tar.xz" "libpact_ffi.so"
download_native "macos" "x86_64" "x86_64-apple-darwin" "tar.xz" "libpact_ffi.dylib"
download_native "macos" "aarch64" "aarch64-apple-darwin" "tar.xz" "libpact_ffi.dylib"

echo "Successfully downloaded FFI libraries"
echo "Successfully downloaded FFI libraries"
Original file line number Diff line number Diff line change
Expand Up @@ -158,8 +158,8 @@
],
"metadata": {
"pactRust": {
"ffi": "0.4.27",
"models": "1.2.8"
"ffi": "0.5.13",
"models": "1.3.18"
},
"pactSpecification": {
"version": "4.0"
Expand Down
3 changes: 3 additions & 0 deletions samples/OrdersApi/Provider.Tests/Provider.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<IsPackable>false</IsPackable>
<!-- .NET SDK 11 generates hot reload browser-tools assets for Web SDK projects in Debug,
which fail the static web assets endpoint check in a test project. -->
<EnableHotReloadInRuntimeConfigDevFile>false</EnableHotReloadInRuntimeConfigDevFile>
</PropertyGroup>

<ItemGroup>
Expand Down
9 changes: 8 additions & 1 deletion src/PactNet/PactNet.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,14 @@
<Link>pact_ffi.dll</Link>
<PackagePath>runtimes/win-x64/native</PackagePath>
<Pack>true</Pack>
<CopyToOutputDirectory Condition="'$(IsWindows)'">PreserveNewest</CopyToOutputDirectory>
<CopyToOutputDirectory Condition="'$(IsWindows)' == 'True' And '$(IsArm64)' == 'False'">PreserveNewest</CopyToOutputDirectory>
<Visible>false</Visible>
</Content>
<Content Include="$(MSBuildProjectDirectory)\..\..\build\windows\aarch64\pact_ffi.dll">
<Link>pact_ffi.dll</Link>
<PackagePath>runtimes/win-arm64/native</PackagePath>
<Pack>true</Pack>
<CopyToOutputDirectory Condition="'$(IsWindows)' == 'True' And '$(IsArm64)' == 'True'">PreserveNewest</CopyToOutputDirectory>
<Visible>false</Visible>
</Content>
<Content Include="$(MSBuildProjectDirectory)\..\..\build\linux\x86_64\libpact_ffi.so">
Expand Down
4 changes: 2 additions & 2 deletions tests/PactNet.Tests/data/v2-consumer-integration.json
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@
],
"metadata": {
"pactRust": {
"ffi": "0.4.27",
"models": "1.2.8"
"ffi": "0.5.13",
"models": "1.3.18"
},
"pactSpecification": {
"version": "2.0.0"
Expand Down
4 changes: 2 additions & 2 deletions tests/PactNet.Tests/data/v3-consumer-integration.json
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,8 @@
],
"metadata": {
"pactRust": {
"ffi": "0.4.27",
"models": "1.2.8"
"ffi": "0.5.13",
"models": "1.3.18"
},
"pactSpecification": {
"version": "3.0.0"
Expand Down
4 changes: 2 additions & 2 deletions tests/PactNet.Tests/data/v3-message-consumer-integration.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@
"language": "C#"
},
"pactRust": {
"ffi": "0.4.27",
"models": "1.2.8"
"ffi": "0.5.13",
"models": "1.3.18"
},
"pactSpecification": {
"version": "3.0.0"
Expand Down
4 changes: 2 additions & 2 deletions tests/PactNet.Tests/data/v3-message-integration.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
],
"metadata": {
"pactRust": {
"ffi": "0.4.27",
"models": "1.2.8"
"ffi": "0.5.13",
"models": "1.3.18"
},
"pactSpecification": {
"version": "3.0.0"
Expand Down
4 changes: 2 additions & 2 deletions tests/PactNet.Tests/data/v3-server-integration.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@
],
"metadata": {
"pactRust": {
"ffi": "0.4.27",
"models": "1.2.8"
"ffi": "0.5.13",
"models": "1.3.18"
},
"pactSpecification": {
"version": "3.0.0"
Expand Down
4 changes: 2 additions & 2 deletions tests/PactNet.Tests/data/v4-combined-integration.json
Original file line number Diff line number Diff line change
Expand Up @@ -185,8 +185,8 @@
"language": "C#"
},
"pactRust": {
"ffi": "0.4.27",
"models": "1.2.8"
"ffi": "0.5.13",
"models": "1.3.18"
},
"pactSpecification": {
"version": "4.0"
Expand Down
4 changes: 2 additions & 2 deletions tests/PactNet.Tests/data/v4-consumer-integration.json
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,8 @@
],
"metadata": {
"pactRust": {
"ffi": "0.4.27",
"models": "1.2.8"
"ffi": "0.5.13",
"models": "1.3.18"
},
"pactSpecification": {
"version": "4.0"
Expand Down
4 changes: 2 additions & 2 deletions tests/PactNet.Tests/data/v4-message-consumer-integration.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@
"language": "C#"
},
"pactRust": {
"ffi": "0.4.27",
"models": "1.2.8"
"ffi": "0.5.13",
"models": "1.3.18"
},
"pactSpecification": {
"version": "4.0"
Expand Down
Loading