• Home
  • Raw
  • Download

Lines Matching +full:build +full:- +full:args

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
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
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]:
121 with open(emconfig, encoding="utf-8") as f:
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:
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])
245 version_txt = EMSCRIPTEN_ROOT / "emscripten-version.txt"
250 if version.endswith("-git"):
251 # git / upstream / tot-upstream installation
252 version = version[:-4]
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"
309 config_site=WASMTOOLS / "config.site-wasm32-wasi",
310 configure_wrapper=WASMTOOLS / "wasi-env",
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:
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()}")
531 args: Iterable[str] = (),
535 cmd.extend(args)
549 def run_build(self, *args): argument
553 self.run_configure(*args)
554 self.run_make("all", *args)
556 def run_configure(self, *args): argument
559 return self._run_cmd(self.configure_cmd, args)
561 def run_make(self, *args): argument
562 """Run make (defaults to build all)"""
563 return self._run_cmd(self.make_cmd, args)
565 def run_pythoninfo(self, *args): argument
568 return self.run_make("pythoninfo", *args)
577 def run_py(self, *args): argument
581 "--eval", f"run: all; $(HOSTRUNNER) ./$(PYTHON) {shlex.join(args)}", "run"
585 """Run WASM webserver and open build in browser"""
588 args = [
591 "--bind",
593 "--port",
596 srv = subprocess.Popen(args, cwd=SRCDIR)
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:
663 args = [
665 "-o",
668 self._run_cmd(ports_cmd, args, cwd=tmppath)
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",
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",
827 args = parser.parse_args()
829 level=logging.INFO if args.verbose else logging.ERROR,
833 if args.platform == "cleanall":
838 # additional configure and make args
839 cm_args = ("--silent",) if args.silent else ()
842 if args.ops == "build":
843 args.ops = ["build"]
845 builder = PROFILES[args.platform]
851 if args.clean:
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()
867 if args.clean:
868 BUILD.clean(all=False)
869 BUILD.run_build(*cm_args)
870 # build Emscripten ports with embuilder
871 if builder.host.is_emscripten and "emports" not in args.ops:
874 for op in args.ops:
875 logger.info("\n*** %s %s", args.platform, op)
876 if op == "build":
890 builder.run_test("buildbottest", testopts=args.testopts)
892 builder.run_test("hostrunnertest", testopts=args.testopts)
898 builder.build_emports(force=args.clean)