Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/build-test-run-reusable-workflow.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ jobs:
with:
python-version: '3.11'
- run: |
python -u Scripts/ConanSetup.py
python -u Scripts/BuildAndInstallExternalLibs.py --TargetPlatform ${{ inputs.target-platform }}
python -u Scripts/BuildAndInstallCoDeLib.py --TargetPlatform ${{ inputs.target-platform }}
python -u Scripts/BuildBenchmark.py --TargetPlatform ${{ inputs.target-platform }}
Expand Down
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,11 @@ Test*.txt*

# Python
__pycache__/
.venv

# Custom
AddedFlags.cmake
tmp
tmp

# Conan
build/
4 changes: 4 additions & 0 deletions Benchmark/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ include(FetchContent)

project(COMPRESSION_DECOMPRESSION_BENCHMARK C)

list(APPEND CMAKE_PREFIX_PATH ${MINIZIP_INSTALL_PATH})
list(APPEND CMAKE_PREFIX_PATH ${CODELIB_INSTALL_PATH})
message(STATUS "CMAKE_PREFIX_PATH: ${CMAKE_PREFIX_PATH}")

# b63
FetchContent_Declare(
b63
Expand Down
3 changes: 3 additions & 0 deletions CoDeLib/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
cmake_minimum_required(VERSION 3.28)
project(COMPRESSION_DECOMPRESSION_LIB VERSION 0.0.1 LANGUAGES C)

list(APPEND CMAKE_PREFIX_PATH ${MINIZIP_INSTALL_PATH})
message(STATUS "CMAKE_PREFIX_PATH: ${CMAKE_PREFIX_PATH}")

add_compile_definitions("$<$<NOT:$<CONFIG:Debug>>:NDEBUG>")

# Required for FileUtils.c (and its tests) to use the correct versions of ftello and similar functions
Expand Down
10 changes: 10 additions & 0 deletions ConanProfiles/Linux_x86_64
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[settings]
arch=x86_64
compiler=gcc
compiler.libcxx=libstdc++11
compiler.version=14
os=Linux

# https://github.com/conan-io/conan-center-index/issues/19340
[conf]
tools.build:compiler_executables={ "c" : "gcc", "cpp": "g++" }
10 changes: 10 additions & 0 deletions ConanProfiles/Windows_x86_64
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[settings]
arch=x86_64
compiler=gcc
compiler.libcxx=libstdc++11
compiler.version=14
os=Windows

# https://github.com/conan-io/conan-center-index/issues/19340
[conf]
tools.build:compiler_executables={ "c" : "gcc", "cpp": "g++" }
7 changes: 7 additions & 0 deletions DevEnvSetup.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,13 @@ Install the recommended packages for this reposity (see `./vscode/extensions.jso
- Install **C development packages**: `$ apt install build-essential`
- Install **CMake**: https://cmake.org/download/ (>= 3.28)

# Conan

```sh
$ python ./Scripts/ConanSetup.py
```


# Verify
Now you should be able build and run:

Expand Down
18 changes: 11 additions & 7 deletions Scripts/BuildAndInstallCoDeLib.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,6 @@ def BuildAndInstallCoDeLib(
buildEnv.GetTargetPlatform()
)

ExternalZlibLibInstallPath = Path(
ExternalLibPath / "zlib/Install" / targetPlatformString / BuildTypeString
)
ExternalMinizipNgLibInstallPath = Path(
ExternalLibPath / "minizip-ng/Install" / targetPlatformString / BuildTypeString
)
Expand All @@ -73,14 +70,19 @@ def BuildAndInstallCoDeLib(
print("==============================")
print(ProjectName + ": Configuring ({})".format(BuildTypeString))
print("==============================")
configureCommand = 'cmake -G "{0}" -DCMAKE_TOOLCHAIN_FILE="{1}" -S "{2}" -B "{3}" -DCMAKE_INSTALL_PREFIX="{4}" -DCMAKE_BUILD_TYPE={5} -DZLIB_ROOT="{6}" -DCMAKE_PREFIX_PATH="{7}"'.format(
configureCommand = 'cmake -G "{0}" -DCMAKE_TOOLCHAIN_FILE="{1}" -S "{2}" -B "{3}" -DCMAKE_INSTALL_PREFIX="{4}" -DCMAKE_BUILD_TYPE={5} -DMINIZIP_INSTALL_PATH="{6}"'.format(
buildEnv.GetCmakeGenerator(),
buildEnv.GetCustomToolChainPath(),
Path(
RepositoryRootPath
/ "build/conan/build"
/ BuildTypeString
/ "generators"
/ "conan_toolchain.cmake"
),
CoDeLibRootPath,
BuildDirectory,
InstallDirectory,
BuildTypeString,
ExternalZlibLibInstallPath,
ExternalMinizipNgLibInstallPath,
)
print(configureCommand)
Expand All @@ -93,7 +95,9 @@ def BuildAndInstallCoDeLib(
print("==============================")
print(ProjectName + ": Building ({})".format(BuildTypeString))
print("==============================")
buildCommand = "cmake --build {0} -- -j 4".format(BuildDirectory)
buildCommand = "cmake --build {0} --config {1} -- -j 4".format(
BuildDirectory, BuildTypeString
)
print(buildCommand)
subprocess.run(
buildCommand,
Expand Down
84 changes: 3 additions & 81 deletions Scripts/BuildAndInstallExternalLibs.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,82 +36,6 @@
ExternalLibPath = Path(RepositoryRootPath / "External")


##############################
# zlib
##############################
def BuildAndInstallZlib(
buildEnv: EnvironmentConfig.EnvironmentConfiguration,
buildConfig: EnvironmentConfig.BuildConfig = EnvironmentConfig.BuildConfig.DEBUG,
):
ProjectName = "zlib"

BuildTypeString = EnvironmentConfig.BuildConfig.ToCMakeBuildType(buildConfig)
targetPlatformString = EnvironmentConfig.Platform.PlatformToOsName(
buildEnv.GetTargetPlatform()
)

TopLevelCMakeListsDirectory = Path(ExternalLibPath / ProjectName)
BuildDirectory = Path(
ExternalLibPath / ProjectName / "Build" / targetPlatformString / BuildTypeString
)
InstallDirectory = Path(
ExternalLibPath
/ ProjectName
/ "Install"
/ targetPlatformString
/ BuildTypeString
)

if not BuildDirectory.exists():
BuildDirectory.mkdir(parents=True)

if InstallDirectory.exists():
shutil.rmtree(InstallDirectory)
InstallDirectory.mkdir(parents=True)

os.chdir(RepositoryRootPath)

print("==============================")
print(ProjectName + ": Configuring ({})".format(BuildTypeString))
print("==============================")
configureCommand = 'cmake -G "{0}" -DCMAKE_TOOLCHAIN_FILE="{1}" -S {2} -B {3} -DCMAKE_INSTALL_PREFIX="{4}" -DZLIB_BUILD_EXAMPLES=OFF -DCMAKE_BUILD_TYPE={5} -DZLIB_BUILD_SHARED=OFF'.format(
buildEnv.GetCmakeGenerator(),
buildEnv.GetCustomToolChainPath(),
TopLevelCMakeListsDirectory,
BuildDirectory,
InstallDirectory,
BuildTypeString,
)
print(configureCommand)
subprocess.run(
configureCommand,
shell=True,
check=True,
)

print("==============================")
print(ProjectName + ": Building ({})".format(BuildTypeString))
print("==============================")
buildCommand = "cmake --build {0} -- -j 4".format(BuildDirectory)
print(buildCommand)
subprocess.run(
buildCommand,
shell=True,
check=True,
)

print("==============================")
print(ProjectName + ": Installing ({})".format(BuildTypeString))
print("==============================")
installCommand = "cmake --install {0}".format(BuildDirectory)
print(installCommand)
subprocess.run(
installCommand,
shell=True,
check=True,
)


##############################
# minizip-ng
##############################
Expand Down Expand Up @@ -170,7 +94,9 @@ def BuildAndInstallMinizipNg(
print("==============================")
print(ProjectName + ": Building ({})".format(BuildTypeString))
print("==============================")
buildCommand = "cmake --build {0}".format(BuildDirectory)
buildCommand = "cmake --build {0} --config {1} -- -j 4".format(
BuildDirectory, BuildTypeString
)
print(buildCommand)
subprocess.run(
buildCommand,
Expand All @@ -194,10 +120,6 @@ def BuildAndInstallMinizipNg(
RepositoryRootPath, targetPlatform
)

# zlib
BuildAndInstallZlib(BuildEnv, EnvironmentConfig.BuildConfig.DEBUG)
BuildAndInstallZlib(BuildEnv, EnvironmentConfig.BuildConfig.RELEASE)

# minizip-ng
BuildAndInstallMinizipNg(BuildEnv, EnvironmentConfig.BuildConfig.DEBUG)
BuildAndInstallMinizipNg(BuildEnv, EnvironmentConfig.BuildConfig.RELEASE)
23 changes: 15 additions & 8 deletions Scripts/BuildBenchmark.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,7 @@ def BuildBenchmark(
CoDeLibInstallDirectory = Path(
CoDeLibPath / "Install" / targetPlatformString / BuildTypeString
)
ExternalZlibLibInstallPath = Path(
ExternalLibPath / "zlib/Install" / targetPlatformString / BuildTypeString
)

ExternalMinizipNgLibInstallPath = Path(
ExternalLibPath / "minizip-ng/Install" / targetPlatformString / BuildTypeString
)
Expand All @@ -72,16 +70,22 @@ def BuildBenchmark(
print("==============================")
print(ProjectName + ": Configuring ({})".format(BuildTypeString))
print("==============================")
configureCommand = 'cmake -G "{0}" -DCMAKE_TOOLCHAIN_FILE="{1}" -S {2} -B {3} -DCMAKE_BUILD_TYPE={4} -DZLIB_ROOT="{5}" -DCMAKE_PREFIX_PATH="{6};{7}"'.format(
configureCommand = 'cmake -G "{0}" -DCMAKE_TOOLCHAIN_FILE="{1}" -S {2} -B {3} -DCMAKE_BUILD_TYPE={4} -DMINIZIP_INSTALL_PATH="{5}" -DCODELIB_INSTALL_PATH="{6}"'.format(
buildEnv.GetCmakeGenerator(),
buildEnv.GetCustomToolChainPath(),
Path(
RepositoryRootPath
/ "build/conan/build"
/ BuildTypeString
/ "generators"
/ "conan_toolchain.cmake"
),
BenchmarkRootPath,
BuildDirectory,
BuildTypeString,
ExternalZlibLibInstallPath,
CoDeLibInstallDirectory,
ExternalMinizipNgLibInstallPath,
CoDeLibInstallDirectory,
)
print(configureCommand)
subprocess.run(
configureCommand,
shell=True,
Expand All @@ -91,7 +95,10 @@ def BuildBenchmark(
print("==============================")
print(ProjectName + ": Building ({})".format(BuildTypeString))
print("==============================")
buildCommand = "cmake --build {0} -- -j 4".format(BuildDirectory)
buildCommand = "cmake --build {0} --config {1} -- -j 4".format(
BuildDirectory, BuildTypeString
)
print(buildCommand)
subprocess.run(
buildCommand,
shell=True,
Expand Down
107 changes: 107 additions & 0 deletions Scripts/ConanSetup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
import os
from pathlib import Path
import EnvironmentConfig
import subprocess

hostPlatform = EnvironmentConfig.Platform.OsNameToPlatform(os.name)

currentScriptPath = Path(os.path.dirname(os.path.abspath(__file__)))
repositoryRootPath = Path(currentScriptPath.parent)

venvPath = Path(repositoryRootPath / ".venv")
if not venvPath.exists():
print("Creating virtual environment at {}".format(venvPath))
subprocess.run(
"python -m venv {}".format(venvPath),
shell=True,
check=True,
)
else:
print("Virtual environment already exists at {}".format(venvPath))

print("Activating virtual environment...")

VirtualEnvPythonPath = Path(
venvPath
/ ("Scripts" if hostPlatform == EnvironmentConfig.Platform.WINDOWS else "bin")
/ "python"
)


print("Upgrading pip...")
pipUpgradeCommand = "{} -m pip install --upgrade pip".format(VirtualEnvPythonPath)
print(pipUpgradeCommand)
subprocess.run(
pipUpgradeCommand,
shell=True,
check=True,
)

requirementsFilePath = Path(repositoryRootPath / "requirements.txt")
if requirementsFilePath.exists():
print("Installing required packages from {}".format(requirementsFilePath))
installCommand = "{} -m pip install -r {}".format(
VirtualEnvPythonPath, requirementsFilePath
)
print(installCommand)
subprocess.run(
installCommand,
shell=True,
check=True,
)
else:
print(
"No requirements.txt file found at {}, skipping package installation.".format(
requirementsFilePath
)
)

print("Virtual environment setup complete.")

VirtualEnvConanPath = Path(
venvPath
/ ("Scripts" if hostPlatform == EnvironmentConfig.Platform.WINDOWS else "bin")
/ "conan"
)

print("Getting conan profile...")
conanProfileCommand = "{} profile detect --force".format(VirtualEnvConanPath)
print(conanProfileCommand)
subprocess.run(
conanProfileCommand,
shell=True,
check=True,
)

print("Getting Conan dependencies...")
buildTypes = ["Debug", "Release"]
profiles = ["Windows_x86_64", "Linux_x86_64"]
for profile in profiles:
if (
hostPlatform == EnvironmentConfig.Platform.WINDOWS
and profile.startswith("Linux")
) or (
hostPlatform == EnvironmentConfig.Platform.LINUX
and profile.startswith("Windows")
):
continue
for buildType in buildTypes:
print(
"Installing Conan dependencies for build type '{}' and profile '{}'...".format(
buildType, profile
)
)
conanInstallCommand = '{0} install "{1}" --profile:host={2} --profile:build={3} --output-folder="{4}" --build=missing --settings=build_type={5}'.format(
VirtualEnvConanPath,
Path(repositoryRootPath / "conanfile.py"),
Path(repositoryRootPath / "ConanProfiles" / profile),
Path(repositoryRootPath / "ConanProfiles" / profile),
Path(repositoryRootPath / "build" / "conan"),
buildType,
)
print(conanInstallCommand)
subprocess.run(
conanInstallCommand,
shell=True,
check=True,
)
Loading
Loading