diff --git a/docs/new_packages.md b/docs/new_packages.md index d66f7e858..eacbea17e 100644 --- a/docs/new_packages.md +++ b/docs/new_packages.md @@ -143,6 +143,14 @@ Extra arguments to pass to the linker when building for WebAssembly. (This key is not in the Conda spec). +#### `build/library` + +Should be set to true for library packages. Library packages are packages that are needed for other packages but are not Python packages themselves. For library packages, the script specified in the `build/script` section is run to compile the library. See the [zlib meta.yaml](https://github.com/iodide-project/pyodide/blob/master/packages/zlib/meta.yaml) for an example of a library package specification. + +#### `build/script` + +The script section is required for a library package (`build/library` set to true). For a Python package this section is optional. If it is specified for a Python package, the script section will be run before the build system runs `setup.py`. This script is run by `bash` in the directory where the tarball was extracted. + #### `build/post` Shell commands to run after building the library. These are run inside of diff --git a/pyodide_build/buildpkg.py b/pyodide_build/buildpkg.py index 58f65e227..b9a1c378d 100755 --- a/pyodide_build/buildpkg.py +++ b/pyodide_build/buildpkg.py @@ -226,8 +226,10 @@ def run_script(buildpath: Path, srcpath: Path, pkg: Dict[str, Any]): finally: os.chdir(orig_path) - with open(buildpath / ".packaged", "wb") as fd: - fd.write(b"\n") + # If library, we're done so create .packaged file + if pkg["build"].get("library"): + with open(buildpath / ".packaged", "wb") as fd: + fd.write(b"\n") def needs_rebuild(pkg: Dict[str, Any], path: Path, buildpath: Path) -> bool: @@ -275,6 +277,8 @@ def build_package(path: Path, args): if pkg.get("build", {}).get("library"): run_script(buildpath, srcpath, pkg) else: + if pkg.get("build", {}).get("script"): + run_script(buildpath, srcpath, pkg) compile(path, srcpath, pkg, args) package_files(buildpath, srcpath, pkg, args) finally: diff --git a/pyodide_build/tests/test_buildpkg.py b/pyodide_build/tests/test_buildpkg.py index 276ad75c4..1159a5fa2 100644 --- a/pyodide_build/tests/test_buildpkg.py +++ b/pyodide_build/tests/test_buildpkg.py @@ -3,6 +3,8 @@ import subprocess from pathlib import Path +import pytest + from pyodide_build import buildpkg, common @@ -33,3 +35,17 @@ def test_download_and_extract(monkeypatch): srcpath = buildpkg.download_and_extract(buildpath, packagedir, pkg, args=None) assert srcpath.name.lower().endswith(packagedir.lower()) + + +@pytest.mark.parametrize("is_library", [True, False]) +def test_run_script(is_library, tmpdir): + build_dir = Path(tmpdir.mkdir("build")) + src_dir = Path(tmpdir.mkdir("build/package_name")) + script = "touch out.txt" + pkg = {"build": {"script": script, "library": is_library}} + buildpkg.run_script(build_dir, src_dir, pkg) + assert (src_dir / "out.txt").exists() + if is_library: + assert (build_dir / ".packaged").exists() + else: + assert not (build_dir / ".packaged").exists()