Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add meson build system support #134

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
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
84 changes: 84 additions & 0 deletions renpybuild/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,9 @@ def build_environment(c):
c.var("configure", "./configure")
c.var("cmake", "cmake")

c.var("meson_configure", "meson setup")
c.var("meson_compile", "meson compile -j " + str(cpuccount))

c.var("sysroot", c.tmp / f"sysroot.{c.platform}-{c.arch}")
c.var("build_platform", sysconfig.get_config_var("HOST_GNU_TYPE"))

Expand Down Expand Up @@ -218,6 +221,11 @@ def build_environment(c):
c.var("cmake_system_processor", "x86_64")
c.var("cmake_args", "-DCMAKE_FIND_ROOT_PATH='{{ install }};{{ sysroot }}' -DCMAKE_SYSROOT={{ sysroot }}")

c.var("meson_cross_system", "linux")
c.var("meson_cross_kernel", "linux")
c.var("meson_cross_cpu_family", "x86_64")
c.var("meson_cross_cpu", "x86_64")

elif (c.platform == "linux") and (c.arch == "aarch64"):

llvm(c, clang_args="-target {{ host_platform }} --sysroot {{ sysroot }} -fPIC -pthread")
Expand All @@ -229,6 +237,11 @@ def build_environment(c):
c.var("cmake_system_processor", "aarch64")
c.var("cmake_args", "-DCMAKE_FIND_ROOT_PATH='{{ install }};{{ sysroot }}' -DCMAKE_SYSROOT={{ sysroot }}")

c.var("meson_cross_system", "linux")
c.var("meson_cross_kernel", "linux")
c.var("meson_cross_cpu_family", "aarch64")
c.var("meson_cross_cpu", "aarch64")

elif (c.platform == "linux") and (c.arch == "armv7l"):

llvm(c, clang_args="-target {{ host_platform }} --sysroot {{ sysroot }} -fPIC -pthread -mfpu=neon -mfloat-abi=hard")
Expand All @@ -240,6 +253,11 @@ def build_environment(c):
c.var("cmake_system_processor", "armv7")
c.var("cmake_args", "-DCMAKE_FIND_ROOT_PATH='{{ install }};{{ sysroot }}' -DCMAKE_SYSROOT={{ sysroot }}")

c.var("meson_cross_system", "linux")
c.var("meson_cross_kernel", "linux")
c.var("meson_cross_cpu_family", "arm")
c.var("meson_cross_cpu", "armhf")

elif (c.platform == "windows") and (c.arch == "x86_64"):

