Created
February 9, 2022 12:09
-
-
Save wolfv/9d97208f089e1efe9726691ac08730cf to your computer and use it in GitHub Desktop.
Python based cross-platform build scripts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import subprocess | |
import os | |
from pathlib import Path | |
def initialize_globals(): | |
globals()['prefix'] = os.environ.get('PREFIX') | |
globals()['target_platform'] = os.environ.get('TARGET_PLATFORM') | |
globals()['src_dir'] = Path(os.environ.get('SRC_DIR')) | |
globals()['recipe_dir'] = Path(os.environ.get('RECIPE_DIR')) | |
initialize_globals() | |
run = subprocess.check_call | |
class RecipeBase: | |
workdir = src_dir | |
def __init__(self): | |
pass | |
def pre_configure(self): | |
pass | |
def configure(self): | |
args = [str(x) for x in [self.configure_cmd] + self.get_default_configure_args() + self.configure_args] | |
run( | |
args, | |
cwd=self.workdir, | |
) | |
def build(self): | |
pass | |
def install(self): | |
pass | |
def post_install(self): | |
pass | |
def get_default_configure_args(self): | |
return self.default_configure_args | |
class CMake(RecipeBase): | |
configure_cmd = "cmake" | |
build_cmd = "ninja" | |
cmakelists_dir = src_dir | |
default_configure_args = [ | |
f'-DCMAKE_INSTALL_PREFIX={prefix}', | |
f'-DCMAKE_PREFIX_PATH={prefix}', | |
'-DCMAKE_INSTALL_LIBDIR=lib', | |
'-GNinja', | |
] | |
default_args = [] | |
def get_default_configure_args(self): | |
return self.default_configure_args + [self.cmakelists_dir] | |
def pre_configure(self): | |
build_dir = self.workdir / "build" | |
build_dir.mkdir(parents=True, exist_ok=True) | |
self.workdir = build_dir | |
def build(self): | |
run(self.build_cmd, cwd=self.workdir) | |
def install(self): | |
run([self.build_cmd, "install"], cwd=self.workdir) | |
class Recipe(CMake): | |
# workdir = | |
cmakelists_dir = src_dir / "build" / "cmake" | |
configure_args = [ | |
'-DZSTD_LEGACY_SUPPORT=ON', | |
'-DZSTD_BUILD_PROGRAMS=OFF', | |
'-DZSTD_BUILD_CONTRIB=OFF', | |
'-DZSTD_PROGRAMS_LINK_SHARED=ON' | |
] | |
def pre_configure(self): | |
build_dir = self.workdir / "cmake_build" | |
build_dir.mkdir(parents=True, exist_ok=True) | |
self.workdir = build_dir | |
def __init__(self): | |
pass | |
if __name__ == '__main__': | |
r = Recipe() | |
r.pre_configure() | |
r.configure() | |
r.build() | |
r.install() | |
r.post_install() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment