Skip to content

Commit

Permalink
feat: support musl variants of pact ffi and upgrade to pact_ffi 0.4.17
Browse files Browse the repository at this point in the history
  • Loading branch information
YOU54F committed Feb 22, 2024
1 parent 09ee818 commit 51ae9ff
Show file tree
Hide file tree
Showing 12 changed files with 121 additions and 13 deletions.
36 changes: 36 additions & 0 deletions .cirrus.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
BUILD_TEST_TASK_TEMPLATE: &BUILD_TEST_TASK_TEMPLATE
arch_check_script: |
uname -m
ffi_download_script: |
chmod +x build/download-native-libs.sh
build/download-native-libs.sh
restore_script: |
dotnet restore
build_script: |
dotnet build --no-restore
test_script: |
dotnet test --no-build --verbosity normal
pack_script: |
dotnet pack --verbosity normal -c Release --no-restore --include-source --version-suffix alpha.123 -o ./dist
linux_arm64_task:
arm_container:
image: mcr.microsoft.com/dotnet/sdk:7.0
<< : *BUILD_TEST_TASK_TEMPLATE

linux_amd64_task:
container:
image: mcr.microsoft.com/dotnet/sdk:7.0
<< : *BUILD_TEST_TASK_TEMPLATE

linux_arm64_alpine_task:
arm_container:
image: mcr.microsoft.com/dotnet/sdk:7.0-alpine
setup_alpine_script: apk add --no-cache curl bash gzip
<< : *BUILD_TEST_TASK_TEMPLATE

linux_amd64_alpine_task:
container:
image: mcr.microsoft.com/dotnet/sdk:7.0-alpine
setup_alpine_script: apk add --no-cache curl bash gzip
<< : *BUILD_TEST_TASK_TEMPLATE
33 changes: 31 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ jobs:
build-dotnet:
name: "Build and Test (dotnet)"
strategy:
fail-fast: false
matrix:
os:
- windows-latest
Expand All @@ -22,6 +23,14 @@ jobs:
- arch: x64
- arch: ARM64
os: macos-14
- os: ubuntu-latest
alpine: true
arch: x86_64
# - os: ubuntu-latest
# alpine: true
# arch: aarch64
## Skipped as .NET does not work with QEMU https://github.com/dotnet/core/blob/main/release-notes/8.0/supported-os.md#qemu

runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v4
Expand All @@ -42,19 +51,39 @@ jobs:
build/osx
build/windows
- name: Set up QEMU
if: matrix.alpine == true
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
if: matrix.alpine == true
uses: docker/setup-buildx-action@v3
- name: Pull interop dependencies
if: matrix.alpine != true && ${{ steps.cache.outputs.cache-hit != 'true' }}
run: bash -c "build/download-native-libs.sh"
if: ${{ steps.cache.outputs.cache-hit != 'true' }}

- name: Restore
if: matrix.alpine != true
run: dotnet restore

- name: Build
if: matrix.alpine != true
run: dotnet build --no-restore

- name: Test
run: dotnet test --no-build --verbosity normal -- RunConfiguration.TargetPlatform=${{matrix.arch}}
if: matrix.alpine != true
run: dotnet test --no-build --verbosity normal

- name: test linux amd64 musl
if: matrix.alpine == true && matrix.arch == 'x86_64'
run: |
docker run --platform=linux/amd64 --rm -v $PWD:/app mcr.microsoft.com/dotnet/sdk:8.0-alpine /bin/sh -c 'apk add --no-cache curl bash gzip && cd /app && build/download-native-libs.sh && dotnet restore && dotnet build --no-restore && dotnet test --no-build --verbosity normal'
## Skipped as .NET does not work with QEMU https://github.com/dotnet/core/blob/main/release-notes/8.0/supported-os.md#qemu
# - name: test linux arm64 musl
# if: matrix.alpine == true && matrix.arch == 'aarch64'
# run: |
# docker run --platform=linux/arm64 --rm -v $PWD:/app mcr.microsoft.com/dotnet/sdk:8.0-alpine /bin/sh -c 'apk add --no-cache curl bash gzip && cd /app && build/download-native-libs.sh && dotnet restore && dotnet build --no-restore && dotnet test --no-build --verbosity normal'

