Skip to content

Commit

Permalink
Merge pull request #521 from nosracd/feature/wheels
Browse files Browse the repository at this point in the history
Add PEP-517 Support
  • Loading branch information
ihilt committed Aug 5, 2024
2 parents 9a303f8 + c783f9e commit f18f8a6
Show file tree
Hide file tree
Showing 9 changed files with 189 additions and 134 deletions.
50 changes: 50 additions & 0 deletions .github/workflows/build_wheels.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
name: Build wheels

on: [push, pull_request]

jobs:
unix:
name: ${{ matrix.os }} | ${{ matrix.arch }} | ${{ matrix.python }}
runs-on: ${{ matrix.os }}
strategy:
matrix:
# macos-13 is an intel runner, macos-14 is apple silicon
os: [ubuntu-latest, macos-13, macos-14]
arch: [auto, aarch64]
python: [cp37-*, cp38-*, cp39-*, cp310-*, cp311-*, cp312-*,
pp37-*, pp38-*, pp39-*, pp310-*]
include:
- os: macos-13
macos_deployment_target: 13
- os: macos-14
macos_deployment_target: 14
exclude:
- os: macos-13
arch: aarch64
- os: macos-14
arch: aarch64
- os: macos-14
python: cp37-*
- os: macos-14
python: pp37-*

steps:
- uses: actions/checkout@v4

- name: Set up QEMU
if: runner.os == 'Linux'
uses: docker/setup-qemu-action@v3
with:
platforms: all

- name: Build wheels
uses: pypa/cibuildwheel@v2.19.2
env:
MACOSX_DEPLOYMENT_TARGET: ${{ matrix.macos_deployment_target }}
CIBW_ARCHS: ${{ matrix.arch }}
CIBW_BUILD: ${{ matrix.python }}

