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

[CLIENT-2512] Label version properly when building sanitizer wheels and instrument C client with libasan as well #655

Merged
merged 17 commits into from
Dec 16, 2024
Merged
Show file tree
Hide file tree
Changes from 16 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
32 changes: 30 additions & 2 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,12 @@ jobs:
strategy:
matrix:
py-version: ["3.8", "3.9", "3.10", "3.11", "3.12"]
# Make sure we can build and run tests on an instrumented build that uses libasan
# We aren't necessarily checking for memory errors / leaks in this test
sanitizer: [false]
include:
- py-version: 3.8
sanitizer: true
fail-fast: false

steps:
Expand All @@ -64,15 +70,23 @@ jobs:
- name: Install build dependencies (pip packages)
run: python3 -m pip install -r requirements.txt

- if: ${{ matrix.sanitizer }}
run: echo SANITIZER=1 >> $GITHUB_ENV

- name: Build client
run: python3 -m build
env:
CFLAGS: '-Werror'

- run: echo WHEEL_GH_ARTIFACT_NAME=wheel-${{ matrix.py-version }} >> $GITHUB_ENV

- if: ${{ matrix.sanitizer }}
run: echo WHEEL_GH_ARTIFACT_NAME=${{ env.WHEEL_GH_ARTIFACT_NAME }}-sanitizer >> $GITHUB_ENV

- name: Send wheel to test jobs
uses: actions/upload-artifact@v3
with:
name: wheel-${{ matrix.py-version }}
name: ${{ env.WHEEL_GH_ARTIFACT_NAME }}
path: ./dist/*.whl

test-memray:
Expand Down Expand Up @@ -299,6 +313,10 @@ jobs:
"3.11",
"3.12"
]
sanitizer: [false]
include:
- py-version: 3.8
sanitizer: true
fail-fast: false

steps:
Expand All @@ -311,9 +329,14 @@ jobs:
python-version: ${{ matrix.py-version }}
architecture: 'x64'

- run: echo WHEEL_GH_ARTIFACT_NAME=wheel-${{ matrix.py-version }} >> $GITHUB_ENV

- if: ${{ matrix.sanitizer }}
run: echo WHEEL_GH_ARTIFACT_NAME=${{ env.WHEEL_GH_ARTIFACT_NAME }}-sanitizer >> $GITHUB_ENV

- uses: actions/download-artifact@v3
with:
name: wheel-${{ matrix.py-version }}
name: ${{ env.WHEEL_GH_ARTIFACT_NAME }}

- name: Install client
run: pip install *.whl
Expand Down Expand Up @@ -343,6 +366,11 @@ jobs:
with:
container-name: aerospike

- if: ${{ matrix.sanitizer }}
run: |
echo ASAN_OPTIONS='halt_on_error=0' >> $GITHUB_ENV
echo LD_PRELOAD=$(gcc --print-file-name=libasan.so) >> $GITHUB_ENV

- name: Run tests
run: python -m pytest ./new_tests -vv
working-directory: test
Expand Down
2 changes: 2 additions & 0 deletions BUILD.md
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,8 @@ Then once you install the build with sanitizer, you may run a Python script usin
LD_PRELOAD=/lib/x86_64-linux-gnu/libasan.so.6 python3 -c "import aerospike"
```

This is only supported for building with GCC.

### Troubleshooting macOS

In some versions of macOS, Python 2.7 is installed as ``python`` with
Expand Down
2 changes: 2 additions & 0 deletions custom-versionit-format.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,5 +58,7 @@ def my_format(
version_str = append_to_local(version_str, "unoptimized")
if os.getenv("INCLUDE_DSYM"):
version_str = append_to_local(version_str, "dsym")
if os.getenv("SANITIZER"):
version_str = append_to_local(version_str, "sanitizer")

return version_str
17 changes: 12 additions & 5 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,14 +87,16 @@

SANITIZER=os.getenv('SANITIZER')
if SANITIZER:
sanitizer_flags = [
sanitizer_c_and_ld_flags = [
'-fsanitize=address',
'-fsanitize-recover=all'
'-fno-omit-frame-pointer'
]
extra_compile_args.extend(sanitizer_flags)
sanitizer_cflags = sanitizer_c_and_ld_flags.copy()
sanitizer_cflags.append('-fsanitize-recover=all')
extra_compile_args.extend(sanitizer_cflags)

extra_link_args.append("-static-libasan")
extra_link_args.extend(sanitizer_flags)
sanitizer_ldflags = sanitizer_c_and_ld_flags.copy()
extra_link_args.extend(sanitizer_ldflags)

library_dirs = ['/usr/local/opt/openssl/lib', '/usr/local/lib']
libraries = [
Expand Down Expand Up @@ -232,6 +234,11 @@ def clean():
]
if UNOPTIMIZED:
cmd.append('O=0')
if SANITIZER:
ext_cflags = " ".join(sanitizer_cflags)
cmd.append(f"EXT_CFLAGS={ext_cflags}")
ldflags = " ".join(sanitizer_ldflags)
cmd.append(f"LDFLAGS={ldflags}")

def compile():
print(cmd, library_dirs, libraries)
Expand Down
Loading