Skip to content

Commit 7785db8

Browse files
authored
Merge pull request #353 from davidhewitt/workspace-error
better error when accidentally targeting a workspace root
2 parents 4c85178 + e3b242d commit 7785db8

File tree

2 files changed

+15
-10
lines changed

2 files changed

+15
-10
lines changed

setuptools_rust/build.py

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
from __future__ import annotations
22

3-
import glob
43
import json
54
import os
65
import platform
@@ -17,10 +16,9 @@
1716
)
1817
from sysconfig import get_config_var
1918
from pathlib import Path
20-
from typing import Dict, Iterable, List, NamedTuple, Optional, Set, Tuple, cast
19+
from typing import Dict, List, NamedTuple, Optional, Set, Tuple, cast
2120

2221
import pkg_resources
23-
from semantic_version import Version
2422
from setuptools.command.build import build as CommandBuild
2523
from setuptools.command.build_ext import build_ext as CommandBuildExt
2624
from setuptools.command.build_ext import get_abi3_suffix
@@ -31,7 +29,6 @@
3129
from .extension import Binding, RustBin, RustExtension, Strip
3230
from .rustc_info import (
3331
get_rust_host,
34-
get_rust_target_list,
3532
get_rust_version,
3633
get_rustc_cfgs,
3734
)
@@ -155,12 +152,21 @@ def build_extension(
155152
env = _prepare_build_environment()
156153

157154
if not os.path.exists(ext.path):
158-
raise FileError(f"can't find Rust extension project file: {ext.path}")
155+
raise FileError(
156+
f"can't find manifest for Rust extension `{ext.name}` at path `{ext.path}`"
157+
)
159158

160159
quiet = self.qbuild or ext.quiet
161160
debug = self._is_debug_build(ext)
162161
use_cargo_crate_type = _check_cargo_supports_crate_type_option()
163162

163+
package_id = ext.metadata(quiet=quiet)["resolve"]["root"]
164+
if package_id is None:
165+
raise FileError(
166+
f"manifest for Rust extention `{ext.name}` at path `{ext.path}` is a virtual manifest (a workspace root without a package).\n\n"
167+
"If you intended to build for a workspace member, set `path` for the extension to the member's Cargo.toml file."
168+
)
169+
164170
cargo_args = self._cargo_args(
165171
ext=ext, target_triple=target_triple, release=not debug, quiet=quiet
166172
)
@@ -212,7 +218,7 @@ def build_extension(
212218
"wasm32",
213219
"emscripten",
214220
):
215-
rustc_args.extend(["-C", f"link-args=-sSIDE_MODULE=2 -sWASM_BIGINT"])
221+
rustc_args.extend(["-C", "link-args=-sSIDE_MODULE=2 -sWASM_BIGINT"])
216222

217223
if use_cargo_crate_type and "--crate-type" not in cargo_args:
218224
cargo_args.extend(["--crate-type", "cdylib"])
@@ -269,7 +275,6 @@ def build_extension(
269275
# it into the build directory as if it were produced by build_ext.
270276

271277
dylib_paths = []
272-
package_id = ext.metadata(quiet=quiet)["resolve"]["root"]
273278

274279
if ext._uses_exec_binding():
275280
# Find artifact from cargo messages
@@ -396,7 +401,7 @@ def install_extension(
396401
args.insert(0, "strip")
397402
args.append(ext_path)
398403
try:
399-
output = subprocess.check_output(args)
404+
subprocess.check_output(args)
400405
except subprocess.CalledProcessError:
401406
pass
402407

@@ -643,7 +648,7 @@ def _binding_features(
643648
python_version = py_limited_api[2:]
644649
features.add(f"pyo3/abi3-py{python_version}")
645650
elif py_limited_api:
646-
features.add(f"pyo3/abi3")
651+
features.add("pyo3/abi3")
647652
return features
648653
elif ext.binding is Binding.RustCPython:
649654
return {"cpython/python3-sys", "cpython/extension-module"}

setuptools_rust/clean.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,5 +26,5 @@ def run_for_extension(self, ext: RustExtension) -> None:
2626
# Execute cargo command
2727
try:
2828
subprocess.check_output(args)
29-
except:
29+
except Exception:
3030
pass

0 commit comments

Comments
 (0)