Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
9a79f51
Try limited api 3.10 on windows, this produces correct dependencies o…
aymanhab Sep 3, 2026
38c5fe0
Use stable api on linux
aymanhab Sep 14, 2026
fbe78cd
Both apple and linux use .abi3.so
aymanhab Sep 15, 2026
7a2885d
windows doesnt recognize abi3.pyd so restoring the extension and upda…
aymanhab Sep 15, 2026
f6fd7a4
Add steps to the windows workflow to build and upload wheel similar t…
aymanhab Sep 15, 2026
df5e512
Update CMake command in CI workflow
aymanhab Sep 15, 2026
aea9c53
Update wheel path capture for Windows environment
aymanhab Sep 16, 2026
bffca3a
Don't link against libpython3 on linux, provided by default in runtime
aymanhab Sep 16, 2026
a2da8d7
Fix link line so libpython is not linked on linux
aymanhab Sep 16, 2026
6e83d6f
Fix link line on windows for python wrapping
aymanhab Sep 16, 2026
d48981a
No need for matrix since we build one wheel tageting abi 3.10 now
aymanhab Sep 18, 2026
df1eada
No need for matrix since we build one wheel tageting abi 3.10 now
aymanhab Sep 18, 2026
e93e888
Merge branch 'limited_python_310' of https://github.com/opensim-org/o…
aymanhab Sep 18, 2026
333a755
Move limited_api definition from swig interface file to CMake and key…
aymanhab Sep 18, 2026
aac24ac
Pull API version to cmake variable to make easy to change
aymanhab Sep 22, 2026
e64b6d9
Remove extra brace
aymanhab Sep 22, 2026
2704bad
Rename CMake variables for OPENSIM namespace, use CMake's Development…
aymanhab Sep 24, 2026
bd1deac
build non ABI wheel on osx, windows work already
Sep 29, 2026
1306bc5
Move OPENSIM_USE_PYTHON_SABI to top level CMakeLists close to its fir…
aymanhab Sep 29, 2026
0bdef7b
Restore extension on Mac
Sep 29, 2026
9d956db
setup not using abi and configure non sabi python build to test on al…
aymanhab Sep 30, 2026
e088bba
Fix typo
aymanhab Sep 30, 2026
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
6 changes: 3 additions & 3 deletions .github/workflows/build_all_wheels.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:

strategy:
matrix:
python-version: ['3.11', '3.12', '3.13']
python-version: ['3.11']

outputs:
version: ${{ steps.configure.outputs.version }}
Expand Down Expand Up @@ -91,7 +91,7 @@ jobs:
runs-on: macos-15
strategy:
matrix:
python-version: ['3.11', '3.12', '3.13']
python-version: ['3.11']

outputs:
version: ${{ steps.configure.outputs.version }}
Expand Down Expand Up @@ -173,7 +173,7 @@ jobs:

strategy:
matrix:
python: ["cp311", "cp312", "cp313"]
python: ["cp311"]

