Skip to content

Build a static TA-Lib C when none is installed; add opt-in TSAN build - #770

Closed
Tapanhaz wants to merge 7 commits into
TA-Lib:masterfrom
Tapanhaz:build/static-talib-fallback
Closed

Tapanhaz wants to merge 7 commits into
TA-Lib:masterfrom
Tapanhaz:build/static-talib-fallback

Conversation

@Tapanhaz

Copy link
Copy Markdown
Contributor

Changes

  1. Static TA-Lib C fallback (setup.py):
    • A system TA-Lib is used only if its reported version (TA_GetVersionString) is >= TALIB_C_VER.
    • Otherwise the release tarball is built with CMake as a static library and linked into talib._ta_lib.
  2. sdist ships .pyx only: cythonization now happens inside build_ext, and include talib/*.c is removed from MANIFEST.in.
  3. CI:
    • wheels, tests and test-dev no longer build TA-Lib C by hand.
    • Custom auditwheel/delocate repair commands are dropped.
    • test-dev.yml builds C dev through TALIB_C_URL.
  4. TSAN (opt-in):
    • TA_TSAN=1 builds the extension and a static TA-Lib C with ThreadSanitizer.
    • make test-tsan runs the threading tests.
    • tsan.yml runs the suite on free-threaded 3.14t and 3.15t using prebuilt TSAN images.

@mrjbq7

mrjbq7 commented Oct 14, 2026

Copy link
Copy Markdown
Member

What's the point of this PR?

@mrjbq7

mrjbq7 commented Oct 14, 2026

Copy link
Copy Markdown
Member

There's a bunch of issue with this, not least of which is I want to ship the C files so that cython is not required to install this module...

@Tapanhaz

Copy link
Copy Markdown
Contributor Author

Thanks for the feedback, I'll close this.

For the record, the point was: pip builds from source fails
unless TA-Lib C is already installed. This builds a pinned TA-Lib C statically
when no suitable system copy is available, so pip install works without a
manual TA-Lib C install.

On Cython: pip fetches it automatically through build-system.requires, so users
never install it by hand. I see the case you want to keep, installs without
Cython (--no-build-isolation, distro builds).

Happy to revisit a narrower version if there's interest.

@Tapanhaz Tapanhaz closed this Oct 14, 2026
@mrjbq7 mrjbq7 reopened this Oct 14, 2026
@mrjbq7

mrjbq7 commented Oct 14, 2026

Copy link
Copy Markdown
Member

Sorry, I'm not against your PR, I just didn't understand it.

so the main motivation is install from the source code should be able to build against TA-Lib static C library , like the wheels do?

@Tapanhaz

Copy link
Copy Markdown
Contributor Author

Yes. When installing from source, the build currently needs TA-Lib C installed first. With this
change it builds a pinned TA-Lib C as a static library and links it in when no
suitable system copy is found, so the result is self-contained, like the wheels.

Nothing changes if a suitable TA-Lib is already installed (version >= TALIB_C_VER)
or if TA_INCLUDE_PATH / TA_LIBRARY_PATH are set, so packagers aren't affected.

@mrjbq7

mrjbq7 commented Oct 16, 2026

Copy link
Copy Markdown
Member

I'm considering a version of this change. While I test it, are there platforms or architectures or versions of Python that we don't have support for that is motivating this change for you?

@Tapanhaz

Copy link
Copy Markdown
Contributor Author

Right now, a source install fails if there is no system TA-Lib C, or if the
installed version is older than the one required. I forked this to test
free-threaded Python, and my system has an slightly older TA-Lib C, so the build
failed for me.

With this change, a source install builds TA-Lib C statically when no suitable
system copy (version >= TALIB_C_VER) is found. If one is found, it is used as
before.

The wheels were already self-contained, so nothing changes for wheel users. I
also switched the wheel build to the same static link, so wheels and source
installs share one code path. That removes the separate C-build scripts and the
auditwheel/delocate repair steps, and the wheel then holds a single extension
module instead of a bundled shared library.

Honestly, my main motivation is testing with ThreadSanitizer, and this is what
I ended up with along the way.

@mrjbq7

mrjbq7 commented Oct 16, 2026

Copy link
Copy Markdown
Member

Hi @Tapanhaz thank you for that perspective. I do think building from source simplifies some things, so I have merged a variant of this in #772. I did not include TSAN, and probably we want ASAN, UBSAN too in a focused sanitizer-build PR.

@mrjbq7 mrjbq7 closed this Oct 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants