-
-
Notifications
You must be signed in to change notification settings - Fork 815
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
Finish out of tree build system (except xbuildenv deploy) #2823
Changes from all commits
f3ab3d2
480d7cc
f4eebdf
f1c10bd
1566861
0055269
5c65533
2cb47b3
e4c30a3
0f68b04
4996fe5
1d59947
66e37ce
02cf02c
109c89d
e7ffd7e
9811c7d
d93690c
9229d5b
3371a0d
9f1a6b7
1c1bd37
abd658a
d4e7f88
8ae3acb
5f4042c
49d5d5f
4b4da1b
8fed837
6e163a2
cb8a022
9f32585
d5328b9
7a0c0b4
1fa76e9
c261ad5
84b37ce
8d8ccd2
9f1084b
6e4566b
b5f6b87
fa0f5ea
1043040
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,12 +15,27 @@ def make_parser(parser: argparse.ArgumentParser) -> argparse.ArgumentParser: | |
"on numpy or scipy.\n" | ||
"Note: this is a private endpoint that should not be used outside of the Pyodide Makefile." | ||
) | ||
parser.add_argument("--download", action="store_true", help="Download xbuild env") | ||
parser.add_argument("xbuild_env", type=str, nargs=1) | ||
return parser | ||
|
||
|
||
def main(args: argparse.Namespace) -> None: | ||
xbuildenv_path = Path(args.xbuild_env[0]) | ||
def download_xbuild_env(version: str, xbuildenv_path: Path) -> None: | ||
from shutil import rmtree, unpack_archive | ||
from tempfile import NamedTemporaryFile | ||
from urllib.request import urlretrieve | ||
|
||
rmtree(xbuildenv_path, ignore_errors=True) | ||
with NamedTemporaryFile(suffix=".tar") as f: | ||
urlretrieve( | ||
f"http://pyodide-cache.s3-website-us-east-1.amazonaws.com/xbuildenv/{version}.tar", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this your personal S3 bucket? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Roman set it up. We could use it for other things too. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, as long as it remains a bit of dev oriented cache and we make no quality of service promises, I think it should be OK. Eventually, this could probably be also done with github releases though that's harder for nightly deployments. Also if you can make it a .tar.gz to reduce the bandwidth that would be better. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also is there anything platform/OS dependent in this tar? For instance, I see a,
is this intentional? Should we add the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's not linux specific, it's an Emscripten static library.
I was thinking about naming them by version e.g., |
||
f.name, | ||
) | ||
unpack_archive(f.name, xbuildenv_path) | ||
|
||
|
||
def install_xbuild_env(xbuildenv_path: Path) -> None: | ||
xbuildenv_path = xbuildenv_path / "xbuildenv" | ||
pyodide_root = get_pyodide_root() | ||
xbuildenv_root = xbuildenv_path / "pyodide-root" | ||
host_site_packages = xbuildenv_root / Path( | ||
|
@@ -42,3 +57,11 @@ def main(args: argparse.Namespace) -> None: | |
shutil.copytree( | ||
xbuildenv_path / "site-packages-extras", host_site_packages, dirs_exist_ok=True | ||
) | ||
|
||
|
||
def main(args: argparse.Namespace) -> None: | ||
xbuildenv_path = Path(args.xbuild_env[0]) | ||
version = "2" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What is your future plan of versioning build envs? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. One version per Pyodide release. After we merge this I am planning to add a CI job to deploy the cross build environment as part of deploy-release. It would also be nice to periodically deploy a "nightly" build at some point. Maybe once a month or once every other week or something. |
||
if args.download: | ||
download_xbuild_env(version, xbuildenv_path) | ||
install_xbuild_env(xbuildenv_path) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import argparse | ||
import os | ||
from pathlib import Path | ||
|
||
from . import build | ||
|
||
|
||
def ensure_env_installed(env: Path) -> None: | ||
if env.exists(): | ||
return | ||
from ..install_xbuildenv import download_xbuild_env, install_xbuild_env | ||
|
||
version = "2" | ||
download_xbuild_env(version, env) | ||
install_xbuild_env(env) | ||
|
||
|
||
def main(): | ||
main_parser = argparse.ArgumentParser(prog="pywasmbuild") | ||
main_parser.description = "Tools for creating Python extension modules for the wasm32-unknown-emscripten platform" | ||
subparsers = main_parser.add_subparsers(help="action") | ||
for module in [build]: | ||
modname = module.__name__.rpartition(".")[-1] | ||
parser = module.make_parser(subparsers.add_parser(modname)) | ||
parser.set_defaults(func=module.main) | ||
|
||
env = Path(".pyodide-xbuildenv") | ||
os.environ["PYODIDE_ROOT"] = str(env / "xbuildenv/pyodide-root") | ||
ensure_env_installed(env) | ||
|
||
args = main_parser.parse_args() | ||
if hasattr(args, "func"): | ||
# run the selected action | ||
args.func(args) | ||
else: | ||
main_parser.print_help() |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import argparse | ||
import os | ||
|
||
from .. import common, pypabuild, pywasmcross | ||
|
||
|
||
def run(exports, args): | ||
cflags = common.get_make_flag("SIDE_MODULE_CFLAGS") | ||
cflags += f" {os.environ.get('CFLAGS', '')}" | ||
cxxflags = common.get_make_flag("SIDE_MODULE_CXXFLAGS") | ||
cxxflags += f" {os.environ.get('CXXFLAGS', '')}" | ||
ldflags = common.get_make_flag("SIDE_MODULE_LDFLAGS") | ||
ldflags += f" {os.environ.get('LDFLAGS', '')}" | ||
build_env_ctx = pywasmcross.get_build_env( | ||
env=os.environ.copy(), | ||
pkgname="", | ||
cflags=cflags, | ||
cxxflags=cxxflags, | ||
ldflags=ldflags, | ||
target_install_dir="", | ||
exports=exports, | ||
) | ||
|
||
with build_env_ctx as env: | ||
pypabuild.build(env, " ".join(args)) | ||
|
||
|
||
def main(parser_args: argparse.Namespace) -> None: | ||
run(parser_args.exports, parser_args.backend_args) | ||
|
||
|
||
def make_parser(parser: argparse.ArgumentParser) -> argparse.ArgumentParser: | ||
parser.description = "Use pypa/build to build a Python package." | ||
parser.add_argument( | ||
"--exports", | ||
choices=["pyinit", "requested", "whole_archive"], | ||
default="requested", | ||
help="Which symbols should be exported when linking .so files?", | ||
) | ||
parser.add_argument( | ||
"backend_args", | ||
metavar="args", | ||
type=str, | ||
nargs=argparse.REMAINDER, | ||
help="Arguments to pass on to the backend", | ||
) | ||
return parser |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,7 @@ | |
setuptools.setup( | ||
entry_points={ | ||
"console_scripts": [ | ||
"pywasm = pyodide_build.out_of_tree.__main__:main", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's a bit confusing with https://github.com/mohanson/pywasm So I guess it would be a bit difficult to use subcommands here. Sill maybe something like There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Although if you are calling it as Maybe we should just call this command There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The main distinction in my mind is between in-tree and out-of-tree commands. E.g., |
||
"_pywasmcross = pyodide_build.pywasmcross:compiler_main", | ||
] | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This call will fail if we haven't installed the xbuildenv yet.