Skip to content

Commit

Permalink
Added script validation on a minimal version of python.
Browse files Browse the repository at this point in the history
Fixed quotes in string interpolation to support the minimal version.
Supersedes #58
  • Loading branch information
DmitriySalnikov committed Nov 14, 2024
1 parent 520344d commit 8a7dcfd
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 23 deletions.
29 changes: 29 additions & 0 deletions .github/workflows/gdextension_build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,35 @@ jobs:
use_cache: ${{env.USE_CACHE}}
token: ${{secrets.TELEMETRY_TOKEN}}

# ============================================

check-python-version:
name: 🐍 Check compatibility with python
runs-on: ubuntu-latest
strategy:
matrix:
PYTHON_VER: ["3.8"] # this is the minimum available version to install on ubuntu 22.04 and 24.04
# but the code is most likely compatible with python 3.6
steps:
- name: Checkout
uses: actions/checkout@v4
with:
sparse-checkout: |
.
patches
- name: Setup python ${{matrix.PYTHON_VER}}
uses: actions/setup-python@v5
with:
python-version: ${{matrix.PYTHON_VER}}

- name: Try to compile all .py files
run: |
python --version
files="SConstruct $(find . -maxdepth 1 -name "*.py") $(find patches -name "*.py")"
echo "Found files: '$files'"
python -m py_compile $files
echo "All files compiled successfully!"
# ============================================

Expand Down
70 changes: 47 additions & 23 deletions lib_utils_external.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,19 @@
# Get the name of the cmake build directory
def get_cmake_build_dir_name(env: SConsEnvironment) -> str:
if env.get("threads", True) and env["platform"] == "web":
return f"{env["platform"]}_{env["arch"]}_threads"
return f"cmake_build_out/{env["platform"]}_{env["arch"]}"
return f'{env["platform"]}_{env["arch"]}_threads'
return f'cmake_build_out/{env["platform"]}_{env["arch"]}'


# Get a path to the build folder of the cmake library
def get_cmake_build_dir(env: SConsEnvironment, lib_path: str) -> str:
abs_scons_root = os.path.dirname(os.path.abspath(__file__))
# CMake doesn't seem to be able to work with the cache at all...
#
#scons_cache_path = os.environ.get("SCONS_CACHE")
#if scons_cache_path:
# scons_cache_path = os.environ.get("SCONS_CACHE")
# if scons_cache_path:
# return os.path.join(abs_scons_root, scons_cache_path, "cmake", lib_path, get_cmake_build_dir_name(env))
#else:
# else:
return os.path.join(abs_scons_root, lib_path, get_cmake_build_dir_name(env))


Expand Down Expand Up @@ -72,7 +72,7 @@ def apply_git_patches(env: SConsEnvironment, patches_to_apply: list, working_dir
encoding="utf-8",
)
print_subprocess_result(result, "git")
print(f"Successfully applied patch: {patch}")
print(f"Successfully applied patch: '{patch}'")
except subprocess.CalledProcessError as e:
print_subprocess_result(e, "git")
print("Please fix the patches, disable them, or try to git reset!")
Expand All @@ -91,40 +91,64 @@ def cmake_build_project(env: SConsEnvironment, lib_path: str, extra_args: list,
linker_flags = extra_c_compiler_flags.get("linker_flags", []).copy()

if platform == "windows":
arch_map = { "arm32": "ARM", "arm64": "ARM64", "x86_32": "Win32", "x86_64":"x64" }
platform_args += ["-G", "Visual Studio 17 2022",
"-A", arch_map[arch],
"-DCMAKE_MSVC_RUNTIME_LIBRARY=MultiThreaded" + ("" if env["use_static_cpp"] else "DLL")]
arch_map = {"arm32": "ARM", "arm64": "ARM64", "x86_32": "Win32", "x86_64": "x64"}
platform_args += [
"-G",
"Visual Studio 17 2022",
"-A",
arch_map[arch],
"-DCMAKE_MSVC_RUNTIME_LIBRARY=MultiThreaded" + ("" if env["use_static_cpp"] else "DLL"),
]
elif platform == "linux":
platform_args += ["-G", "Ninja Multi-Config",]
platform_args += [
"-G",
"Ninja Multi-Config",
]
elif platform == "macos":
platform_args += ["-G", "Ninja Multi-Config",
"-DCMAKE_SYSTEM_NAME=Darwin",]
platform_args += [
"-G",
"Ninja Multi-Config",
"-DCMAKE_SYSTEM_NAME=Darwin",
]
elif platform == "ios":
platform_args += ["-G", "Ninja Multi-Config",
"-DCMAKE_SYSTEM_NAME=iOS",]
platform_args += [
"-G",
"Ninja Multi-Config",
"-DCMAKE_SYSTEM_NAME=iOS",
]
elif platform == "android":
arch_map = { "arm32": "armeabi-v7a", "arm64": "arm64-v8a", "x86_32": "x86", "x86_64":"x86_64" }
platform_args += ["-G", "Ninja Multi-Config",
f"-DCMAKE_TOOLCHAIN_FILE={os.getenv("ANDROID_HOME")}/ndk/25.2.9519653/build/cmake/android.toolchain.cmake",
f"-DANDROID_ABI={arch_map[arch]}", f"-DANDROID_PLATFORM={env.get("android_api_level", 21)}",]
arch_map = {"arm32": "armeabi-v7a", "arm64": "arm64-v8a", "x86_32": "x86", "x86_64": "x86_64"}
platform_args += [
"-G",
"Ninja Multi-Config",
f'-DCMAKE_TOOLCHAIN_FILE={os.getenv("ANDROID_HOME")}/ndk/25.2.9519653/build/cmake/android.toolchain.cmake',
f"-DANDROID_ABI={arch_map[arch]}",
f'-DANDROID_PLATFORM={env.get("android_api_level", 21)}',
]
elif platform == "web":
platform_args += ["-G", "Ninja Multi-Config",
f"-DCMAKE_TOOLCHAIN_FILE={os.path.dirname(WhereIs("emcc"))}/cmake/Modules/Platform/Emscripten.cmake",]
platform_args += [
"-G",
"Ninja Multi-Config",
f'-DCMAKE_TOOLCHAIN_FILE={os.path.dirname(WhereIs("emcc"))}/cmake/Modules/Platform/Emscripten.cmake',
]
if env.get("threads", True):
compiler_flags += ["-sUSE_PTHREADS=1"]
linker_flags += ["-sUSE_PTHREADS=1"]

build_args += ["--config", "Debug" if env["dev_build"] else "Release"]

if len(compiler_flags):
platform_args += [f"-DCMAKE_C_FLAGS={";".join(compiler_flags)}", f"-DCMAKE_CXX_FLAGS={";".join(compiler_flags)}"]
platform_args += [
f'-DCMAKE_C_FLAGS={";".join(compiler_flags)}',
f'-DCMAKE_CXX_FLAGS={";".join(compiler_flags)}',
]
if len(linker_flags):
platform_args += [f"-DCMAKE_EXE_LINKER_FLAGS={";".join(linker_flags)}"]
platform_args += [f'-DCMAKE_EXE_LINKER_FLAGS={";".join(linker_flags)}']

curdir = os.curdir
os.chdir(lib_path)
try:

def config():
result = subprocess.run(
["cmake", f"-B{get_cmake_build_dir(env, lib_path)}"] + platform_args + extra_args,
Expand Down

0 comments on commit 8a7dcfd

Please sign in to comment.