Setup pyconcept build with CMake

This commit is contained in:
IRBorisov 2024-04-17 00:11:47 +03:00
parent 6ad679c1fd
commit 843718b4a3
8 changed files with 54 additions and 51 deletions

View File

@ -19,7 +19,7 @@ output
packages
**/build
**/venv
**/pyconcept/import
**/pyconcept/ccl
**/egg-info

2
.gitignore vendored
View File

@ -11,7 +11,7 @@ build
output
venv/
CMakeUserPresets.json
pyconcept/import/
pyconcept/ccl/
*egg-info
ccl/rslang/src/RSParserImpl.output

25
.vscode/settings.json vendored
View File

@ -1,4 +1,20 @@
{
"search.exclude": {
".mypy_cache/": true,
".pytest_cache/": true
},
"python.testing.unittestArgs": ["-v", "-s", "./tests", "-p", "t_*.py"],
"python.testing.pytestEnabled": false,
"python.testing.unittestEnabled": true,
"python.analysis.typeCheckingMode": "off",
"python.analysis.ignore": ["**/tests/**", "**/venv/**"],
"cmake.configureOnEdit": false,
"cmake.configureOnOpen": false,
"cmake.sourceDirectory": "${workspaceFolder}/ccl",
"cmake.configureArgs": ["--preset=conan-default"],
"cmake.buildArgs": ["--preset=conan-release"],
"cmake.ctestArgs": ["--test-dir build", "--output-on-failure"],
"cmake.installPrefix": "output",
"cSpell.words": [
"coredll",
"DCMAKE",
@ -14,12 +30,5 @@
"pyconcept",
"rslang",
"symmdiff"
],
"cmake.configureOnEdit": false,
"cmake.configureOnOpen": false,
"cmake.sourceDirectory": "${workspaceFolder}/ccl",
"cmake.configureArgs": ["--preset=conan-default"],
"cmake.buildArgs": ["--preset=conan-release"],
"cmake.ctestArgs": ["--test-dir build", "--output-on-failure"],
"cmake.installPrefix": "output"
]
}

View File

