Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
9 changes: 8 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,13 @@ jobs:
run: PATH="$PATH:/c/Users/runneradmin/.cargo/bin" nox -s test-examples

test-emscripten:
name: emscripten (${{ matrix.rust-version }} Rust)
strategy:
fail-fast: true
matrix:
rust-version: [stable, nightly]
runs-on: ubuntu-latest
continue-on-error: ${{ matrix.rust-version == 'nightly' }}
steps:
- uses: actions/checkout@v6
- uses: astral-sh/setup-uv@v7
Expand All @@ -433,8 +439,9 @@ jobs:
- run: |
uvx nox -s install-pyodide-emscripten
echo "ORIG_PATH=$PATH" >> $GITHUB_ENV
- uses: dtolnay/rust-toolchain@nightly
- uses: dtolnay/rust-toolchain@master
with:
toolchain: ${{ matrix.rust-version }}
components: rust-src
targets: wasm32-unknown-emscripten
- uses: mymindstorm/setup-emsdk@v14
Expand Down
18 changes: 4 additions & 14 deletions noxfile.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import os
from contextlib import ExitStack
from inspect import cleandoc as heredoc
from glob import glob
from pathlib import Path
import shutil
import sys
import tempfile
from contextlib import ExitStack
from glob import glob
from inspect import cleandoc as heredoc
from pathlib import Path

import nox
import nox.command
Expand Down Expand Up @@ -264,15 +264,6 @@ def install_pyodide_emscripten(session: nox.Session):
def test_examples_emscripten(session: nox.Session):
session.install(".", "build")

session.run(
"rustup",
"component",
"add",
"rust-src",
"--toolchain",
"nightly",
external=True,
)
examples_dir = Path("examples").absolute()
test_crates = [
examples_dir / "html-py-ever",
Expand All @@ -297,7 +288,6 @@ def test_examples_emscripten(session: nox.Session):
for example in test_crates:
env = os.environ.copy()
env.update(
RUSTUP_TOOLCHAIN="nightly",
PYTHONPATH=str(EMSCRIPTEN_DIR),
_PYTHON_SYSCONFIGDATA_NAME="_sysconfigdata__emscripten_wasm32-emscripten",
_PYTHON_HOST_PLATFORM=f"emscripten_{emscripten_version_joined}_wasm32",
Expand Down
42 changes: 28 additions & 14 deletions setuptools_rust/build.py
Original file line number Diff line number Diff line change
@@ -1,30 +1,30 @@
from __future__ import annotations

import json
import logging
import os
import platform
import shutil
import subprocess
import sys
import sysconfig
import logging
import warnings
from setuptools.errors import (
CompileError,
ExecError,
FileError,
PlatformError,
)
from sysconfig import get_config_var
from pathlib import Path
from sysconfig import get_config_var
from typing import Dict, List, Literal, NamedTuple, Optional, Set, Tuple, cast

from setuptools import Distribution
from setuptools.command.build_ext import build_ext as CommandBuildExt
from setuptools.command.build_ext import get_abi3_suffix
from setuptools.command.install_scripts import install_scripts as CommandInstallScripts
from setuptools.errors import (
CompileError,
ExecError,
FileError,
PlatformError,
)

from ._utils import check_subprocess_output, format_called_process_error, Env
from ._utils import Env, check_subprocess_output, format_called_process_error
from .command import RustCommand
from .extension import Binding, RustBin, RustExtension, Strip
from .rustc_info import (
Expand All @@ -40,7 +40,9 @@
from setuptools.command.bdist_wheel import bdist_wheel as CommandBdistWheel
except ImportError: # old version of setuptools
try:
from wheel.bdist_wheel import bdist_wheel as CommandBdistWheel # type: ignore[no-redef]
from wheel.bdist_wheel import (
bdist_wheel as CommandBdistWheel, # type: ignore[no-redef]
)
except ImportError:
from setuptools import Command as CommandBdistWheel # type: ignore[assignment]

Expand All @@ -54,6 +56,16 @@ def _check_cargo_supports_crate_type_option(env: Optional[Env]) -> bool:
return version.major > 1 or (version.major == 1 and version.minor >= 64) # type: ignore


def _rustc_passes_side_module_automatically(env: Optional[Env]) -> bool:
version = get_rust_version(env)

if version is None:
return False

# Rust 1.95.0 and above automatically pass `-C link-args=-sSIDE_MODULE=2` for wasm32-emscripten targets when building cdylibs
return version.major > 1 or (version.major == 1 and version.minor >= 95) # type: ignore


class build_rust(RustCommand):
"""Command for building Rust crates via cargo."""

Expand Down Expand Up @@ -212,11 +224,13 @@ def build_extension(
# the cdylib, see https://github.com/rust-lang/cargo/issues/10143
rustflags.append("-Ctarget-feature=-crt-static")

elif (rustc_cfgs.get("target_arch"), rustc_cfgs.get("target_os")) == (
"wasm32",
"emscripten",
elif (
rustc_cfgs.get("target_arch") == "wasm32"
and rustc_cfgs.get("target_os") == "emscripten"
):
rustc_args.extend(["-C", "link-args=-sSIDE_MODULE=2 -sWASM_BIGINT"])
rustc_args.extend(["-C", "symbol-mangling-version=v0"])
if not _rustc_passes_side_module_automatically(ext.env):
rustc_args.extend(["-C", "link-args=-sSIDE_MODULE=2"])

if use_cargo_crate_type and "--crate-type" not in cargo_args:
cargo_args.extend(["--crate-type", "cdylib"])
Expand Down
Loading