- name: Pack
if: matrix.os == 'windows-latest'
run: dotnet pack --verbosity normal -c Release --no-restore --include-source --version-suffix alpha.${{ github.run_number }} -o ./dist
Expand Down
21 changes: 20 additions & 1 deletion build/download-native-libs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,23 @@ download_native() {
shasum -a 256 --check --quiet "$path/$dest_file.sha256"
else
sed -Ei "s|../release_artifacts/.+$|$path/$dest_file|" "$path/$dest_file.sha256"
sha256sum --check --quiet "$path/$dest_file.sha256"
if [[ "$OSTYPE" == "linux"* ]]; then
if ldd /bin/ls >/dev/null 2>&1; then
ldd_output=$(ldd /bin/ls)
case "$ldd_output" in
*musl*)
sha256sum -c -s "$path/$dest_file.sha256"
;;
*)
sha256sum --check --quiet "$path/$dest_file.sha256"
;;
esac
else
sha256sum --check --quiet "$path/$dest_file.sha256"
fi
else
sha256sum --check --quiet "$path/$dest_file.sha256"
fi
fi

rm "$path/$dest_file.sha256"
Expand All @@ -60,5 +76,8 @@ download_native() {

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" "linux" "x86_64-musl" "so"
download_native "libpact_ffi" "linux" "aarch64-musl" "so"
download_native "libpact_ffi" "osx" "x86_64" "dylib"
download_native "libpact_ffi" "osx" "aarch64-apple-darwin" "dylib"
28 changes: 26 additions & 2 deletions src/PactNet/PactNet.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@
<IsOSX>False</IsOSX>
<IsArm64>False</IsArm64>
<IsWindows Condition="'$([System.Runtime.InteropServices.RuntimeInformation]::IsOSPlatform($([System.Runtime.InteropServices.OSPlatform]::Windows)))' == 'True'">True</IsWindows>
<IsLinux Condition="'$([System.Runtime.InteropServices.RuntimeInformation]::IsOSPlatform($([System.Runtime.InteropServices.OSPlatform]::Linux)))' == 'True'">True</IsLinux>
<IsLinuxX64 Condition="'$([System.Runtime.InteropServices.RuntimeInformation]::IsOSPlatform($([System.Runtime.InteropServices.OSPlatform]::Linux)))' == 'True' And $([System.IO.File]::Exists('/lib/libc.musl-x86_64.so.1')) == 'False' And '$([System.Runtime.InteropServices.RuntimeInformation]::OSArchitecture)' != 'Arm64'">True</IsLinuxX64>
<IsLinuxArm64 Condition="'$([System.Runtime.InteropServices.RuntimeInformation]::IsOSPlatform($([System.Runtime.InteropServices.OSPlatform]::Linux)))' == 'True' And $([System.IO.File]::Exists('/lib/libc.musl-aarch64.so.1')) == 'False' And '$([System.Runtime.InteropServices.RuntimeInformation]::OSArchitecture)' == 'Arm64'">True</IsLinuxArm64>
<IsLinuxMuslX64 Condition="'$([System.Runtime.InteropServices.RuntimeInformation]::IsOSPlatform($([System.Runtime.InteropServices.OSPlatform]::Linux)))' == 'True' And $([System.IO.File]::Exists('/lib/libc.musl-x86_64.so.1')) == 'True' And '$([System.Runtime.InteropServices.RuntimeInformation]::OSArchitecture)' != 'Arm64'">True</IsLinuxMuslX64>
<IsLinuxMuslArm64 Condition="'$([System.Runtime.InteropServices.RuntimeInformation]::IsOSPlatform($([System.Runtime.InteropServices.OSPlatform]::Linux)))' == 'True' And $([System.IO.File]::Exists('/lib/libc.musl-aarch64.so.1')) == 'True' And '$([System.Runtime.InteropServices.RuntimeInformation]::OSArchitecture)' == 'Arm64'">True</IsLinuxMuslArm64>
<IsOSX Condition="'$([System.Runtime.InteropServices.RuntimeInformation]::IsOSPlatform($([System.Runtime.InteropServices.OSPlatform]::OSX)))' == 'True'">True</IsOSX>
<IsArm64 Condition="'$([System.Runtime.InteropServices.RuntimeInformation]::OSArchitecture)' == 'Arm64'">True</IsArm64>
</PropertyGroup>
Expand All @@ -33,7 +36,28 @@
<Link>libpact_ffi.so</Link>
<PackagePath>runtimes/linux-x64/native</PackagePath>
<Pack>true</Pack>
<CopyToOutputDirectory Condition="'$(IsLinux)'">PreserveNewest</CopyToOutputDirectory>
<CopyToOutputDirectory Condition="'$(IsLinuxX64)' == 'True'">PreserveNewest</CopyToOutputDirectory>
<Visible>false</Visible>
</Content>
<Content Include="$(MSBuildProjectDirectory)\..\..\build\linux\aarch64\libpact_ffi.so">
<Link>libpact_ffi.so</Link>
<PackagePath>runtimes/linux-arm64/native</PackagePath>
<Pack>true</Pack>
<CopyToOutputDirectory Condition="'$(IsLinuxArm64)' == 'True'">PreserveNewest</CopyToOutputDirectory>
<Visible>false</Visible>
</Content>
<Content Include="$(MSBuildProjectDirectory)\..\..\build\linux\x86_64-musl\libpact_ffi.so">
<Link>libpact_ffi.so</Link>
<PackagePath>runtimes/linux-x64-musl/native</PackagePath>
<Pack>true</Pack>
<CopyToOutputDirectory Condition="'$(IsLinuxMuslX64)' == 'True'">PreserveNewest</CopyToOutputDirectory>
<Visible>false</Visible>
</Content>
<Content Include="$(MSBuildProjectDirectory)\..\..\build\linux\aarch64-musl\libpact_ffi.so">
<Link>libpact_ffi.so</Link>
<PackagePath>runtimes/linux-arm64-musl/native</PackagePath>
<Pack>true</Pack>
<CopyToOutputDirectory Condition="'$(IsLinuxMuslArm64)' == 'True'">PreserveNewest</CopyToOutputDirectory>
<Visible>false</Visible>
</Content>
<Content Include="$(MSBuildProjectDirectory)\..\..\build\osx\x86_64\libpact_ffi.dylib">
Expand Down
2 changes: 1 addition & 1 deletion tests/PactNet.Tests/data/v2-consumer-integration.json
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@
],
"metadata": {
"pactRust": {
"ffi": "0.4.16",
"ffi": "0.4.17",
"models": "1.1.19"
},
"pactSpecification": {
Expand Down
2 changes: 1 addition & 1 deletion tests/PactNet.Tests/data/v3-consumer-integration.json
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@
],
"metadata": {
"pactRust": {
"ffi": "0.4.16",
"ffi": "0.4.17",
"models": "1.1.19"
},
"pactSpecification": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
"language": "C#"
},
"pactRust": {
"ffi": "0.4.16",
"ffi": "0.4.17",
"models": "1.1.19"
},
"pactSpecification": {
Expand Down
2 changes: 1 addition & 1 deletion tests/PactNet.Tests/data/v3-message-integration.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
],
"metadata": {
"pactRust": {
"ffi": "0.4.16",
"ffi": "0.4.17",
"models": "1.1.19"
},
"pactSpecification": {
Expand Down
2 changes: 1 addition & 1 deletion tests/PactNet.Tests/data/v3-server-integration.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
],
"metadata": {
"pactRust": {
"ffi": "0.4.16",
"ffi": "0.4.17",
"models": "1.1.19"
},
"pactSpecification": {
Expand Down
2 changes: 1 addition & 1 deletion tests/PactNet.Tests/data/v4-combined-integration.json
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@
"language": "C#"
},
"pactRust": {
"ffi": "0.4.16",
"ffi": "0.4.17",
"models": "1.1.19"
},
"pactSpecification": {
Expand Down
2 changes: 1 addition & 1 deletion tests/PactNet.Tests/data/v4-consumer-integration.json
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@
],
"metadata": {
"pactRust": {
"ffi": "0.4.16",
"ffi": "0.4.17",
"models": "1.1.19"
},
"pactSpecification": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
"language": "C#"
},
"pactRust": {
"ffi": "0.4.16",
"ffi": "0.4.17",
"models": "1.1.19"
},
"pactSpecification": {
Expand Down

0 comments on commit 51ae9ff

Please sign in to comment.