Skip to content

Commit

Permalink
Fix conan on arm (#125)
Browse files Browse the repository at this point in the history
* Add arm profiles

* Add check depending on arch

* Bump benchmark version

* Fix "aarch64" -> "arm64" on conan Setup.py

* Fix RPi support

---------

Co-authored-by: Philipp Basler <[email protected]>
Co-authored-by: João Viana <[email protected]>
  • Loading branch information
3 people authored Apr 27, 2024
1 parent a7682be commit 54de6bd
Show file tree
Hide file tree
Showing 19 changed files with 139 additions and 31 deletions.
16 changes: 16 additions & 0 deletions .github/GetProfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import os
import sys

current = os.path.dirname(os.path.realpath(__file__))
parent = os.path.dirname(current)
sys.path.append(parent)

import Build

if __name__ == "__main__":

env_file = os.getenv('GITHUB_ENV')
with open(env_file, "a") as myfile:
myfile.write(f"GeneratedCMakeProfile={Build.get_preset()}")

print(f"Setting GeneratedCMakeProfile={Build.get_preset()}")
10 changes: 7 additions & 3 deletions .github/workflows/codecov.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,15 @@ jobs:
- name: Install conan
run: pip install conan>2
- run: python3 Setup.py --options EnableCoverage=True CompileBaryo=True UseVectorization=False
- run: cmake --preset conan-linux-x86_64-release

- name: Set cmake preset name
run: python3 .github/GetProfile.py

- run: cmake --preset $GeneratedCMakeProfile
- name: compile
run: cmake --build --preset conan-linux-x86_64-release -j${{ steps.cpu-cores.outputs.count }}
run: cmake --build --preset $GeneratedCMakeProfile -j${{ steps.cpu-cores.outputs.count }}
- name: Generate Coverage
run: cmake --build --preset conan-linux-x86_64-release -j${{ steps.cpu-cores.outputs.count }} -t coverage
run: cmake --build --preset $GeneratedCMakeProfile -j${{ steps.cpu-cores.outputs.count }} -t coverage
- name: Upload coverage
uses: codecov/codecov-action@v4
with:
Expand Down
9 changes: 7 additions & 2 deletions .github/workflows/codeql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,16 @@ jobs:
- name: Setup
run: python3 Setup.py --options CompileBaryo=True
if: matrix.language == 'cpp'

- name: Set cmake preset name
run: python3 .github/GetProfile.py
if: matrix.language == 'cpp'

- name: Preset cmake
run: cmake --preset conan-linux-x86_64-release
run: cmake --preset $GeneratedCMakeProfile
if: matrix.language == 'cpp'
- name: build
run: cmake --build --preset conan-linux-x86_64-release -j${{ steps.cpu-cores.outputs.count }}
run: cmake --build --preset $GeneratedCMakeProfile -j${{ steps.cpu-cores.outputs.count }}
if: matrix.language == 'cpp'

- name: Autobuild
Expand Down
25 changes: 21 additions & 4 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
tests-fullSetup:
strategy:
matrix:
setup: [ {os: ubuntu-latest, profile: conan-linux-x86_64-release}, {os: windows-latest, profile: conan-windows-x86_64-release}, {os: macos-latest, profile: conan-macos-x86_64-release}]
setup: [ {os: ubuntu-latest}, {os: windows-latest}, {os: macos-latest}]
runs-on: ${{matrix.setup.os}}
if: "!contains(github.event.head_commit.message, 'skip-ci')"

Expand All @@ -39,12 +39,29 @@ jobs:
uses: SimenB/github-actions-cpu-cores@v2
id: cpu-cores
- run: python3 Setup.py --options CompileBaryo=True

- name: Set cmake preset name
run: python3 .github/GetProfile.py

- name: cmake
run: cmake --preset $GeneratedCMakeProfile
if: runner.os != 'Windows'
- name: build
run: cmake --build --preset $GeneratedCMakeProfile -j${{ steps.cpu-cores.outputs.count }}
if: runner.os != 'Windows'
- name: run tests
run: ctest --preset $GeneratedCMakeProfile -j --output-on-failure
if: runner.os != 'Windows'

- name: cmake
run: cmake --preset ${{matrix.setup.profile}}
run: cmake --preset $env:GeneratedCMakeProfile
if: runner.os == 'Windows'
- name: build
run: cmake --build --preset ${{matrix.setup.profile}} -j${{ steps.cpu-cores.outputs.count }}
run: cmake --build --preset $env:GeneratedCMakeProfile -j${{ steps.cpu-cores.outputs.count }}
if: runner.os == 'Windows'
- name: run tests
run: ctest --preset ${{matrix.setup.profile}} -j --output-on-failure
run: ctest --preset $env:GeneratedCMakeProfile -j --output-on-failure
if: runner.os == 'Windows'



Expand Down
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,6 @@ build
*.out
*.synctex.gz

CMakeUserPresets.json
CMakeUserPresets.json
__pycache__/Build.cpython-310.pyc
__pycache__/Setup.cpython-310.pyc
24 changes: 18 additions & 6 deletions Build.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,22 @@
import subprocess
import sys

presets={
"linux": "conan-linux-x86_64-release",
"win32": "conan-windows-x86_64-release",
"darwin": "conan-macos-x86_64-release"
}
def get_preset():
preset = "conan-"
os = sys.platform
if os == "win32":
preset += "windows"
elif os == "linux":
preset += "linux"
elif os == "darwin":
preset += "macos"

preset += "-"
preset += Setup.get_arch()

preset += "-release"

return preset

def build(preset):
cmd=f"cmake --preset {preset}".split()
Expand All @@ -17,8 +28,9 @@ def build(preset):


def main():
Setup.setup_profiles()
Setup.conan_install_all(Setup.BuildMode.release)
build(presets[sys.platform])
build(get_preset())

if __name__ == "__main__":
main()
Expand Down
44 changes: 30 additions & 14 deletions Setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import shutil
from enum import Enum
from argparse import ArgumentParser, ArgumentTypeError
import platform


class ArgTypeEnum(Enum):
Expand All @@ -23,18 +24,33 @@ class BuildMode(ArgTypeEnum, Enum):
release = (1,)
debug = 2

def get_profile(os: str, arch: str, build_type: BuildMode):
profile = ""
if os == "win32":
profile += "windows"
elif os == "linux":
profile += "linux"
elif os == "darwin":
profile += "macos"

build_profiles = {
"win32": "windows-release",
"linux": "linux-release",
"darwin": "macos-release",
}
profile += "-"

target_profiles = {
"win32": {"release": "windows-release", "debug": "windows-debug"},
"linux": {"release": "linux-release", "debug": "linux-debug"},
"darwin": {"release": "macos-release", "debug": "macos-debug"},
}
if build_type == BuildMode.release:
profile += "release"
elif build_type == BuildMode.debug:
profile += "debug"

profile += "-"
profile += arch

return profile


def get_arch():
arch = "x86_64"
if platform.machine() == "aarch64" or platform.machine() == "arm64":
arch = "armv8"
return arch


def setup_profiles():
Expand All @@ -51,7 +67,8 @@ def conan_install(profile, additional_options=[], build_missing=False):
"tools.cmake.cmake_layout:build_folder_vars=['settings.os','settings.arch','settings.build_type']"
]

