Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Force-disable BMI2 instruction set when building snappy.lib #47

Merged
merged 2 commits into from
Aug 6, 2024
Merged
Changes from 1 commit
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
37 changes: 37 additions & 0 deletions .github/workflows/bcny-firebase.yml
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,25 @@ jobs:
-D CMAKE_MSVC_DEBUG_INFORMATION_FORMAT=Embedded `
-D FIREBASE_PYTHON_HOST_EXECUTABLE:FILEPATH=${{ steps.python.outputs.python-path }} `
-D FLATBUFFERS_FLATC_EXECUTABLE=${{ github.workspace }}/BinaryCache/flatbuffers/Release/flatc.exe

# The step below is necessary since Snappy detects if it should use BMI2 instructions on x64 based only on its ability to
# compile BMI2 code on the host machine, but we need to disable BMI2 instructions so that the resulting nuget package
# can be used on target machines without BMI2 support. Unfortunately Snappy is pulled indirectly from
# another dependency (firebase-ios-sdk) in a very involved dependency chain and there is no good way to
# set SNAPPY_HAVE_BMI2 without patching its code since compiler directives have less precendence than
# the result of the host machine's check_cxx_source_compiles (which ends up in the config.h file).
# So, the less messy solution seems to be to patch the config.h file after the configure step, which is what we do below.
- name: Change SNAPPY_HAVE_BMI2 in snappy config.h
# BMI2 instructions are only relevant in amd64
if: ${{ matrix.arch }} == 'amd64'
run: |
$snappy_config = "${{ github.workspace }}\BinaryCache\firebase\external\src\firestore-build\external\src\snappy-build\config.h"
if (-not (Select-String -Path $snappy_config -Pattern "#define SNAPPY_HAVE_BMI2 1")) {
Write-Error "String '#define SNAPPY_HAVE_BMI2 1' expected but not found in $snappy_config"
exit 1
}
(Get-Content $snappy_config) -replace '#define SNAPPY_HAVE_BMI2 1', '#define SNAPPY_HAVE_BMI2 0' | Set-Content $snappy_config

- name: Build firebase
run: cmake --build ${{ github.workspace }}/BinaryCache/firebase --config RelWithDebInfo
- name: Install firebase
Expand All @@ -137,6 +156,24 @@ jobs:
Copy-Item -Path $library.FullName -Destination $destination -Force
Write-Host "... copied ${destination}"
}

# We need this library to be used on CPUs without BMI2 support, so we check that snappy.lib was built correctly,
# and fail if it contains BMI2 instructions.
- name: Check for Snappy BMI2 instructions
# BMI2 instructions are only relevant in amd64
if: ${{ matrix.arch }} == 'amd64'
run: |
Write-Host "Checking for BMI2 instructions on Snappy.lib..."
$snappy_lib = "${{ github.workspace }}/BuildRoot/Library/firebase/usr/libs/windows/snappy.lib"
$output = dumpbin /DISASM "$snappy_lib" | Select-String -Pattern "bzhi"
mangini marked this conversation as resolved.
Show resolved Hide resolved
if ($output) {
Write-Host $output
Write-Error "ERROR: A BMI2 instruction ('bzhi') was not supposed to be found in $snappy_lib."
exit 1
} else {
Write-Output "Success! No BMI2 instructions were found in snappy.lib."
}

- uses: actions/upload-artifact@v3
with:
name: firebase-windows-${{ matrix.arch }}
Expand Down
Loading