Skip to content

Commit

Permalink
Adjust for powsybl jl building.
Browse files Browse the repository at this point in the history
Signed-off-by: Bertrand Rix <[email protected]>

Update on java side.

Signed-off-by: Bertrand Rix <[email protected]>

Zip binaries and upload artifact.

Signed-off-by: Bertrand Rix <[email protected]>

Adjust.

Signed-off-by: Bertrand Rix <[email protected]>

Adjust.

Signed-off-by: Bertrand Rix <[email protected]>

Try creating dist.

Signed-off-by: Bertrand Rix <[email protected]>

Replace if exists.

Signed-off-by: Bertrand Rix <[email protected]>

Release workflow.

Signed-off-by: Bertrand Rix <[email protected]>

Package headers.

Signed-off-by: Bertrand Rix <[email protected]>

Clean zip.

Signed-off-by: Bertrand Rix <[email protected]>

Try adding cxx11 compile definition.

Signed-off-by: Bertrand Rix <[email protected]>

Try cpp 17.

Signed-off-by: Bertrand Rix <[email protected]>

Try manylinux 2 28.

Signed-off-by: Bertrand Rix <[email protected]>

Back to manylinux 2014.

Signed-off-by: Bertrand Rix <[email protected]>

Try mingw.

Signed-off-by: Bertrand Rix <[email protected]>

print gcc.

Signed-off-by: Bertrand Rix <[email protected]>

print gcc.

Signed-off-by: Bertrand Rix <[email protected]>

Print cmake args

Signed-off-by: Bertrand Rix <[email protected]>

Revert

Signed-off-by: Bertrand Rix <[email protected]>

Add flag to build only powsybl cpp.

Signed-off-by: Bertrand Rix <[email protected]>

Update CI release.

Signed-off-by: Bertrand Rix <[email protected]>

Update CI Release.

Signed-off-by: Bertrand Rix <[email protected]>

Put in binaries only what is needed.

Signed-off-by: Bertrand Rix <[email protected]>

Clean.

Signed-off-by: Bertrand Rix <[email protected]>

Try update of release CI.

Signed-off-by: Bertrand Rix <[email protected]>
  • Loading branch information
obrix committed Aug 1, 2024
1 parent 69b2ad6 commit 4718859
Show file tree
Hide file tree
Showing 4 changed files with 222 additions and 40 deletions.
135 changes: 135 additions & 0 deletions .github/workflows/release-ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
name: Release

on:
release:
types:
- created

jobs:
manylinux_build:
name: Build linux ${{ matrix.python.name }} wheel
runs-on: ubuntu-latest
container: quay.io/pypa/manylinux2014_x86_64:2024-07-01-8dac23b
env:
ACTIONS_ALLOW_USE_UNSECURE_NODE_VERSION: true
strategy:
matrix:
python:
- {
name: cp38,
abi: cp38,
version: '3.8',
}

steps:
- name: Install Maven
run: |
curl --fail --silent --show-error https://dlcdn.apache.org/maven/maven-3/3.9.6/binaries/apache-maven-3.9.6-bin.tar.gz -o /tmp/apache-maven-3.9.6-bin.tar.gz
tar xf /tmp/apache-maven-*.tar.gz -C /opt
echo /opt/apache-maven-3.9.6/bin >> $GITHUB_PATH
- name: Setup GraalVM
uses: graalvm/[email protected] # !!! this is last version compatible with manylinux 2014
with:
java-version: '17'
distribution: 'graalvm'
github-token: ${{ secrets.GITHUB_TOKEN }}

- name: Checkout sources
uses: actions/checkout@v3
with:
submodules: true

- name: Setup path
run: echo "/opt/python/${{ matrix.python.name }}-${{ matrix.python.abi }}/bin/" >> $GITHUB_PATH

- name: Install dependencies
run: pip3 install -r requirements.txt