build_profile = build_profiles[sys.platform]

build_profile = get_profile(sys.platform, get_arch(), BuildMode.release)

cmd = f"conan install . -pr:h BSMPT/{profile} -pr:b BSMPT/{build_profile} ".split()

Expand All @@ -68,11 +85,10 @@ def conan_install(profile, additional_options=[], build_missing=False):


def conan_install_all(mode: BuildMode, options=[], build_missing=False):
profiles = target_profiles[sys.platform]
if mode == BuildMode.all or mode == BuildMode.release:
conan_install(profiles["release"], options, build_missing)
conan_install( get_profile(sys.platform, get_arch(), BuildMode.release) , options, build_missing)
if mode == BuildMode.all or mode == BuildMode.debug:
conan_install(profiles["debug"], options, build_missing)
conan_install(get_profile(sys.platform, get_arch(), BuildMode.debug), options, build_missing)


class ArgTypeEnum(Enum):
Expand Down
2 changes: 1 addition & 1 deletion conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def build_requirements(self):

if self.options.EnableTests:
self.test_requires("catch2/3.5.3")
self.test_requires("benchmark/1.6.1")
self.test_requires("benchmark/1.6.2")

def system_requirements(self):
if self.options.EnableCoverage:
Expand Down
10 changes: 10 additions & 0 deletions profiles/BSMPT/linux-debug-armv8
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[settings]
arch=armv8
build_type=Debug
compiler=gcc
compiler.cppstd=gnu17
compiler.libcxx=libstdc++11
compiler.version=11
os=Linux


File renamed without changes.
9 changes: 9 additions & 0 deletions profiles/BSMPT/linux-release-armv8
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[settings]
arch=armv8
build_type=Release
compiler=gcc
compiler.cppstd=gnu17
compiler.libcxx=libstdc++11
compiler.version=11
os=Linux

File renamed without changes.
8 changes: 8 additions & 0 deletions profiles/BSMPT/macos-debug-armv8
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[settings]
arch=armv8
build_type=Debug
compiler=apple-clang
compiler.cppstd=gnu17
compiler.libcxx=libc++
compiler.version=13
os=Macos
File renamed without changes.
8 changes: 8 additions & 0 deletions profiles/BSMPT/macos-release-armv8
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[settings]
arch=armv8
build_type=Release
compiler=apple-clang
compiler.cppstd=gnu17
compiler.libcxx=libc++
compiler.version=13
os=Macos
File renamed without changes.
File renamed without changes.
File renamed without changes.
1 change: 1 addition & 0 deletions test.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
A=conan-linux-x86_64-release

0 comments on commit 54de6bd

Please sign in to comment.