Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
gh-127629: Add ctypes to the Emscripten build
  • Loading branch information
hoodmane committed Dec 6, 2024
commit d9b6e9bbf32110c38c6f2274079474ec495474bf
31 changes: 29 additions & 2 deletions Tools/wasm/emscripten/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,26 @@ def make_build_python(context, working_dir):
print(f"🎉 {binary} {version}")


@subdir(HOST_DIR, clean_ok=True)
def make_emscripten_libffi(context, working_dir):
shutil.rmtree(HOST_DIR/"libffi", ignore_errors=True)

call([
"git",
"clone",
"https://github.com/libffi/libffi",
Comment thread
hoodmane marked this conversation as resolved.
Outdated
"--depth=1"
],
quiet=context.quiet,
)
call(
[EMSCRIPTEN_DIR / "make_libffi.sh"],
env=updated_env({"PREFIX": HOST_DIR}),
cwd=HOST_DIR/"libffi",
quiet=context.quiet,
Comment thread
hoodmane marked this conversation as resolved.
)


@subdir(HOST_DIR, clean_ok=True)
def configure_emscripten_python(context, working_dir):
"""Configure the emscripten/host build."""
Expand All @@ -183,12 +203,14 @@ def configure_emscripten_python(context, working_dir):
sysconfig_data += "-pydebug"

host_runner = context.host_runner
env_additions = {"CONFIG_SITE": config_site, "HOSTRUNNER": host_runner}
pkg_config_path_dir = (working_dir / "lib/pkgconfig/").resolve()
env_additions = {"CONFIG_SITE": config_site, "HOSTRUNNER": host_runner, "EM_PKG_CONFIG_PATH": str(pkg_config_path_dir)}
build_python = os.fsdecode(build_python_path())
configure = [
"emconfigure",
os.path.relpath(CHECKOUT / "configure", working_dir),
"CFLAGS=-DPY_CALL_TRAMPOLINE -sUSE_BZIP2",
'PKG_CONFIG=pkg-config',
f"--host={HOST_TRIPLE}",
f"--build={build_platform()}",
f"--with-build-python={build_python}",
Expand Down Expand Up @@ -264,6 +286,7 @@ def build_all(context):
steps = [
configure_build_python,
make_build_python,
make_emscripten_libffi,
configure_emscripten_python,
make_emscripten_python,
]
Expand Down Expand Up @@ -292,6 +315,9 @@ def main():
configure_build = subcommands.add_parser(
"configure-build-python", help="Run `configure` for the " "build Python"
)
make_libffi_cmd = subcommands.add_parser(
"make-libffi", help="Clone libffi repo, configure and build it for emscripten"
)
make_build = subcommands.add_parser(
"make-build-python", help="Run `make` for the build Python"
)
Expand All @@ -303,7 +329,7 @@ def main():
clean = subcommands.add_parser(
"clean", help="Delete files and directories created by this script"
)
for subcommand in build, configure_build, make_build, configure_host, make_host:
for subcommand in build, configure_build, make_libffi_cmd, make_build, configure_host, make_host:
subcommand.add_argument(
"--quiet",
action="store_true",
Expand Down Expand Up @@ -336,6 +362,7 @@ def main():
context = parser.parse_args()

dispatch = {
"make-libffi": make_emscripten_libffi,
Comment thread
hoodmane marked this conversation as resolved.
"configure-build-python": configure_build_python,
"make-build-python": make_build_python,
"configure-host": configure_emscripten_python,
Expand Down
22 changes: 22 additions & 0 deletions Tools/wasm/emscripten/make_libffi.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/bin/bash
set +e

export CFLAGS="-O2 -fPIC -DWASM_BIGINT"
export CXXFLAGS="$CFLAGS"

# Build paths
export CPATH="$PREFIX/include"
export PKG_CONFIG_PATH="$PREFIX/lib/pkgconfig"
export EM_PKG_CONFIG_PATH="$PKG_CONFIG_PATH"

# Specific variables for cross-compilation
export CHOST="wasm32-unknown-linux" # wasm32-unknown-emscripten
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why did this end up being wasm32-unknown-linux instead of wasm32-unknown-emscripten?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good question. Maybe I put it that way while debugging and didn't notice before merging.


autoreconf -fi
emconfigure ./configure --host=$CHOST --prefix="$PREFIX" --enable-static --disable-shared --disable-dependency-tracking \
--disable-builddir --disable-multi-os-directory --disable-raw-api --disable-docs

make install
# Some forgotten headers?
cp fficonfig.h $PREFIX/include/
cp include/ffi_common.h $PREFIX/include/