llvm(
Expand All @@ -254,6 +272,11 @@ def build_environment(c):
c.var("cmake_system_processor", "x86_64")
c.var("cmake_args", "-DCMAKE_FIND_ROOT_PATH='{{ install }};{{ cross }}/llvm-mingw/x86_64-w64-mingw32' -DCMAKE_SYSROOT={{ cross }}/llvm-mingw/x86_64-w64-mingw32")

c.var("meson_cross_system", "windows")
c.var("meson_cross_kernel", "nt")
c.var("meson_cross_cpu_family", "x86_64")
c.var("meson_cross_cpu", "x86_64")

elif (c.platform == "android") and (c.arch == "x86_64"):

android_llvm(c, "x86_64")
Expand All @@ -265,6 +288,11 @@ def build_environment(c):
c.var("android_abi", "x86_64")
c.var("cmake_args", "-DCMAKE_FIND_ROOT_PATH={{ install }} -DCMAKE_TOOLCHAIN_FILE={{cross}}/{{ndk_version}}/build/cmake/android.toolchain.cmake -DANDROID_ABI={{ android_abi }} -DANDROID_PLATFORM=android-21 -DANDROID_USE_LEGACY_TOOLCHAIN_FILE=OFF")

c.var("meson_cross_system", "android")
c.var("meson_cross_kernel", "linux")
c.var("meson_cross_cpu_family", "x86_64")
c.var("meson_cross_cpu", "x86_64")

elif (c.platform == "android") and (c.arch == "arm64_v8a"):

android_llvm(c, "aarch64")
Expand All @@ -276,6 +304,11 @@ def build_environment(c):
c.var("android_abi", "arm64-v8a")
c.var("cmake_args", "-DCMAKE_FIND_ROOT_PATH={{ install }} -DCMAKE_TOOLCHAIN_FILE={{cross}}/{{ndk_version}}/build/cmake/android.toolchain.cmake -DANDROID_ABI={{ android_abi }} -DANDROID_PLATFORM=android-21 -DANDROID_USE_LEGACY_TOOLCHAIN_FILE=OFF")

c.var("meson_cross_system", "android")
c.var("meson_cross_kernel", "linux")
c.var("meson_cross_cpu_family", "aarch64")
c.var("meson_cross_cpu", "aarch64")

elif (c.platform == "android") and (c.arch == "armeabi_v7a"):

android_llvm(c, "armv7a")
Expand All @@ -287,6 +320,11 @@ def build_environment(c):
c.var("android_abi", "armeabi-v7a")
c.var("cmake_args", "-DCMAKE_FIND_ROOT_PATH={{ install }} -DCMAKE_TOOLCHAIN_FILE={{cross}}/{{ndk_version}}/build/cmake/android.toolchain.cmake -DANDROID_ABI={{ android_abi }} -DANDROID_PLATFORM=android-21 -DANDROID_USE_LEGACY_TOOLCHAIN_FILE=OFF")

c.var("meson_cross_system", "android")
c.var("meson_cross_kernel", "linux")
c.var("meson_cross_cpu_family", "arm")
c.var("meson_cross_cpu", "armv7")

elif (c.platform == "mac") and (c.arch == "x86_64"):

llvm(
Expand All @@ -302,6 +340,12 @@ def build_environment(c):
c.var("cmake_system_processor", "x86_64")
c.var("cmake_args", "-DCMAKE_FIND_ROOT_PATH='{{ install }};{{ cross }}/sdk' -DCMAKE_SYSROOT={{ cross }}/sdk")

c.var("meson_cross_system", "darwin")
c.var("meson_cross_subsystem", "macos")
c.var("meson_cross_kernel", "xnu")
c.var("meson_cross_cpu_family", "x86_64")
c.var("meson_cross_cpu", "x86_64")

elif (c.platform == "mac") and (c.arch == "arm64"):

llvm(
Expand All @@ -317,6 +361,12 @@ def build_environment(c):
c.var("cmake_system_processor", "aarch64")
c.var("cmake_args", "-DCMAKE_FIND_ROOT_PATH='{{ install }};{{ cross }}/sdk' -DCMAKE_SYSROOT={{ cross }}/sdk")

c.var("meson_cross_system", "darwin")
c.var("meson_cross_subsystem", "macos")
c.var("meson_cross_kernel", "xnu")
c.var("meson_cross_cpu_family", "aarch64")
c.var("meson_cross_cpu", "arm64")

elif (c.platform == "ios") and (c.arch == "arm64"):

llvm(
Expand All @@ -331,6 +381,12 @@ def build_environment(c):
c.var("cmake_system_processor", "aarch64")
c.var("cmake_args", "-DCMAKE_FIND_ROOT_PATH='{{ install }};{{ cross }}/sdk' -DCMAKE_SYSROOT={{ cross }}/sdk")

c.var("meson_cross_system", "darwin")
c.var("meson_cross_subsystem", "ios")
c.var("meson_cross_kernel", "xnu")
c.var("meson_cross_cpu_family", "aarch64")
c.var("meson_cross_cpu", "aarch64")

elif (c.platform == "ios") and (c.arch == "sim-arm64"):

llvm(
Expand All @@ -345,6 +401,12 @@ def build_environment(c):
c.var("cmake_system_processor", "aarch64")
c.var("cmake_args", "-DCMAKE_FIND_ROOT_PATH='{{ install }};{{ cross }}/sdk' -DCMAKE_SYSROOT={{ cross }}/sdk")

c.var("meson_cross_system", "darwin")
c.var("meson_cross_subsystem", "ios-simulator")
c.var("meson_cross_kernel", "xnu")
c.var("meson_cross_cpu_family", "aarch64")
c.var("meson_cross_cpu", "aarch64")

elif (c.platform == "ios") and (c.arch == "sim-x86_64"):

llvm(
Expand All @@ -359,6 +421,12 @@ def build_environment(c):
c.var("cmake_system_processor", "x86_64")
c.var("cmake_args", "-DCMAKE_FIND_ROOT_PATH='{{ install }};{{ cross }}/sdk' -DCMAKE_SYSROOT={{ cross }}/sdk")

c.var("meson_cross_system", "darwin")
c.var("meson_cross_subsystem", "ios-simulator")
c.var("meson_cross_kernel", "xnu")
c.var("meson_cross_cpu_family", "x86_64")
c.var("meson_cross_cpu", "x86_64")

elif (c.platform == "web") and (c.arch == "wasm") and (c.name != "web"):

# Use emscripten wrapper to configure and build
Expand Down Expand Up @@ -399,6 +467,11 @@ def build_environment(c):
c.var("cmake_system_processor", "generic")
c.var("cmake_args", "-DCMAKE_FIND_ROOT_PATH={{ install }}")

c.var("meson_cross_system", "emscripten")
c.var("meson_cross_kernel", "none")
c.var("meson_cross_cpu_family", "wasm32")
c.var("meson_cross_cpu", "wasm32")


if c.kind not in ( "host", "host-python", "cross" ):
c.env("PKG_CONFIG_LIBDIR", "{{ install }}/lib/pkgconfig:{{ PKG_CONFIG_LIBDIR }}")
Expand All @@ -411,6 +484,17 @@ def build_environment(c):

c.var("cmake", "{{cmake}} {{ cmake_args }} -DCMAKE_PROJECT_INCLUDE_BEFORE={{root}}/tools/cmake_build_variables.cmake -DCMAKE_BUILD_TYPE=Release")

if not "meson_cross_subsystem" in c.variables:
c.var("meson_cross_subsystem", "{{ meson_cross_system }} ")

if c.kind not in ( "host", "host-python", "cross" ):
c.var("meson_build_kind", "cross")
else:
c.var("meson_build_kind", "native")

c.var("meson_config_file", "{{ install }}/meson_{{meson_build_kind}}_file.txt")
c.var("meson_args", "--{{meson_build_kind}}-file={{meson_config_file}} --buildtype=release -Dc_std=gnu17 -Dcpp_std=gnu++17")

# Used by zlib.
if c.kind != "host":
c.var("cross_config", "--host={{ host_platform }} --build={{ build_platform }}")
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,4 @@ sphinxcontrib-qthelp==2.0.0
sphinxcontrib-serializinghtml==2.0.0
typing==3.7.4.3
urllib3==2.2.2
meson>=1.4.1
1 change: 1 addition & 0 deletions tasks/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from . import cython

from . import env_sh
from . import meson_setup

from . import sysroot
from . import toolchain
Expand Down
61 changes: 61 additions & 0 deletions tasks/meson_setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
from renpybuild.context import Context
from renpybuild.task import task

@task(platforms="all")
def unpack(c: Context):

# Remove flags for compiler and set them using meson's method
for compiler_var in ("CC", "CXX", "CPP"):
updated_var = c.environ[compiler_var].replace("-fuse-ld=lld -Wno-unused-command-line-argument ", "")

if compiler_var == "CXX":
updated_var = updated_var.replace(" -std=gnu++17", "")
else:
updated_var = updated_var.replace(" -std=gnu17", "")

c.env(compiler_var, updated_var)

# Set linker type
c.env("CC_LD", "lld")
c.env("CXX_LD", "lld")

if c.platform == "mac" or c.platform == "ios":
c.env("OBJC_LD", "lld")
c.env("OBJCXX_LD", "lld")

c.run("""
meson env2mfile --cross
-o "{{ install }}/meson_cross_file.txt"
--system={{ meson_cross_system }}
--subsystem={{ meson_cross_subsystem }}
--kernel={{ meson_cross_kernel }}
--cpu-family={{ meson_cross_cpu_family }}
--cpu={{ meson_cross_cpu }}
""")

# Delete option if its value is "none"
c.run(""" sed -i "/'none'/d" "{{ install }}/meson_cross_file.txt" """)

@task(kind="host", platforms="all")
def unpack(c: Context):

# Remove flags for compiler and set them using meson's method
for compiler_var in ("CC", "CXX", "CPP"):
updated_var = c.environ[compiler_var].replace("-fuse-ld=lld -Wno-unused-command-line-argument ", "")

if compiler_var == "CC":
updated_var = updated_var.replace(" -std=gnu17", "")
elif compiler_var == "CXX":
updated_var = updated_var.replace(" -std=gnu++17", "")

c.env(compiler_var, updated_var)

# Set linker type
c.env("CC_LD", "lld")
c.env("CXX_LD", "lld")

if c.platform == "mac" or c.platform == "ios":
c.env("OBJC_LD", "lld")
c.env("OBJCXX_LD", "lld")

c.run("""meson env2mfile --native -o "{{ install }}/meson_native_file.txt" """)