Skip to content

Commit

Permalink
Add Python Support (#5)
Browse files Browse the repository at this point in the history
* Python Support
- Use METH_FASTCALL for Python functions
- Use Python Limited ABI
- Add Python APIs
- Added finder for Python3 library

* Remove old unused redundant code.
- Fix PyLimitedAPI < 3.7 for METH_FASTCALL.
- Fixed Parsing Keyword Arguments
- Bumped Minimum python version and limited API version to 3.8+

* Added ability to set image format.
- Fix Simba compatibility with BGRA
- Add Pre-Multiplied Alpha

* Update CI to compile Python
* Disable linux-armhf (32-bit ARM)
  • Loading branch information
Brandon-T authored Dec 17, 2023
1 parent 08e0913 commit 27cb1a4
Show file tree
Hide file tree
Showing 43 changed files with 10,422 additions and 1,508 deletions.
72 changes: 16 additions & 56 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@ name: Build

on:
push:
branches: [ master ]
branches:
- master
- 'feature/**'
pull_request:
branches: [ master ]
branches:
- master

jobs:
Build:
Expand All @@ -22,14 +25,6 @@ jobs:
output: libRemoteInput.so.1.0.0
release: libRemoteInput-aarch64.so

#Linux-armhf
- os: ubuntu-latest
name: Linux-armhf
other_linker_flags: ''
arch: armhf
output: libRemoteInput.so.1.0.0
release: libRemoteInput-armhf.so

#Linux-64
- os: ubuntu-latest
name: Linux-64
Expand Down Expand Up @@ -66,6 +61,11 @@ jobs:
- uses: actions/checkout@v1
with:
submodules: true

- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.x'

#Linux-aarch64
- name: Update Sources - Linux-aarch64
Expand Down Expand Up @@ -108,52 +108,12 @@ jobs:
run: |
cmake --build '${{ github.workspace }}/cmake-build-release' --target all -- -j 4
#Linux-armhf
- name: Update Sources - Linux-armhf
if: matrix.config.name == 'Linux-armhf'
run: |
#source_version=$(cat /etc/apt/sources.list | grep "main restricted" | head -1 | sed -e 's/.*com\/ //' -e 's/ main.*//')
#echo "Found: ${ source_version }"
sudo sed -Ei 's/^deb /deb \[arch=amd64\,i386\] /' /etc/apt/sources.list
echo "deb [arch=armhf] http://ports.ubuntu.com/ jammy main restricted" | sudo tee -a /etc/apt/sources.list
echo "deb [arch=armhf] http://ports.ubuntu.com/ jammy-updates main restricted" | sudo tee -a /etc/apt/sources.list
echo "deb [arch=armhf] http://ports.ubuntu.com/ jammy universe" | sudo tee -a /etc/apt/sources.list
echo "deb [arch=armhf] http://ports.ubuntu.com/ jammy-updates universe" | sudo tee -a /etc/apt/sources.list
echo "deb [arch=armhf] http://ports.ubuntu.com/ jammy multiverse" | sudo tee -a /etc/apt/sources.list
echo "deb [arch=armhf] http://ports.ubuntu.com/ jammy-updates multiverse" | sudo tee -a /etc/apt/sources.list
echo "deb [arch=armhf] http://ports.ubuntu.com/ jammy-backports main restricted universe multiverse" | sudo tee -a /etc/apt/sources.list
sudo dpkg --add-architecture armhf
sudo apt-get update
- name: Dependencies - Linux-armhf
if: matrix.config.name == 'Linux-armhf'
run: |
sudo apt-get install gcc-arm-linux-gnueabihf g++-arm-linux-gnueabihf
sudo apt-get install libprocps-dev:armhf mesa-common-dev:armhf libglu1-mesa:armhf libglu1-mesa-dev:armhf libgl1-mesa-glx:armhf libgl1-mesa-dev:armhf libglfw3-dev:armhf cmake
sudo apt-get install openjdk-11-jdk
sudo apt-get install libpython3-dev:armhf
- name: CMake Generate Build Files - Linux-armhf
if: matrix.config.name == 'Linux-armhf'
env:
JAVA_HOME: '/usr/lib/jvm/java-11-openjdk-amd64'
run: |
cmake -S '${{ github.workspace }}' -B '${{ github.workspace }}/cmake-build-release' -DCMAKE_SYSTEM_NAME=Linux -DCMAKE_SYSTEM_PROCESSOR=armhf -DCMAKE_C_COMPILER=/usr/bin/arm-linux-gnueabihf-gcc -DCMAKE_CXX_COMPILER=/usr/bin/arm-linux-gnueabihf-g++ -DCMAKE_BUILD_TYPE=Release -DOTHER_LINKER_FLAGS:STRING=${{ matrix.config.other_linker_flags }} -G "CodeBlocks - Unix Makefiles"
- name: Build - Linux-armhf
if: matrix.config.name == 'Linux-armhf'
env:
JAVA_HOME: '/usr/lib/jvm/java-11-openjdk-amd64'
run: |
cmake --build '${{ github.workspace }}/cmake-build-release' --target all -- -j 4
#Linux-64
- name: Dependencies - Linux-64
if: matrix.config.name == 'Linux-64'
run: |
sudo apt-get update
sudo apt-get install libprocps-dev mesa-common-dev libglu1-mesa libglu1-mesa-dev libgl1-mesa-glx libgl1-mesa-dev clang cmake g++
sudo apt-get install libprocps-dev mesa-common-dev libglu1-mesa libglu1-mesa-dev libgl1-mesa-glx libgl1-mesa-dev libpython3-dev clang cmake g++
- name: CMake Generate Build Files - Linux-64
if: matrix.config.name == 'Linux-64'
Expand Down Expand Up @@ -182,7 +142,7 @@ jobs:
uses: msys2/setup-msys2@v2
with:
msystem: MINGW32
install: mingw-w64-i686-gcc mingw-w64-i686-cmake make
install: mingw-w64-i686-gcc mingw-w64-i686-clang mingw-w64-i686-python mingw-w64-i686-cmake make
update: false

- name: CMake Generate Build Files - Windows-32
Expand All @@ -207,7 +167,7 @@ jobs:
uses: msys2/setup-msys2@v2
with:
msystem: MINGW64
install: mingw-w64-x86_64-gcc mingw-w64-x86_64-cmake make
install: mingw-w64-x86_64-gcc mingw-w64-x86_64-clang mingw-w64-x86_64-python mingw-w64-x86_64-cmake make
update: false

- name: CMake Generate Build Files - Windows-64
Expand Down Expand Up @@ -253,9 +213,9 @@ jobs:
uses: Brandon-T/wait-for-check-action@v1
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
check_names: '["Linux-aarch64", "Linux-armhf", "Linux-64", "MacOS-64", "Windows-32", "Windows-64"]'
statuses: '["completed", "completed", "completed", "completed", "completed", "completed"]'
conclusions: '["success", "success", "success", "success", "success", "success"]'
check_names: '["Linux-aarch64", "Linux-64", "MacOS-64", "Windows-32", "Windows-64"]'
statuses: '["completed", "completed", "completed", "completed", "completed"]'
conclusions: '["success", "success", "success", "success", "success"]'
timeout: 600
poll_interval: 10

Expand Down
26 changes: 18 additions & 8 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ IF(NOT CMAKE_BUILD_TYPE)
SET(CMAKE_BUILD_TYPE Release)
ENDIF()

set(PYTHON_BINDINGS OFF)
set(PYTHON_BINDINGS ON)


# ----------------------------- PACKAGES -----------------------------
Expand All @@ -20,13 +20,13 @@ find_package(Java 1.8 REQUIRED)
find_package(JNI 1.8 REQUIRED)

IF(PYTHON_BINDINGS)
find_package(Python 3.10 EXACT REQUIRED COMPONENTS Interpreter Development)
find_package(Python 3.8 REQUIRED COMPONENTS Interpreter Development)
MESSAGE(STATUS, "${Python_LIBRARIES}")
MESSAGE(STATUS, "${Python_LIBRARY_DIRS}")
MESSAGE(STATUS, "${PYTHON_DYNAMIC_LINKER_FLAGS}")
ENDIF()

set(Py_LIMITED_API 0x03070000)
set(Py_LIMITED_API 0x03080000)


# ----------------------- INCLUDE_DIRECTORIES -----------------------
Expand Down Expand Up @@ -257,17 +257,27 @@ ENDIF()
IF(PYTHON_BINDINGS)
set(SRC_LIST
${SRC_LIST}
RemoteInput/Plugin/PythonPlugin.cxx
RemoteInput/Plugin/PythonPlugin.hxx
RemoteInput/Plugin/PythonTraits.hxx)
RemoteInput/Plugin/Python/PythonCommon.cxx
RemoteInput/Plugin/Python/PythonCommon.hxx
RemoteInput/Plugin/Python/PythonPlugin.cxx
RemoteInput/Plugin/Python/PythonPlugin.hxx
RemoteInput/Plugin/Python/PythonEIOS.cxx
RemoteInput/Plugin/Python/PythonEIOS.hxx
RemoteInput/Plugin/Python/PythonJavaObject.cxx
RemoteInput/Plugin/Python/PythonJavaObject.hxx
RemoteInput/Plugin/Python/PythonJavaArray.cxx
RemoteInput/Plugin/Python/PythonJavaArray.hxx
RemoteInput/Plugin/Python/PythonCommon_Templates.hxx
RemoteInput/Plugin/Python/Python.cxx
RemoteInput/Plugin/Python/Python.hxx)
ENDIF()