- uses: actions/upload-artifact@v4
with:
name: cibw-wheels-${{ matrix.os }}-${{ strategy.job-index }}
path: ./wheelhouse/*.whl
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,6 @@ docs/_build/
.idea/
.settings/
.project
.classpath
.classpath
.venv
.DS_Store
8 changes: 8 additions & 0 deletions docs/content/build-instructions.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,14 @@ release or the latest `master`, we recommend referring to the copy of this
document (`docs/content/build-instructions.md`) found in your source
distribution.

## Installing the Python module

To build the Python module from source and install it, run:

```
pip3 install -v .
```

## CMake Overview

These instructions assume that you will build in a directory named `build` as
Expand Down
4 changes: 2 additions & 2 deletions lcm-logger/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
add_executable(lcm-logger lcm_logger.c glib_util.c)
target_link_libraries(lcm-logger lcm GLib2::glib)
target_link_libraries(lcm-logger lcm-static GLib2::glib)

add_executable(lcm-logplayer lcm_logplayer.c)
target_link_libraries(lcm-logplayer lcm GLib2::glib)
target_link_libraries(lcm-logplayer lcm-static GLib2::glib)

install(TARGETS
lcm-logger
Expand Down
45 changes: 31 additions & 14 deletions lcm-python/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,13 +1,22 @@
# FindPython added in 3.12
cmake_minimum_required(VERSION 3.12)

execute_process(
COMMAND "${Python_EXECUTABLE}" -c "if True:
from sysconfig import get_path
from os.path import sep
print(get_path('platlib').replace(get_path('data') + sep, ''))"
OUTPUT_VARIABLE PYTHON_SITE
OUTPUT_STRIP_TRAILING_WHITESPACE)
option(LCM_PIP_BUILD "When true, adjusts install path to something appropriate for a Python wheel" OFF)

if (NOT LCM_PIP_BUILD)
execute_process(
COMMAND "${Python_EXECUTABLE}" -c "if True:
from sysconfig import get_path
from os.path import sep
print(get_path('platlib').replace(get_path('data') + sep, ''))"
OUTPUT_VARIABLE PYTHON_SITE
OUTPUT_STRIP_TRAILING_WHITESPACE)

set(PYTHON_INSTALL_DIR ${PYTHON_SITE}/lcm)
else()
set(PYTHON_INSTALL_DIR lcm)
endif()


set(lcm_python_sources
module.c
Expand All @@ -28,11 +37,19 @@ if (WIN32 AND NOT CYGWIN)
set_target_properties(lcm-python PROPERTIES SUFFIX .pyd)
endif ()

find_package (Python COMPONENTS Interpreter Development)
if (WIN32)
find_package(Python COMPONENTS Interpreter Development.Module)

target_include_directories(lcm-python PRIVATE
${Python_INCLUDE_DIRS}
)
target_include_directories(lcm-python PRIVATE
${Python_INCLUDE_DIRS}
)
else ()
find_package(Python3 COMPONENTS Interpreter Development.Module)

target_include_directories(lcm-python PRIVATE
${Python3_INCLUDE_DIRS}
)
endif ()

target_link_libraries(lcm-python PRIVATE
lcm-static
Expand All @@ -47,13 +64,13 @@ else()
endif()

install(TARGETS lcm-python
RUNTIME DESTINATION ${PYTHON_SITE}/lcm
LIBRARY DESTINATION ${PYTHON_SITE}/lcm
RUNTIME DESTINATION ${PYTHON_INSTALL_DIR}
LIBRARY DESTINATION ${PYTHON_INSTALL_DIR}
)

lcm_copy_file_target(lcm-python-init
${CMAKE_CURRENT_SOURCE_DIR}/lcm/__init__.py
${CMAKE_BINARY_DIR}/python/lcm/__init__.py
)

install(FILES lcm/__init__.py DESTINATION ${PYTHON_SITE}/lcm)
install(FILES lcm/__init__.py DESTINATION ${PYTHON_INSTALL_DIR})
36 changes: 36 additions & 0 deletions lcm-python/lcm/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import os
import sys
import subprocess

# Attempt to be backwards compatible
if sys.version_info >= (3, 6):
Expand Down Expand Up @@ -164,3 +165,38 @@ def tell (self):
@rtype: int
"""
return self.c_eventlog.ftell ()

LCM_BIN_DIR = os.path.join(os.path.dirname(__file__), '..', 'bin')

def run_script(name: str, args) -> int:
return subprocess.call([os.path.join(LCM_BIN_DIR, name), *args], close_fds=False)

def run_example():
raise SystemExit(run_script('lcm-example', sys.argv[1:]))

def run_gen():
raise SystemExit(run_script('lcm-gen', sys.argv[1:]))

def run_logfilter():
raise SystemExit(run_script('lcm-logfilter', sys.argv[1:]))

def run_logger():
raise SystemExit(run_script('lcm-logger', sys.argv[1:]))

def run_logplayer():
raise SystemExit(run_script('lcm-logplayer', sys.argv[1:]))

def run_logplayer_gui():
raise SystemExit(run_script('lcm-logplayer-gui', sys.argv[1:]))

def run_sink():
raise SystemExit(run_script('lcm-sink', sys.argv[1:]))

def run_source():
raise SystemExit(run_script('lcm-source', sys.argv[1:]))

def run_spy():
raise SystemExit(run_script('lcm-spy', sys.argv[1:]))

def run_tester():
raise SystemExit(run_script('lcm-tester', sys.argv[1:]))
110 changes: 0 additions & 110 deletions lcm-python/setup.py

This file was deleted.

14 changes: 7 additions & 7 deletions liblcm-test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@
add_executable(lcm-sink lcm-sink.c)
target_link_libraries(lcm-sink lcm)
target_link_libraries(lcm-sink lcm-static)

add_executable(lcm-source lcm-source.c)
target_link_libraries(lcm-source lcm)
target_link_libraries(lcm-source lcm-static)

add_executable(lcm-tester lcm-tester.c)
target_link_libraries(lcm-tester lcm GLib2::glib)
target_link_libraries(lcm-tester lcm-static GLib2::glib)
if(WIN32)
target_link_libraries(lcm-tester wsock32 ws2_32)
endif()

add_executable(lcm-example lcm-example.c)
target_link_libraries(lcm-example lcm)
target_link_libraries(lcm-example lcm-static)
if(WIN32)
target_link_libraries(lcm-example ws2_32)
endif()

add_executable(lcm-logfilter lcm-logfilter.c)
target_link_libraries(lcm-logfilter lcm GLib2::glib)
target_link_libraries(lcm-logfilter lcm-static GLib2::glib)

add_executable(lcm-buftest-receiver buftest-receiver.c)
target_link_libraries(lcm-buftest-receiver lcm GLib2::glib)
target_link_libraries(lcm-buftest-receiver lcm-static GLib2::glib)

add_executable(lcm-buftest-sender buftest-sender.c)
target_link_libraries(lcm-buftest-sender lcm GLib2::glib)
target_link_libraries(lcm-buftest-sender lcm-static GLib2::glib)

install(TARGETS
lcm-sink
Expand Down
Loading

0 comments on commit f18f8a6

Please sign in to comment.