• Home
  • Raw
  • Download

Lines Matching +full:build +full:- +full:with +full:- +full:python

2 """Build script for Python on WebAssembly platforms.
4 $ ./Tools/wasm/wasm_builder.py emscripten-browser build repl
5 $ ./Tools/wasm/wasm_builder.py emscripten-node-dl build test
6 $ ./Tools/wasm/wasm_builder.py wasi build test
8 Primary build targets are "emscripten-node-dl" (NodeJS, dynamic linking),
9 "emscripten-browser", and "wasi".
16 and falls back to /opt/wasi-sdk.
18 The 'build' Python interpreter must be rebuilt every time Python's byte code
21 ./Tools/wasm/wasm_builder.py --clean build build
42 # for Python 3.8
55 # path to WASI-SDK root
56 WASI_SDK_PATH = pathlib.Path(os.environ.get("WASI_SDK_PATH", "/opt/wasi-sdk"))
59 # auto-detect's EMSDK in /opt/emsdk without ". emsdk_env.sh".
63 (3, 1, 14): "https://github.com/emscripten-core/emscripten/issues/17338",
64 (3, 1, 16): "https://github.com/emscripten-core/emscripten/issues/17393",
65 (3, 1, 20): "https://github.com/emscripten-core/emscripten/issues/17720",
73 run "make clean -C '{SRCDIR}'".
77 Builds require a C compiler (gcc, clang), make, pkg-config, and development
80 Debian/Ubuntu: sudo apt install build-essential git curl pkg-config zlib1g-dev
81 Fedora/CentOS: sudo dnf install gcc make git-core curl pkgconfig zlib-devel
85 wasm32-emscripten builds need Emscripten SDK. Please follow instructions at
87 Emscripten and how to activate the SDK with "emsdk_env.sh".
89 git clone https://github.com/emscripten-core/emsdk.git /path/to/emsdk
97 wasm32-wasi builds need WASI SDK. Please fetch the latest SDK from
98 https://github.com/WebAssembly/wasi-sdk/releases and install it to
99 "/opt/wasi-sdk". Alternatively you can install the SDK in a different location
105 wasm32-wasi tests require wasmtime on PATH. Please follow instructions at
112 ) -> Tuple[pathlib.PurePath, pathlib.PurePath]:
115 The ".emscripten" config file is a Python snippet that uses "EM_CONFIG"
117 subdirectory with tools like "emconfigure".
121 with open(emconfig, encoding="utf-8") as f:
123 # EM_CONFIG file is a Python snippet
134 def read_python_version(configure: pathlib.Path = CONFIGURE) -> str:
141 with configure.open(encoding="utf-8") as f:
171 """Platform-specific settings
173 - CONFIG_SITE override
174 - configure wrapper (e.g. emconfigure)
175 - make wrapper (e.g. emmake)
176 - additional environment variables
177 - check function to verify SDK
191 def getenv(self, profile: "BuildProfile") -> dict:
197 SRCDIR / "Programs" / "python.o",
198 SRCDIR / "Python" / "frozen_modules" / "importlib._bootstrap.h",
211 # skip pkg-config check on macOS
212 if not shutil.which("pkg-config"):
213 raise MissingDependency("pkg-config", INSTALL_NATIVE)
217 subprocess.check_call(["pkg-config", "--exists", devel])
225 # macOS has python.exe
226 pythonexe=sysconfig.get_config_var("BUILDPYTHON") or "python",
245 version_txt = EMSCRIPTEN_ROOT / "emscripten-version.txt"
248 with open(version_txt) as f:
250 if version.endswith("-git"):
251 # git / upstream / tot-upstream installation
252 version = version[:-4]
280 pythonexe="python.js",
281 config_site=WASMTOOLS / "config.site-wasm32-emscripten",
287 # workaround for https://github.com/emscripten-core/emscripten/issues/17635
297 wasm_ld = WASI_SDK_PATH / "bin" / "wasm-ld"
308 pythonexe="python.wasm",
309 config_site=WASMTOOLS / "config.site-wasm32-wasi",
310 configure_wrapper=WASMTOOLS / "wasi-env",
316 # workaround for https://github.com/python/cpython/issues/95952
319 "--env PYTHONPATH=/{relbuilddir}/build/lib.wasi-wasm32-{version}:/Lib "
320 "--mapdir /::{srcdir} --"
331 wasm32_emscripten = "wasm32-unknown-emscripten"
332 wasm64_emscripten = "wasm64-unknown-emscripten"
333 wasm32_wasi = "wasm32-unknown-wasi"
334 wasm64_wasi = "wasm64-unknown-wasi"
336 build = sysconfig.get_config_var("BUILD_GNU_TYPE") variable in Host
339 def platform(self) -> Platform:
348 def is_emscripten(self) -> bool:
353 def is_wasi(self) -> bool:
357 def get_extra_paths(self) -> Iterable[pathlib.PurePath]:
358 """Host-specific os.environ["PATH"] entries.
360 Emscripten's Node version 14.x works well for wasm32-emscripten.
361 wasm64-emscripten requires more recent v8 version, e.g. node 16.x.
374 def emport_args(self) -> List[str]:
375 """Host-specific port args (Emscripten)."""
378 return ["-sMEMORY64=1"]
380 return ["-sMEMORY64=0"]
385 def embuilder_args(self) -> List[str]:
386 """Host-specific embuilder args (Emscripten)."""
389 return ["--wasm64"]
395 """Emscripten-specific targets (--with-emscripten-target)"""
398 browser_debug = "browser-debug"
400 node_debug = "node-debug"
408 def emport_args(self) -> List[str]:
409 """Target-specific port args."""
412 # some libs come in debug and non-debug builds
413 return ["-O0"]
415 return ["-O2"]
437 default_testopts: str = "-j2"
440 def is_browser(self) -> bool:
441 """Is this a browser build?"""
445 def builddir(self) -> pathlib.Path:
446 """Path to build directory"""
450 def python_cmd(self) -> pathlib.Path:
451 """Path to python executable"""
455 def makefile(self) -> pathlib.Path:
460 def configure_cmd(self) -> List[str]:
465 cmd = [configure, "-C"]
470 cmd.append(f"--host={self.host.value}")
471 cmd.append(f"--build={Host.build.value}")
475 cmd.append(f"--with-emscripten-target={self.target.value}")
480 cmd.append(f"--{opt}-wasm-dynamic-linking")
485 cmd.append(f"--{opt}-wasm-pthreads")
487 if self.host != Host.build:
488 cmd.append(f"--with-build-python={BUILD.python_cmd}")
496 def make_cmd(self) -> List[str]:
504 def getenv(self) -> dict:
507 env.setdefault("MAKEFLAGS", f"-j{os.cpu_count()}")
513 # list of path items, prefix with extra paths
562 """Run make (defaults to build all)"""
578 """Run Python with hostrunner"""
581 "--eval", f"run: all; $(HOSTRUNNER) ./$(PYTHON) {shlex.join(args)}", "run"
585 """Run WASM webserver and open build in browser"""
587 url = f"http://{bind}:{port}/{relbuilddir}/python.html"
591 "--bind",
593 "--port",
601 with socket.create_connection((bind, port), timeout=0.1) as s:
616 """Clean build directory"""
624 """Pre-build emscripten ports."""
632 embuilder_cmd.append("--force")
640 # Trigger PIC build.
641 ports_cmd.append("-sMAIN_MODULE")
642 embuilder_cmd.append("--pic")
645 # Trigger multi-threaded build.
646 ports_cmd.append("-sUSE_PTHREADS")
648 # Pre-build libbz2, libsqlite3, libz, and some system libs.
649 ports_cmd.extend(["-sUSE_ZLIB", "-sUSE_BZIP2", "-sUSE_SQLITE3"])
650 # Multi-threaded sqlite3 has different suffix
652 ["build", "bzip2", "sqlite3-mt" if self.pthreads else "sqlite3", "zlib"]
657 with tempfile.TemporaryDirectory(suffix="-py-emport") as tmpdir:
661 with main_c.open("w") as f:
665 "-o",
671 # native build (build Python)
672 BUILD = BuildProfile( variable
673 "build",
675 host=Host.build,
679 BUILD,
680 # wasm32-emscripten
682 "emscripten-browser",
689 "emscripten-browser-debug",
696 "emscripten-node-dl",
703 "emscripten-node-dl-debug",
710 "emscripten-node-pthreads",
717 "emscripten-node-pthreads-debug",
723 # Emscripten build with both pthreads and dynamic linking is crashing.
725 "emscripten-node-dl-pthreads-debug",
732 # wasm64-emscripten (requires Emscripten >= 3.1.21)
734 "wasm64-emscripten-node-debug",
738 # MEMORY64 is not compatible with dynamic linking
742 # wasm32-wasi
750 # "wasm64-wasi",
765 "--clean",
766 "-c",
767 help="Clean build directories first",
772 "--verbose",
773 "-v",
779 "--silent",
785 "--testopts",
788 "--testopts='-v test_os'."
799 help=f"Build platform: {', '.join(platforms_help)}",
804 build="auto build (build 'build' Python, emports, configure, compile)",
812 cleanall="remove all build directories",
813 emports="build Emscripten port with embuilder (only Emscripten)",
819 help=f"operation (default: build)\n\n{ops_help}",
821 default="build",
839 cm_args = ("--silent",) if args.silent else ()
841 # nargs=* with default quirk
842 if args.ops == "build":
843 args.ops = ["build"]
858 # auto-build
859 if "build" in args.ops:
860 # check and create build Python
861 if builder is not BUILD:
862 logger.info("Auto-building 'build' Python.")
864 BUILD.host.platform.check()
868 BUILD.clean(all=False)
869 BUILD.run_build(*cm_args)
870 # build Emscripten ports with embuilder
876 if op == "build":