- name: Build wheel
run: |
python3 setup.py bdist_wheel
auditwheel repair dist/*.whl
- name: Install wheel
run: pip3 install wheelhouse/*.whl --user

- name: Run basic pypowsybl import
working-directory: ./tests
run: python3 basic_import_test.py

- name: Upload binaries
uses: actions/[email protected]
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ github.event.release.upload_url }}
asset_path: ./dist/binaries.zip
asset_name: binaries-${{ github.event.release.tag_name }}-linux.zip
asset_content_type: application/zip

macos_windows_build:
name: Build ${{ matrix.config.name }} ${{ matrix.python.name }} wheel
runs-on: ${{ matrix.config.os }}
strategy:
matrix:
config:
- {
name: darwin,
os: macos-12,
}
- {
name: windows,
os: windows-2022,
}
python:
- {
name: cp38,
version: '3.8',
}

steps:
- name: Setup GraalVM
uses: graalvm/setup-graalvm@v1
with:
java-version: '17'
distribution: 'graalvm'
github-token: ${{ secrets.GITHUB_TOKEN }}

- name: Checkout sources
uses: actions/checkout@v3
with:
submodules: true

- name: Setup Python
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python.version }}

- name: Install Python dependencies
run: |
python -m pip install --upgrade pip
python -m pip install -r requirements.txt
- name: Build wheel
env:
MACOSX_DEPLOYMENT_TARGET: "10.16" # to ensure pip finds wheel when Big Sur is configured to return 10.16 as version instead of 11.0
run: python setup.py bdist_wheel

- name: Install wheel
shell: bash
run: python -m pip install dist/*.whl --user

- name: Run basic pypowsybl import
working-directory: ./tests
run: python3 basic_import_test.py

- name: Upload binaries
uses: actions/[email protected]
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ github.event.release.upload_url }}
asset_path: ./dist/binaries.zip
asset_name: binaries-${{ github.event.release.tag_name }}-${{ matrix.config.name }}.zip
asset_content_type: application/zip
10 changes: 7 additions & 3 deletions cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,19 @@
cmake_minimum_required(VERSION 3.14)
project(pypowsybl)

set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON)

option(BUILD_ONLY_POWSYBL_CPP "Build the only powsybl cpp library" OFF)

# change shared library rpath to resolve java library in same directory
# only works on linux
set(CMAKE_BUILD_WITH_INSTALL_RPATH TRUE)
set(CMAKE_INSTALL_RPATH "$ORIGIN")

#native-image math-native and powsybl-cpp targets
add_subdirectory(powsybl-cpp)
add_subdirectory(lib/pybind11)
add_subdirectory(pypowsybl-cpp)
if (NOT BUILD_ONLY_POWSYBL_CPP)
add_subdirectory(lib/pybind11)
add_subdirectory(pypowsybl-cpp)
endif()
85 changes: 48 additions & 37 deletions cpp/powsybl-cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,11 @@ project(powsybl-cpp)
if(MSVC)
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /MT")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /MTd")
set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON)
endif()

set(CMAKE_CXX_STANDARD 17)

include(ExternalProject)

set(POWSYBL_CPP_LIB ${CMAKE_SHARED_LIBRARY_PREFIX}powsybl-cpp${CMAKE_SHARED_LIBRARY_SUFFIX})
Expand Down Expand Up @@ -53,53 +56,60 @@ if(${CMAKE_SYSTEM_NAME} STREQUAL "Darwin")
set(MATH_NATIVE_INSTALL_EXTRA_COMMAND COMMAND install_name_tool -id @loader_path/${POWSYBL_MATH_NATIVE_LIB} ${CMAKE_CURRENT_BINARY_DIR}/${POWSYBL_MATH_NATIVE_JAR_ENTRY_DIR}/${POWSYBL_MATH_NATIVE_LIB})
endif()

ExternalProject_Add(mvn
SOURCE_DIR ${PYPOWSYBL_JAVA_SRC_DIR}
PATCH_COMMAND mvn --batch-mode clean package
CONFIGURE_COMMAND ""
BUILD_COMMAND ""
INSTALL_COMMAND ""
)

if("${CMAKE_BUILD_TYPE}" STREQUAL "Debug")
set(NATIVE_IMAGE_BUILD_OPTIONS "-H:GenerateDebugInfo=1" "-Ob")
endif()
if (NOT BUILD_ONLY_POWSYBL_CPP)

ExternalProject_Add(mvn
SOURCE_DIR ${PYPOWSYBL_JAVA_SRC_DIR}
PATCH_COMMAND mvn --batch-mode clean package
CONFIGURE_COMMAND ""
BUILD_COMMAND ""
INSTALL_COMMAND ""
)

if("${CMAKE_BUILD_TYPE}" STREQUAL "Debug")
set(NATIVE_IMAGE_BUILD_OPTIONS "-H:GenerateDebugInfo=1" "-Ob")
endif()

# as of GraalVM 23.0.0 G1 GC is only supported on Linux ADM64
if(${CMAKE_SYSTEM_NAME} STREQUAL "Linux" AND ${OS_BITS} STREQUAL "64")
set(NATIVE_IMAGE_GC "G1")
else()
set(NATIVE_IMAGE_GC "serial")
endif()

# as GraalVm does not follow same library naming convention (lib prefix is missing on Linux and MacOS) we need to rename
# it in the install command step
ExternalProject_Add(native-image
DEPENDS mvn
SOURCE_DIR ${PYPOWSYBL_JAVA_BIN_DIR}
DOWNLOAD_COMMAND ""
PATCH_COMMAND $ENV{JAVA_HOME}/bin/native-image ${NATIVE_IMAGE_BUILD_OPTIONS} --class-path ${PYPOWSYBL_JAVA_SRC_DIR}/target/pypowsybl-java.jar${EXTRA_JARS} -march=compatibility --no-fallback --shared --gc=${NATIVE_IMAGE_GC} -H:Name=pypowsybl-java -H:CLibraryPath=${CMAKE_CURRENT_SOURCE_DIR}
CONFIGURE_COMMAND ""
BUILD_COMMAND ""
INSTALL_COMMAND ${CMAKE_COMMAND} -E copy ${PYPOWSYBL_JAVA_BIN_DIR}/${PYPOWSYBL_JAVA_OLD_LIB} ${PYPOWSYBL_JAVA_BIN_DIR}/${PYPOWSYBL_JAVA_LIB} ${NATIVE_IMAGE_INSTALL_EXTRA_COMMAND}
)

# extract powsybl math native from jar for current platform
# powsybl-math-native.jar has been previously copied by maven build
add_custom_target(math-native ALL COMMAND ${CMAKE_COMMAND} -E tar x ${PYPOWSYBL_JAVA_SRC_DIR}/target/dependency/powsybl-math-native.jar ${POWSYBL_MATH_NATIVE_JAR_ENTRY_DIR}/${POWSYBL_MATH_NATIVE_LIB} ${MATH_NATIVE_INSTALL_EXTRA_COMMAND})

# as of GraalVM 23.0.0 G1 GC is only supported on Linux ADM64
if(${CMAKE_SYSTEM_NAME} STREQUAL "Linux" AND ${OS_BITS} STREQUAL "64")
set(NATIVE_IMAGE_GC "G1")
else()
set(NATIVE_IMAGE_GC "serial")
endif()

# as GraalVm does not follow same library naming convention (lib prefix is missing on Linux and MacOS) we need to rename
# it in the install command step
ExternalProject_Add(native-image
DEPENDS mvn
SOURCE_DIR ${PYPOWSYBL_JAVA_BIN_DIR}
DOWNLOAD_COMMAND ""
PATCH_COMMAND $ENV{JAVA_HOME}/bin/native-image ${NATIVE_IMAGE_BUILD_OPTIONS} --class-path ${PYPOWSYBL_JAVA_SRC_DIR}/target/pypowsybl-java.jar${EXTRA_JARS} -march=compatibility --no-fallback --shared --gc=${NATIVE_IMAGE_GC} -H:Name=pypowsybl-java -H:CLibraryPath=${CMAKE_CURRENT_SOURCE_DIR}
CONFIGURE_COMMAND ""
BUILD_COMMAND ""
INSTALL_COMMAND ${CMAKE_COMMAND} -E copy ${PYPOWSYBL_JAVA_BIN_DIR}/${PYPOWSYBL_JAVA_OLD_LIB} ${PYPOWSYBL_JAVA_BIN_DIR}/${PYPOWSYBL_JAVA_LIB} ${NATIVE_IMAGE_INSTALL_EXTRA_COMMAND}
)

# extract powsybl math native from jar for current platform
# powsybl-math-native.jar has been previously copied by maven build
add_custom_target(math-native ALL COMMAND ${CMAKE_COMMAND} -E tar x ${PYPOWSYBL_JAVA_SRC_DIR}/target/dependency/powsybl-math-native.jar ${POWSYBL_MATH_NATIVE_JAR_ENTRY_DIR}/${POWSYBL_MATH_NATIVE_LIB} ${MATH_NATIVE_INSTALL_EXTRA_COMMAND})

include_directories(${CMAKE_CURRENT_SOURCE_DIR} ${PYPOWSYBL_JAVA_BIN_DIR})
include_directories(${CMAKE_CURRENT_SOURCE_DIR} ${PYPOWSYBL_JAVA_BIN_DIR} ${POWSYBL_INCLUDE_DIR})

link_directories(${PYPOWSYBL_JAVA_BIN_DIR})
link_directories(${POWSYBL_JAVA_LIB_INSTALL_DIR})

set(POWSYBL_CPP_SOURCES "powsybl-cpp.cpp")

add_library(powsybl-cpp SHARED ${POWSYBL_CPP_SOURCES})
add_dependencies(powsybl-cpp native-image)

if(DEFINED CMAKE_LIBRARY_OUTPUT_DIRECTORY)
add_custom_command(TARGET powsybl-cpp POST_BUILD ${POWSYBL_CPP_INSTALL_EXTRA_COMMAND} COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_FILE:powsybl-cpp> ${PYPOWSYBL_JAVA_BIN_DIR}/${PYPOWSYBL_JAVA_LIB} ${CMAKE_CURRENT_BINARY_DIR}/${POWSYBL_MATH_NATIVE_JAR_ENTRY_DIR}/${POWSYBL_MATH_NATIVE_LIB} ${CMAKE_LIBRARY_OUTPUT_DIRECTORY})
endif(DEFINED CMAKE_LIBRARY_OUTPUT_DIRECTORY)
if (NOT BUILD_ONLY_POWSYBL_CPP)
add_dependencies(powsybl-cpp native-image)
if(DEFINED CMAKE_LIBRARY_OUTPUT_DIRECTORY)
add_custom_command(TARGET powsybl-cpp POST_BUILD ${POWSYBL_CPP_INSTALL_EXTRA_COMMAND} COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_FILE:powsybl-cpp> $<TARGET_LINKER_FILE:powsybl-cpp> ${PYPOWSYBL_JAVA_BIN_DIR}/${PYPOWSYBL_JAVA_LIB} ${CMAKE_CURRENT_BINARY_DIR}/${POWSYBL_MATH_NATIVE_JAR_ENTRY_DIR}/${POWSYBL_MATH_NATIVE_LIB} ${CMAKE_LIBRARY_OUTPUT_DIRECTORY})
endif(DEFINED CMAKE_LIBRARY_OUTPUT_DIRECTORY)
endif()

# Fix related to issue describred here https://github.com/actions/runner-images/issues/10004#issuecomment-2156109231
# Should fix incompatibility between MSVC runtime 14.40.XXX and previous version
Expand All @@ -109,3 +119,4 @@ if(MSVC)
endif()

target_link_libraries(powsybl-cpp PUBLIC ${PYPOWSYBL_JAVA_LIB})
install(TARGETS powsybl-cpp)
32 changes: 32 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
import sys
import platform
import subprocess
import zipfile
import glob

from setuptools import setup, Extension
from setuptools.command.build_ext import build_ext
Expand Down Expand Up @@ -66,6 +68,36 @@ def build_extension(self, ext):
subprocess.check_call(['cmake', cpp_source_dir] + cmake_args, cwd=self.build_temp, env=env)
subprocess.check_call(['cmake', '--build', '.'] + build_args, cwd=self.build_temp)

binaries = dict()
binaries['bin'] = []
binaries['lib'] = []
if platform.system() == "Windows":
binaries['bin'] = [os.path.join(extdir, 'math.dll'),
os.path.join(extdir, 'pypowsybl-java.dll')]
binaries['lib'] = [os.path.join(self.build_temp, 'java/pypowsybl-java.lib')]
elif platform.system() == "Linux":
binaries['lib'] = [os.path.join(extdir, 'libmath.so'),
os.path.join(extdir, 'libpypowsybl-java.so')]
elif platform.system() == "Darwin" :
binaries['lib'] = [os.path.join(extdir, 'libmath.dylib'),
os.path.join(extdir, 'libpypowsybl-java.dylib')]

includes = glob.glob(os.path.join(cpp_source_dir, 'powsybl-cpp/') + '*.h')
includes = includes + glob.glob(os.path.join(self.build_temp, 'java/') + '*.h')

if not os.path.exists(os.path.abspath('dist')):
os.makedirs(os.path.abspath('dist'))

binaries_archive = os.path.join(os.path.abspath('dist'), 'binaries.zip')
if os.path.exists(binaries_archive):
os.remove(binaries_archive)
with zipfile.ZipFile(binaries_archive, mode='x') as archive:
for binary in binaries['bin']:
archive.write(binary, arcname=os.path.join('bin', os.path.basename(binary)))
for lib in binaries['lib']:
archive.write(lib, arcname=os.path.join('lib', os.path.basename(lib)))
for include in includes:
archive.write(include, arcname=os.path.join('include/powsybl-cpp', os.path.basename(include)))

setup(
ext_modules=[PyPowsyblExtension()],
Expand Down

0 comments on commit 4718859

Please sign in to comment.