Skip to content

Commit

Permalink
Save symlinks directory when building with recipe builder (#96)
Browse files Browse the repository at this point in the history
Instead of putting the symlinks directory in a temp directory and
deleting after the build is finished, put it under the build directory.
This makes reproducing compile errors much easier, and the `build`
directory is already just scratch files.
  • Loading branch information
hoodmane authored Jan 30, 2025
1 parent dcdf3da commit 742dde8
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 5 deletions.
23 changes: 19 additions & 4 deletions pyodide_build/pypabuild.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,23 @@ def make_command_wrapper_symlinks(symlink_dir: Path) -> dict[str, str]:
return env


@contextmanager
def _create_symlink_dir(env: dict[str, str], build_dir: Path | None):
if build_dir:
# If we're running under build-recipes, leave the symlinks in
# the build directory. This helps with reproducing.
symlink_dir = build_dir / "pywasmcross_symlinks"
shutil.rmtree(symlink_dir, ignore_errors=True)
symlink_dir.mkdir()
yield symlink_dir
return

# Running from "pyodide build". Put symlinks in a temporary directory.
# TODO: Add a debug option to save the symlinks.
with TemporaryDirectory() as symlink_dir_str:
yield Path(symlink_dir_str)


@contextmanager
def get_build_env(
env: dict[str, str],
Expand All @@ -252,6 +269,7 @@ def get_build_env(
ldflags: str,
target_install_dir: str,
exports: _BuildSpecExports,
build_dir: Path | None = None,
) -> Iterator[dict[str, str]]:
"""
Returns a dict of environment variables that should be used when building
Expand All @@ -267,14 +285,11 @@ def get_build_env(
}

args = common.environment_substitute_args(kwargs, env)
args["builddir"] = str(Path(".").absolute())
args["exports"] = exports
env = env.copy()

with TemporaryDirectory() as symlink_dir_str:
symlink_dir = Path(symlink_dir_str)
with _create_symlink_dir(env, build_dir) as symlink_dir:
env.update(make_command_wrapper_symlinks(symlink_dir))

sysconfig_dir = Path(get_build_flag("TARGETINSTALLDIR")) / "sysconfigdata"
args["PYTHONPATH"] = sys.path + [str(symlink_dir), str(sysconfig_dir)]
args["orig__name__"] = __name__
Expand Down
1 change: 1 addition & 0 deletions pyodide_build/recipe/builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,7 @@ def _compile(
ldflags=ldflags,
target_install_dir=self.build_args.target_install_dir,
exports=self.build_metadata.exports,
build_dir=self.build_dir,
)
config_settings = pypabuild.parse_backend_flags(
self.build_metadata.backend_flags
Expand Down
1 change: 0 additions & 1 deletion pyodide_build/tests/test_pypabuild.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,4 +95,3 @@ def test_get_build_env(tmp_path, dummy_xbuildenv):
assert "cxxflags" in wasmcross_args
assert "ldflags" in wasmcross_args
assert "exports" in wasmcross_args
assert "builddir" in wasmcross_args

0 comments on commit 742dde8

Please sign in to comment.