steps:
- uses: actions/checkout@v4
Expand Down
24 changes: 21 additions & 3 deletions .github/workflows/continuous_integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ jobs:
id: configure
run: |
cmake -G "Visual Studio 17 2022" . --preset ci-msvc-windows-release -LAH `
-DPython3_ROOT_DIR=$env:pythonLocation
-DPython3_ROOT_DIR=$env:pythonLocation -DOPENSIM_USE_PYTHON_SABI=OFF

$env:match = cmake -N -L build/ci-msvc-windows-release | Select-String -Pattern OPENSIM_QUALIFIED_VERSION
$version = $env:match.split('=')[1]
Expand All @@ -100,6 +100,24 @@ jobs:
Copy-Item -Path "${{ steps.configure.outputs.CMAKE_INSTALL_PREFIX }}" -Destination "opensim-core-${{ steps.configure.outputs.version }}" -Recurse
7z a "opensim-core-${{ steps.configure.outputs.version }}.zip" "opensim-core-${{ steps.configure.outputs.version }}"

- name: Build wheel
run: |
cd ${{ steps.configure.outputs.CMAKE_INSTALL_PREFIX }}/sdk/Python
python3 setup.py bdist_wheel

- name: Capture wheel path
id: wheel
run: |
cd ${{ steps.configure.outputs.CMAKE_INSTALL_PREFIX }}/sdk/Python/dist
$wheel = (Get-ChildItem -Filter "opensim*.whl" -File | Select-Object -First 1).Name
"path=$wheel" >> $env:GITHUB_OUTPUT

- name: Upload Windows wheel
uses: actions/upload-artifact@v4
with:
name: ${{ steps.wheel.outputs.path }}
path: ${{ steps.configure.outputs.CMAKE_INSTALL_PREFIX }}/sdk/Python/dist/${{ steps.wheel.outputs.path }}

- name: Upload opensim-core
uses: actions/upload-artifact@v4
with:
Expand Down Expand Up @@ -162,7 +180,7 @@ jobs:
id: configure
run: |
cmake -S $GITHUB_WORKSPACE --preset ci-make-macos-release -LAH \
-DSWIG_EXECUTABLE=$HOME/swig/bin/swig
-DSWIG_EXECUTABLE=$HOME/swig/bin/swig -DOPENSIM_USE_PYTHON_SABI=OFF

VERSION=`cmake -N -L $GITHUB_WORKSPACE/build/ci-make-macos-release | grep OPENSIM_QUALIFIED_VERSION | cut -d "=" -f2`
echo "version=$VERSION" >> $GITHUB_OUTPUT
Expand Down Expand Up @@ -281,7 +299,7 @@ jobs:
- name: Configure opensim-core
id: configure
run: |
cmake -S $GITHUB_WORKSPACE --preset ci-make-linux-release -LAH
cmake -S $GITHUB_WORKSPACE --preset ci-make-linux-release -DPython3_ROOT_DIR=/opt/python/cp311-cp311 -DOPENSIM_USE_PYTHON_SABI=OFF -LAH

VERSION=`cmake -N -L $GITHUB_WORKSPACE/build/ci-make-linux-release | grep OPENSIM_QUALIFIED_VERSION | cut -d "=" -f2`
echo "version=$VERSION" >> $GITHUB_OUTPUT
Expand Down
2 changes: 1 addition & 1 deletion Bindings/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
if(BUILD_PYTHON_WRAPPING OR BUILD_JAVA_WRAPPING)
find_package(SWIG 4.1.0 REQUIRED)
find_package(SWIG 4.4.1 REQUIRED)
endif()

# Flags are both Python and Java bindings will use.
Expand Down
31 changes: 23 additions & 8 deletions Bindings/Python/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ endif()
# We set these COMPILE_OPTIONS in the root CMakeLists.txt.
set_directory_properties(PROPERTIES COMPILE_OPTIONS "")

set(OPENSIM_PYTHON_LIMITED_API_HEX 0x030A0000)

# Helper macros.
# ==============
Expand Down Expand Up @@ -69,7 +70,11 @@ macro(OpenSimAddPythonModule)
set(_output_header_file "${_output_file_prefix}.h")
set(_interface_file
"${CMAKE_CURRENT_SOURCE_DIR}/swig/python_${OSIMSWIGPY_MODULE}.i")

if (OPENSIM_USE_PYTHON_SABI)
set_property(SOURCE ${_output_cxx_file} PROPERTY
COMPILE_DEFINITIONS "Py_LIMITED_API=${OPENSIM_PYTHON_LIMITED_API_HEX}"
)
endif()
# We run swig once to get dependencies and then again to actually generate
# the wrappers. This variable holds the parts of the swig command that
# are shared between both invocations.
Expand Down Expand Up @@ -132,12 +137,14 @@ macro(OpenSimAddPythonModule)
/wd4996 # Disable warning 4996: deprecated functions.
/wd4114 # Disable warning 4114: "const const T"
>
)
)
target_compile_definitions(${_libname} PRIVATE
# SWIG_PYTHON was added to account for generated cxx files
# failing to compile due to operators defined in simbody (removed
# by this symbol) -Ayman 3/25
SWIG_PYTHON
# Pass Limited_API version to the compiler if needed
$<$<BOOL:${OPENSIM_USE_PYTHON_SABI}>:-DPy_LIMITED_API=${OPENSIM_PYTHON_LIMITED_API_HEX}>
)

target_include_directories(${_libname} PRIVATE
Expand All @@ -161,11 +168,15 @@ macro(OpenSimAddPythonModule)
if("${PYTHON_LDSHARED}" MATCHES "dynamic_lookup")
set_target_properties(${_libname} PROPERTIES LINK_FLAGS
"-undefined dynamic_lookup")
else()
target_link_libraries(${_libname} ${Python3_LIBRARIES})
elseif(WIN32)
if (OPENSIM_USE_PYTHON_SABI)
target_link_libraries(${_libname} PRIVATE Python3::SABIModule)
else()
target_link_libraries(${_libname} PRIVATE Python3::Module)
endif()
endif()

target_link_libraries(${_libname} osimTools osimExampleComponents osimMoco)
target_link_libraries(${_libname} PUBLIC osimTools osimExampleComponents osimMoco)

# Set target properties for various platforms.
# --------------------------------------------
Expand All @@ -177,9 +188,13 @@ macro(OpenSimAddPythonModule)
)
if(WIN32)
set_target_properties(${_libname} PROPERTIES SUFFIX ".pyd")
elseif(APPLE)
# Defaults to .dylib; change to .so.
set_target_properties(${_libname} PROPERTIES SUFFIX ".so")
else()
# Defaults to .dylib; change to .so on MacOS, also on both mac, linux add abi3 for SABI
if (OPENSIM_USE_PYTHON_SABI)
set_target_properties(${_libname} PROPERTIES SUFFIX ".abi3.so")
else()
set_target_properties(${_libname} PROPERTIES SUFFIX ".so")
endif()
endif()

# RPATH: We always set a relative RPATH but only use an absolute RPATH if
Expand Down
3 changes: 3 additions & 0 deletions Bindings/Python/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ def has_ext_modules(foo):

setup(name='opensim',
version=__version__,
# The build number is used to differentiate between different builds of the same
# version. Typically on testpypi. py_limited_api is used to specify the Python version
# compatibility for the wheel. If upgrading the Python 3.11, change this to cp311 for example.
options={"bdist_wheel": {"build_number": "1"}},
description='OpenSim Simulation Framework',
long_description=long_description,
Expand Down
18 changes: 15 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -433,12 +433,24 @@ if(${BUILD_JAVA_WRAPPING})
endif()

if(${BUILD_PYTHON_WRAPPING})
set(required_python_version 3)
set(Python3_ROOT_DIR "" CACHE PATH "Top level directory containing Python3. For conda environments, this can also be set to the top level directory for a specific environment.")
find_package(Python3 3.6 REQUIRED COMPONENTS Interpreter Development.Module NumPy)
# Default OPENSIM_USE_PYTHON_SABI is on and version 3.10 If you want to use the stable ABI,
# you must use Python 3.8 or higher. If actual ABI version needs to be changed then
# modify the value of the Py_LIMITED_API definition in this file. If building wheels,
# you must modify the value of py_limited_api in setup.py as well.
option(OPENSIM_USE_PYTHON_SABI
"Use the stable ABI for Python bindings" ON)

set(Python3_ROOT_DIR "" CACHE PATH
"Top level directory containing Python3. For conda environments, this can also be set to the top level directory for a specific environment.")
if(${OPENSIM_USE_PYTHON_SABI})
find_package(Python3 3.10 REQUIRED COMPONENTS Interpreter Development.SABIModule NumPy)
else()
find_package(Python3 3.10 REQUIRED COMPONENTS Interpreter Development.Module NumPy)
endif()
message("Python3_FOUND:${Python3_FOUND}")
message("Python3_VERSION:${Python3_VERSION}")
message("Python3_Development_FOUND:${Python3_Development_FOUND}")
message("Python_Development.SABIModule_FOUND:${Python3_Development_SABIModule_FOUND}")
message("Python3_LIBRARIES:${Python3_LIBRARIES}")
message("Python3_Numpy_Include:${Python3_NumPy_INCLUDE_DIRS}")
message("Python3_Numpy_VERSION:${Python3_NumPy_VERSION}")
Expand Down
Loading