@ -10,12 +10,13 @@ set(CMAKE_CXX_EXTENSIONS OFF)
## Project options
##
option(CC_UseSanitizers "Use sanitizers" FALSE)
option(CC_BuildTests "Include tests executable" FALSE)
# Compiler options
include(cmake/CXXTargets.cmake)
# Libraries folder
link_directories(import/lib)
## Import internal targets
add_subdirectory(ccl)
# Add pybind11
set(PYBIND11_FINDPYTHON ON)
@ -49,9 +50,6 @@ target_include_directories(pyconcept
target_link_libraries(pyconcept
PUBLIC
ConceptCoreLibrary
RSlang
cclLang
cclGraph
PRIVATE
pybind11_all_do_not_use
ccl_CXXwarnings

View File

@ -4,6 +4,5 @@ graft include
graft tests
graft cmake
include CMakeLists.txt
recursive-include import *
recursive-include ccl *

View File

@ -1,15 +1,20 @@
Set-Location $PSScriptRoot\..
$packageName = 'pyconcept'
$output = "${PSScriptRoot}\..\..\..\output\py\x64\${packageName}"
$output = "${PSScriptRoot}\..\..\output\py\${packageName}"
$python = '.\venv\Scripts\python.exe'
$conan = 'conan'
$conan = '.\venv\Scripts\conan.exe'
$ccl_source = "${PSScriptRoot}\..\..\ccl"
$ccl_destination = "${PSScriptRoot}\..\ccl"
$ccl_exclude = @('*.vcxproj*','*packages.config','CMakeUserPresets.json')
function Build {
PrepareEnv
# PrepareEnv
PrepareImports
PrepareOutput
$wheel = BuildWheel
BuildProject
$wheel = Get-Childitem -Path "${output}\*.whl" -Name
if (-not (${wheel}) -or $LASTEXITCODE -ne 0) {
Write-Error "No wheel generated for ${packageName}"
Exit 1
@ -19,7 +24,7 @@ function Build {
}
function PrepareEnv {
Write-Host "Setting up environment for ${python}" -ForegroundColor DarkGreen
Write-Host "Set up environment for ${python}" -ForegroundColor DarkGreen
if (-not (Test-Path -Path ${python} -PathType Leaf)) {
& 'python' -m venv .\venv
& $python -m pip install --upgrade pip
@ -29,25 +34,30 @@ function PrepareEnv {
function PrepareImports {
Write-Host 'Copy imports' -ForegroundColor DarkGreen
if (Test-Path -Path 'import') {
Remove-Item 'import' -Recurse -Force
if (Test-Path -Path ${ccl_destination}) {
Remove-Item ${ccl_destination} -Recurse -Force
}
Copy-Item -Path "..\..\output\include" -Destination "import\include" -Recurse
Copy-Item -Path "..\..\output\lib\x64" -Destination "import\lib" -Recurse
New-Item -Path ${ccl_destination} -ItemType Directory | Out-Null
$source = Resolve-Path(${ccl_source})
$destination = Resolve-Path(${ccl_destination})
Get-ChildItem ${source} -Recurse -Exclude ${ccl_exclude} `
| Where-Object -Property 'FullName' -CNotLike '*build*' `
| Copy-Item -Destination {Join-Path ${destination}.Path $_.FullName.Substring(${source}.Path.length)}
}
function PrepareOutput {
Write-Host "Clear output at ${output}" -ForegroundColor DarkGreen
if (Test-Path -Path ${output}) {
Remove-Item ${output} -Recurse -Force
}
}
function BuildWheel {
Write-Host 'Building project...' -ForegroundColor DarkGreen
function BuildProject {
Write-Host 'Configuring Conan...' -ForegroundColor DarkGreen
& ${conan} profile detect --force
& ${conan} install .
& $python -m build --no-isolation --wheel --outdir="${output}"
return Get-Childitem -Path "${output}\*.whl" -Name
Write-Host 'Building project...' -ForegroundColor DarkGreen
& $python -m build --wheel --no-isolation --outdir="${output}"
}
function TestWheel([string] $wheelPath) {

View File

@ -1,11 +0,0 @@
# Build single project
# TODO: setup project folder as parameter
Set-Location $PSScriptRoot
& conan profile detect --force
& conan install .
& cmake --preset conan-default
& cmake --build --preset conan-release
& ctest --test-dir build --output-on-failure
& cmake --install build --prefix ../output

View File

@ -32,11 +32,11 @@ class CMakeBuild(build_ext):
ext_fullpath = Path.cwd() / self.get_ext_fullpath(ext.name)
output_folder = ext_fullpath.parent.resolve()
debug = int(os.environ.get('DEBUG', 0)) if self.debug is None else self.debug
build_type = 'Debug' if debug else 'Release'
debug_flag = int(os.environ.get('DEBUG', 0)) if self.debug is None else self.debug
build_type = 'Debug' if debug_flag else 'Release'
cmake_generator = os.environ.get('CMAKE_GENERATOR', '')
cmake_args = [
'--preset conan-release',
'--preset conan-default',
f"-DCMAKE_LIBRARY_OUTPUT_DIRECTORY={output_folder}{os.sep}",
f"-DCMAKE_BUILD_TYPE={build_type}"
]
@ -44,7 +44,7 @@ class CMakeBuild(build_ext):
if 'CMAKE_ARGS' in os.environ:
cmake_args += [item for item in os.environ['CMAKE_ARGS'].split(' ') if item]
build_args = ['--preset conan-release']
build_args = ['--preset conan-debug' if debug_flag else '--preset conan-release']
if self.compiler.compiler_type != 'msvc':
if not cmake_generator or cmake_generator == 'Ninja':
try:
@ -80,15 +80,13 @@ class CMakeBuild(build_ext):
if hasattr(self, 'parallel') and self.parallel:
build_args += [f"-j{self.parallel}"]
build_temp = Path(self.build_temp) / ext.name
if not build_temp.exists():
build_temp.mkdir(parents=True)
subprocess.run(
['cmake', ext.sourcedir, *cmake_args], cwd=build_temp, check=True
['cmake', ext.sourcedir, *cmake_args],
check=True
)
subprocess.run(
['cmake', '--build', '.', *build_args], cwd=build_temp, check=True
['cmake', '--build', '.', *build_args],
check=True
)