Change the ref to main #202
Workflow file for this run
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Build Native Library | |
| on: | |
| workflow_dispatch: | |
| push: | |
| branches: [ main ] | |
| tags: ["v*"] | |
| pull_request: | |
| branches: [ main ] | |
| env: | |
| dd_trace_go_ref: "main" | |
| jobs: | |
| mac_job: | |
| name: macOS | |
| runs-on: macos-14 | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - uses: actions/setup-go@v5 | |
| with: | |
| go-version: '1.24' | |
| - run: brew install coreutils | |
| - name: Checkout external repository | |
| uses: actions/checkout@v4 | |
| with: | |
| repository: "DataDog/dd-trace-go" | |
| ref: ${{ env.dd_trace_go_ref }} | |
| token: ${{ secrets.GITHUB_TOKEN }} | |
| path: external | |
| - name: Copy build files | |
| run: | | |
| # Create the directory if it doesn't exist | |
| mkdir -p external/internal/civisibility/native | |
| # Copy the build files | |
| cp -rf ./build/* external/internal/civisibility/native/ | |
| # Copy the native files | |
| cp -rf ./native/* external/internal/civisibility/native/ | |
| - name: Build for macOS and iOS | |
| run: | | |
| # ******************** Build for macOS ******************** | |
| export CGO_CFLAGS="-mmacosx-version-min=11.0 -O2 -Os -DNDEBUG -fdata-sections -ffunction-sections" | |
| export CGO_LDFLAGS="-Wl,-x" | |
| export GOOS=darwin | |
| export CGO_ENABLED=1 | |
| GOARCH=arm64 go build -tags civisibility_native -buildmode=c-archive -ldflags="-s -w" -gcflags="all=-l" -o ./output/macos-arm64-libtestoptimization-static/libtestoptimization.a *.go | |
| GOARCH=arm64 go build -tags civisibility_native -buildmode=c-shared -ldflags="-s -w" -gcflags="all=-l" -o ./output/macos-arm64-libtestoptimization-dynamic/libtestoptimization.dylib *.go | |
| strip -x ./output/macos-arm64-libtestoptimization-dynamic/libtestoptimization.dylib | |
| GOARCH=amd64 go build -tags civisibility_native -buildmode=c-archive -ldflags="-s -w" -gcflags="all=-l" -o ./output/macos-x64-libtestoptimization-static/libtestoptimization.a *.go | |
| GOARCH=amd64 go build -tags civisibility_native -buildmode=c-shared -ldflags="-s -w" -gcflags="all=-l" -o ./output/macos-x64-libtestoptimization-dynamic/libtestoptimization.dylib *.go | |
| strip -x ./output/macos-x64-libtestoptimization-dynamic/libtestoptimization.dylib | |
| # ********************************************************* | |
| mkdir -p ./output/macos-libtestoptimization-static | |
| lipo -create ./output/macos-arm64-libtestoptimization-static/libtestoptimization.a ./output/macos-x64-libtestoptimization-static/libtestoptimization.a -output ./output/macos-libtestoptimization-static/libtestoptimization.a | |
| cp ./output/macos-arm64-libtestoptimization-static/libtestoptimization.h ./output/macos-libtestoptimization-static/libtestoptimization.h | |
| zip -j -9 ./output/macos-libtestoptimization-static.zip ./output/macos-libtestoptimization-static/*.* | |
| sha256sum ./output/macos-libtestoptimization-static.zip > ./output/macos-libtestoptimization-static.zip.sha256sum | |
| rm -r ./output/macos-libtestoptimization-static | |
| mkdir -p ./output/macos-libtestoptimization-dynamic | |
| lipo -create ./output/macos-arm64-libtestoptimization-dynamic/libtestoptimization.dylib ./output/macos-x64-libtestoptimization-dynamic/libtestoptimization.dylib -output ./output/macos-libtestoptimization-dynamic/libtestoptimization.dylib | |
| cp ./output/macos-arm64-libtestoptimization-dynamic/libtestoptimization.h ./output/macos-libtestoptimization-dynamic/libtestoptimization.h | |
| zip -j -9 ./output/macos-libtestoptimization-dynamic.zip ./output/macos-libtestoptimization-dynamic/*.* | |
| sha256sum ./output/macos-libtestoptimization-dynamic.zip > ./output/macos-libtestoptimization-dynamic.zip.sha256sum | |
| rm -r ./output/macos-libtestoptimization-dynamic | |
| rm -r ./output/macos-arm64-libtestoptimization-static ./output/macos-arm64-libtestoptimization-dynamic ./output/macos-x64-libtestoptimization-static ./output/macos-x64-libtestoptimization-dynamic | |
| # ******************** Build for iOS ******************** | |
| GOOS=ios GOARCH=arm64 CGO_ENABLED=1 go build -tags civisibility_native -buildmode=c-archive -ldflags="-s -w" -gcflags="all=-l" -o ./output/ios-libtestoptimization-static/libtestoptimization.a *.go | |
| zip -j -9 ./output/ios-libtestoptimization-static.zip ./output/ios-libtestoptimization-static/*.* | |
| sha256sum ./output/ios-libtestoptimization-static.zip > ./output/ios-libtestoptimization-static.zip.sha256sum | |
| rm -r ./output/ios-libtestoptimization-static | |
| working-directory: external/internal/civisibility/native | |
| - name: Upload artifact | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: mac-artifact | |
| path: external/internal/civisibility/native/output/*.zip* | |
| linux_arm64_job: | |
| name: linux-arm64 | |
| runs-on: ubuntu-24.04 | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Set up QEMU | |
| uses: docker/setup-qemu-action@v3 | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@v3 | |
| - name: Checkout external repository | |
| uses: actions/checkout@v4 | |
| with: | |
| repository: "DataDog/dd-trace-go" | |
| ref: ${{ env.dd_trace_go_ref }} | |
| token: ${{ secrets.GITHUB_TOKEN }} | |
| path: external | |
| - name: Copy build files | |
| run: | | |
| # Create the directory if it doesn't exist | |
| mkdir -p external/internal/civisibility/native | |
| # Copy the build files | |
| cp -rf ./build/* external/internal/civisibility/native/ | |
| # Copy the native files | |
| cp -rf ./native/* external/internal/civisibility/native/ | |
| - name: Build and run linux-arm64 | |
| run: | | |
| docker buildx build --platform linux/arm64 --build-arg GOARCH=arm64 --build-arg FILE_NAME=linux-arm64-libtestoptimization -t libtestoptimization-builder:arm64 -f ./Dockerfile ../../.. --load | |
| docker run --rm -v ./output:/libtestoptimization libtestoptimization-builder:arm64 | |
| working-directory: external/internal/civisibility/native | |
| - name: Upload artifact | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: linux-arm64-artifact | |
| path: external/internal/civisibility/native/output/*.zip* | |
| linux_amd64_job: | |
| name: linux-amd64 | |
| runs-on: ubuntu-24.04 | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Checkout external repository | |
| uses: actions/checkout@v4 | |
| with: | |
| repository: "DataDog/dd-trace-go" | |
| ref: ${{ env.dd_trace_go_ref }} | |
| token: ${{ secrets.GITHUB_TOKEN }} | |
| path: external | |
| - name: Copy build files | |
| run: | | |
| # Create the directory if it doesn't exist | |
| mkdir -p external/internal/civisibility/native | |
| # Copy the build files | |
| cp -rf ./build/* external/internal/civisibility/native/ | |
| # Copy the native files | |
| cp -rf ./native/* external/internal/civisibility/native/ | |
| - name: Build and run linux-amd64 | |
| run: | | |
| docker build --platform linux/amd64 --build-arg GOARCH=amd64 --build-arg FILE_NAME=linux-x64-libtestoptimization -t libtestoptimization-builder:amd64 -f ./Dockerfile ../../.. | |
| docker run --rm -v ./output:/libtestoptimization libtestoptimization-builder:amd64 | |
| working-directory: external/internal/civisibility/native | |
| - name: Build and run android-arm64 | |
| run: | | |
| docker build --platform linux/amd64 --build-arg GOARCH=arm64 --build-arg FILE_NAME=android-arm64-libtestoptimization -t libtestoptimization-builder:androidarm64 -f ./Dockerfile-android ../../.. | |
| docker run --rm -v ./output:/libtestoptimization libtestoptimization-builder:androidarm64 | |
| working-directory: external/internal/civisibility/native | |
| - name: Upload artifact | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: linux-amd64-artifact | |
| path: external/internal/civisibility/native/output/*.zip* | |
| windows_job: | |
| name: windows | |
| runs-on: windows-latest | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Checkout external repository | |
| uses: actions/checkout@v4 | |
| with: | |
| repository: "DataDog/dd-trace-go" | |
| ref: ${{ env.dd_trace_go_ref }} | |
| token: ${{ secrets.GITHUB_TOKEN }} | |
| path: external | |
| - name: Copy build files | |
| shell: pwsh | |
| run: | | |
| New-Item -Path "external\internal\civisibility\native" -ItemType Directory -Force | |
| Copy-Item -Path ".\native\*" -Destination "external\internal\civisibility\native" -Recurse -Force | |
| Copy-Item -Path ".\build\*" -Destination "external\internal\civisibility\native" -Recurse -Force | |
| - name: Download MinGW toolchain | |
| shell: pwsh | |
| run: | | |
| $url = "https://github.com/brechtsanders/winlibs_mingw/releases/download/14.2.0posix-12.0.0-ucrt-r3/winlibs-x86_64-posix-seh-gcc-14.2.0-llvm-19.1.7-mingw-w64ucrt-12.0.0-r3.zip" | |
| $output = "$env:RUNNER_TEMP\mingw.zip" | |
| Invoke-WebRequest -Uri $url -OutFile $output | |
| - name: Extract MinGW toolchain | |
| shell: pwsh | |
| run: | | |
| $zipPath = "$env:RUNNER_TEMP\mingw.zip" | |
| $extractPath = "$env:RUNNER_TEMP\mingw" | |
| Expand-Archive -Path $zipPath -DestinationPath $extractPath -Force | |
| echo "MINGW_PATH=$env:RUNNER_TEMP\mingw" >> $env:GITHUB_ENV | |
| - name: Install UPX 5.0.0 | |
| shell: pwsh | |
| run: | | |
| $version = "5.0.0" | |
| $url = "https://github.com/upx/upx/releases/download/v$version/upx-$version-win64.zip" | |
| $zipPath = "$env:RUNNER_TEMP\upx.zip" | |
| $extractPath = "$env:RUNNER_TEMP\upx" | |
| Invoke-WebRequest -Uri $url -OutFile $zipPath -UseBasicParsing | |
| Expand-Archive -Path $zipPath -DestinationPath $extractPath -Force | |
| $upxExe = Join-Path $extractPath "upx-$version-win64\upx.exe" | |
| echo "UPX_PATH=$upxExe" >> $env:GITHUB_ENV | |
| - name: Build Windows libraries | |
| shell: pwsh | |
| run: | | |
| # --------------------------------------------------------------------------- | |
| # Environment variables and compile flags | |
| # --------------------------------------------------------------------------- | |
| $env:CC = "$env:MINGW_PATH\mingw64\bin\gcc.exe" | |
| $env:CGO_ENABLED = "1" | |
| $env:CGO_CFLAGS = "-O2 -fno-unwind-tables -fno-asynchronous-unwind-tables" # prevent new unwind tables | |
| $env:CGO_LDFLAGS = "-Wl,--no-seh" | |
| # --------------------------------------------------------------------------- | |
| # 1. Build the static library (.lib) | |
| # --------------------------------------------------------------------------- | |
| Write-Host "Building Windows static library" | |
| go build ` | |
| -tags civisibility_native ` | |
| -buildmode=c-archive ` | |
| -ldflags "-linkmode=external -extldflags=-Wl,--no-seh" ` | |
| -o ./output/windows-x64-libtestoptimization-static/testoptimization.lib ` | |
| exports.go main.go | |
| # --------------------------------------------------------------------------- | |
| # 2. Strip .pdata/.xdata and re-pack the .lib (fixes MSVC 14.44 linker) | |
| # --------------------------------------------------------------------------- | |
| $libDir = Resolve-Path "./output/windows-x64-libtestoptimization-static" | |
| $libFile = Join-Path $libDir "testoptimization.lib" | |
| $llvmBin = "$env:MINGW_PATH\mingw64\bin" # WinLibs ships llvm-ar / llvm-objcopy | |
| $AR = Join-Path $llvmBin "llvm-ar.exe" | |
| $OBJCOPY = Join-Path $llvmBin "llvm-objcopy.exe" | |
| Write-Host "Removing .pdata/.xdata from $libFile" | |
| Push-Location $libDir | |
| # 2-a) extract all object files | |
| & $AR x testoptimization.lib | Out-Null | |
| # 2-b) strip the problematic sections from each object | |
| Get-ChildItem -Filter *.o | ForEach-Object { | |
| Write-Host " • cleaning $($_.Name)" | |
| & $OBJCOPY --remove-section=.pdata --remove-section=.xdata $_.FullName | |
| } | |
| # 2-c) rebuild the static library | |
| Remove-Item testoptimization.lib | |
| & $AR rc testoptimization.lib *.o | Out-Null | |
| & $AR s testoptimization.lib | Out-Null # rebuild symbol index | |
| # 2-d) delete temporary .o files | |
| Remove-Item *.o | |
| Pop-Location | |
| # --------------------------------------------------------------------------- | |
| # 3. Build the shared library (DLL) – no special handling needed | |
| # --------------------------------------------------------------------------- | |
| Write-Host "Building windows shared library" | |
| go build -tags civisibility_native -buildmode=c-shared -ldflags="-s -w" -o ./output/windows-x64-libtestoptimization-dynamic/testoptimization.dll exports.go main.go | |
| # --------------------------------------------------------------------------- | |
| # 4. Compress the DLL with UPX | |
| # --------------------------------------------------------------------------- | |
| Write-Host "Compressing DLL with UPX" | |
| & "$env:UPX_PATH" --best --lzma ./output/windows-x64-libtestoptimization-dynamic/testoptimization.dll | |
| working-directory: external/internal/civisibility/native | |
| - name: Compress Windows libraries | |
| shell: pwsh | |
| run: | | |
| Write-Host "Compressing static library" | |
| Compress-Archive -Path ./output/windows-x64-libtestoptimization-static/*.* -DestinationPath ./output/windows-x64-libtestoptimization-static.zip -Force | |
| Get-FileHash -Path ./output/windows-x64-libtestoptimization-static.zip -Algorithm SHA256 | Out-File -FilePath ./output/windows-x64-libtestoptimization-static.zip.sha256sum | |
| Write-Host "Compressing dynamic library" | |
| Compress-Archive -Path ./output/windows-x64-libtestoptimization-dynamic/*.* -DestinationPath ./output/windows-x64-libtestoptimization-dynamic.zip -Force | |
| Get-FileHash -Path ./output/windows-x64-libtestoptimization-dynamic.zip -Algorithm SHA256 | Out-File -FilePath ./output/windows-x64-libtestoptimization-dynamic.zip.sha256sum | |
| Remove-Item -Recurse -Force ./output/windows-x64-libtestoptimization-static | |
| Remove-Item -Recurse -Force ./output/windows-x64-libtestoptimization-dynamic | |
| working-directory: external/internal/civisibility/native | |
| - name: Upload artifact | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: windows-artifact | |
| path: external/internal/civisibility/native/output/*.zip* | |
| collect_artifacts: | |
| name: Collect all artifacts | |
| needs: [mac_job, linux_arm64_job, linux_amd64_job, windows_job] | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: write | |
| actions: write | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Download artifacts from mac job | |
| uses: actions/download-artifact@v4 | |
| with: | |
| name: mac-artifact | |
| path: artifacts | |
| - name: Download artifacts from linux-arm64 job | |
| uses: actions/download-artifact@v4 | |
| with: | |
| name: linux-arm64-artifact | |
| path: artifacts | |
| - name: Download artifacts from linux-amd64 job | |
| uses: actions/download-artifact@v4 | |
| with: | |
| name: linux-amd64-artifact | |
| path: artifacts | |
| - name: Download artifacts from windows job | |
| uses: actions/download-artifact@v4 | |
| with: | |
| name: windows-artifact | |
| path: artifacts | |
| - name: Upload final artifacts | |
| id: artifact-upload-step | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: all-artifacts | |
| path: artifacts/*.zip* | |
| if-no-files-found: error | |
| - name: Trigger Python SDK tests | |
| uses: benc-uk/workflow-dispatch@v1 | |
| with: | |
| workflow: python-sdk-tests.yml | |
| ref: ${{ github.event.pull_request.head.ref || github.ref }} | |
| inputs: '{ "artifact_id": "${{ steps.artifact-upload-step.outputs.artifact-id }}" }' | |
| - name: Trigger Rust SDK tests | |
| uses: benc-uk/workflow-dispatch@v1 | |
| with: | |
| workflow: rust-sdk-tests.yml | |
| ref: ${{ github.event.pull_request.head.ref || github.ref }} | |
| inputs: '{ "artifact_id": "${{ steps.artifact-upload-step.outputs.artifact-id }}" }' | |
| - name: Wait for trigger Python SDK tests start | |
| uses: lewagon/wait-on-check-action@v1.3.4 | |
| with: | |
| ref: ${{ github.event.pull_request.head.ref || github.ref }} | |
| check-name: 'Download Build Artifacts for Python SDK Tests' | |
| repo-token: ${{ secrets.GITHUB_TOKEN }} | |
| wait-interval: 10 | |
| - name: Wait for trigger Rust SDK tests start | |
| uses: lewagon/wait-on-check-action@v1.3.4 | |
| with: | |
| ref: ${{ github.event.pull_request.head.ref || github.ref }} | |
| check-name: 'Download Build Artifacts for Rust SDK Tests' | |
| repo-token: ${{ secrets.GITHUB_TOKEN }} | |
| wait-interval: 10 | |
| release: | |
| name: Create Release and Upload Artifacts | |
| needs: collect_artifacts | |
| runs-on: ubuntu-latest | |
| if: startsWith(github.ref, 'refs/tags/') | |
| permissions: | |
| contents: write | |
| steps: | |
| - name: Download all artifacts | |
| uses: actions/download-artifact@v4 | |
| with: | |
| name: all-artifacts | |
| path: release_artifacts | |
| - name: Release | |
| uses: softprops/action-gh-release@v2 | |
| with: | |
| files: release_artifacts/*.zip* | |
| draft: false | |
| prerelease: false | |