IF(PYTHON_BINDINGS AND NOT (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC"))
# set(EXTRA_LIBRARIES
# ${EXTRA_LIBRARIES}
# ${Python_LIBRARIES})
set(PYTHON_DYNAMIC_LINKER_FLAGS
-undefined dynamic_lookup)
# set(PYTHON_DYNAMIC_LINKER_FLAGS
# -undefined dynamic_lookup)
ENDIF()

# ---------------------------- COMPILE ----------------------------
Expand Down
19 changes: 18 additions & 1 deletion RemoteInput/EIOS.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,23 @@ void STD_CALL EIOS_GetTargetDimensions(EIOS* eios, std::int32_t* width, std::int
}
}

ImageFormat STD_CALL EIOS_GetImageFormat(EIOS* eios) noexcept
{
if (eios)
{
return eios->control_center->get_image_format();
}
return ImageFormat::BGRA;
}

void STD_CALL EIOS_SetImageFormat(EIOS* eios, ImageFormat format) noexcept
{
if (eios)
{
eios->control_center->set_image_format(format);
}
}

std::uint8_t* STD_CALL EIOS_GetImageBuffer(EIOS* eios) noexcept
{
if (eios)
Expand Down Expand Up @@ -324,7 +341,7 @@ EIOS* STD_CALL EIOS_PairClient(std::int32_t pid) noexcept
}
catch(std::exception& e)
{
printf("%s\n", e.what());
fprintf(stderr, "%s\n", e.what());
}
return nullptr;
}
Expand Down
2 changes: 2 additions & 0 deletions RemoteInput/EIOS.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ extern "C" {
EXPORT EIOS* STD_CALL EIOS_RequestTarget(const char* initargs) noexcept;
EXPORT void STD_CALL EIOS_ReleaseTarget(EIOS* eios) noexcept;
EXPORT void STD_CALL EIOS_GetTargetDimensions(EIOS* eios, std::int32_t* width, std::int32_t* height) noexcept;
EXPORT ImageFormat STD_CALL EIOS_GetImageFormat(EIOS* eios) noexcept;
EXPORT void STD_CALL EIOS_SetImageFormat(EIOS* eios, ImageFormat format) noexcept;
EXPORT std::uint8_t* STD_CALL EIOS_GetImageBuffer(EIOS* eios) noexcept;
EXPORT std::uint8_t* STD_CALL EIOS_GetDebugImageBuffer(EIOS* eios) noexcept;
EXPORT void STD_CALL EIOS_SetGraphicsDebugging(EIOS* eios, bool enabled) noexcept;
Expand Down
5 changes: 0 additions & 5 deletions RemoteInput/EIOSTypes.cxx

This file was deleted.

10 changes: 10 additions & 0 deletions RemoteInput/EIOSTypes.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,15 @@

#include <cstdint>

enum class ImageFormat: std::uint32_t
{
BGR_BGRA, // Compatibility for Simba's Black pixels representing Transparency. Simba should really fix this.
BGRA,
RGBA,
ARGB,
ABGR
};

enum class EIOSCommand: std::uint32_t
{
COMMAND_NONE,
Expand Down Expand Up @@ -75,6 +84,7 @@ typedef struct EIOSData
std::int32_t height;
bool debug_graphics;
bool ui_scaling;
ImageFormat image_format;
EIOSCommand command;
std::uint8_t args[100000 * 8];
} EIOSData;
Expand Down
1 change: 1 addition & 0 deletions RemoteInput/Echo/MemoryMap.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#endif

#include <istream>
#include <Stream.hxx>

template<typename char_type>
class MemoryMap
Expand Down
12 changes: 0 additions & 12 deletions RemoteInput/Echo/SharedEvent.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -1167,12 +1167,6 @@ void atomic_signal_sleep(int* count)
do {
#if defined(_WIN32) || defined(_WIN64)
SwitchToThread();
#elif defined(_POSIX_THREADS)
#if defined(__APPLE__)
pthread_yield_np();
#else
pthread_yield();
#endif
#else
sched_yield();
#endif
Expand All @@ -1183,12 +1177,6 @@ void atomic_signal_sleep(int* count)
{
#if defined(_WIN32) || defined(_WIN64)
SwitchToThread();
#elif defined(_POSIX_THREADS)
#if defined(__APPLE__)
pthread_yield_np();
#else
pthread_yield();
#endif
#else
sched_yield();
#endif
Expand Down
5 changes: 3 additions & 2 deletions RemoteInput/Platform/DebugConsole.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ DebugConsole::DebugConsole() noexcept : input(nullptr), error(nullptr), output(n
{
#if defined(_WIN32) || defined(_WIN64)
allocated_console = AllocConsole();
#endif

#if defined(__STDC_LIB_EXT1__) && __STDC_WANT_LIB_EXT1__ == 1
freopen_s(&input, "CONIN$", "r", stdin);
freopen_s(&error, "CONOUT$", "w", stderr);
Expand All @@ -16,6 +14,9 @@ DebugConsole::DebugConsole() noexcept : input(nullptr), error(nullptr), output(n
error = std::freopen("CONOUT$", "w", stderr);
output = std::freopen("CONOUT$", "w", stdout);
#endif
#else

#endif
}

DebugConsole::DebugConsole(DebugConsole&& other) : input(other.input), error(other.error), output(other.output), allocated_console(other.allocated_console)
Expand Down
Loading

0 comments on commit 27cb1a4

Please sign in to comment.