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 option to skip emscripten version check #53

Merged
merged 6 commits into from
Nov 9, 2024
Merged
Show file tree
Hide file tree
Changes from 4 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
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]

### Added

- Add `skip_emscripten_version_check` flag to skip emscripten version check.
[#53](https://github.com/pyodide/pyodide-build/pull/53)

## [0.29.0] - 2024/09/19

### Added
Expand Down
12 changes: 9 additions & 3 deletions pyodide_build/build_env.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
from packaging.tags import Tag, compatible_tags, cpython_tags

from pyodide_build import __version__
from pyodide_build.common import search_pyproject_toml, xbuildenv_dirname
from pyodide_build.common import search_pyproject_toml, to_bool, xbuildenv_dirname
from pyodide_build.config import ConfigManager
from pyodide_build.recipe import load_all_recipes

Expand Down Expand Up @@ -238,6 +238,10 @@ def get_emscripten_version_info() -> str:


def check_emscripten_version() -> None:
skip = get_build_flag("SKIP_EMSCRIPTEN_VERSION_CHECK")
if to_bool(skip):
return

needed_version = emscripten_version()
try:
version_info = get_emscripten_version_info()
Expand All @@ -248,8 +252,10 @@ def check_emscripten_version() -> None:
installed_version = None
try:
for x in reversed(version_info.partition("\n")[0].split(" ")):
if re.match(r"[0-9]+\.[0-9]+\.[0-9]+", x):
installed_version = x
# (X.Y.Z) or (X.Y.Z)-git
match = re.match(r"(\d+\.\d+\.\d+)(-\w+)?", x)
if match:
installed_version = match.group(1)
break
except Exception:
raise RuntimeError("Failed to determine Emscripten version.") from None
Expand Down
7 changes: 7 additions & 0 deletions pyodide_build/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -440,3 +440,10 @@ def search_pyproject_toml(
raise ValueError(f"Could not parse {pyproject_file}.") from e

return None, None


def to_bool(value: str) -> bool:
"""
Convert a string to a boolean value. Useful for parsing environment variables.
"""
return value.lower() not in {"", "0", "false", "no", "off"}
3 changes: 3 additions & 0 deletions pyodide_build/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ def to_env(self) -> dict[str, str]:
"home": "HOME",
"path": "PATH",
"zip_compression_level": "PYODIDE_ZIP_COMPRESSION_LEVEL",
"skip_emscripten_version_check": "SKIP_EMSCRIPTEN_VERSION_CHECK",
# maintainer only
"_f2c_fixes_wrapper": "_F2C_FIXES_WRAPPER",
}
Expand All @@ -188,6 +189,7 @@ def to_env(self) -> dict[str, str]:
"ldflags",
"rust_toolchain",
"meson_cross_file",
"skip_emscripten_version_check",
# maintainer only
"_f2c_fixes_wrapper",
}
Expand All @@ -205,6 +207,7 @@ def to_env(self) -> dict[str, str]:
"rust_toolchain": "nightly-2024-01-29",
# Other configuration
"pyodide_jobs": "1",
"skip_emscripten_version_check": "0",
# maintainer only
"_f2c_fixes_wrapper": "",
}
Expand Down
16 changes: 16 additions & 0 deletions pyodide_build/tests/test_build_env.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,12 @@ def get_emscripten_version_info():
"""
build_env.check_emscripten_version()

s = f"""\
emcc (Emscripten gcc/clang-like replacement + linker emulating GNU ld) {build_env.emscripten_version()}-git
clang version 15.0.0 (https://github.com/llvm/llvm-project 7effcbda49ba32991b8955821b8fdbd4f8f303e2)
"""
build_env.check_emscripten_version()

def get_emscripten_version_info(): # type: ignore[no-redef]
raise FileNotFoundError()

Expand All @@ -179,6 +185,16 @@ def get_emscripten_version_info(): # type: ignore[no-redef]
build_env.check_emscripten_version()


def test_check_emscripten_version_skip(dummy_xbuildenv, monkeypatch, reset_cache):
with pytest.raises(RuntimeError):
monkeypatch.setenv("SKIP_EMSCRIPTEN_VERSION_CHECK", "0")
build_env.check_emscripten_version()

reset_cache()
monkeypatch.setenv("SKIP_EMSCRIPTEN_VERSION_CHECK", "1")
build_env.check_emscripten_version()


def test_wheel_paths(dummy_xbuildenv):
from pathlib import Path

Expand Down
Loading