Skip to content

Commit

Permalink
Merge pull request #353 from davidhewitt/workspace-error
Browse files Browse the repository at this point in the history
better error when accidentally targeting a workspace root
  • Loading branch information
davidhewitt authored Aug 11, 2023
2 parents 4c85178 + e3b242d commit 7785db8
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 10 deletions.
23 changes: 14 additions & 9 deletions setuptools_rust/build.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from __future__ import annotations

import glob
import json
import os
import platform
Expand All @@ -17,10 +16,9 @@
)
from sysconfig import get_config_var
from pathlib import Path
from typing import Dict, Iterable, List, NamedTuple, Optional, Set, Tuple, cast
from typing import Dict, List, NamedTuple, Optional, Set, Tuple, cast

import pkg_resources
from semantic_version import Version
from setuptools.command.build import build as CommandBuild
from setuptools.command.build_ext import build_ext as CommandBuildExt
from setuptools.command.build_ext import get_abi3_suffix
Expand All @@ -31,7 +29,6 @@
from .extension import Binding, RustBin, RustExtension, Strip
from .rustc_info import (
get_rust_host,
get_rust_target_list,
get_rust_version,
get_rustc_cfgs,
)
Expand Down Expand Up @@ -155,12 +152,21 @@ def build_extension(
env = _prepare_build_environment()

if not os.path.exists(ext.path):
raise FileError(f"can't find Rust extension project file: {ext.path}")
raise FileError(
f"can't find manifest for Rust extension `{ext.name}` at path `{ext.path}`"
)

quiet = self.qbuild or ext.quiet
debug = self._is_debug_build(ext)
use_cargo_crate_type = _check_cargo_supports_crate_type_option()

package_id = ext.metadata(quiet=quiet)["resolve"]["root"]
if package_id is None:
raise FileError(
f"manifest for Rust extention `{ext.name}` at path `{ext.path}` is a virtual manifest (a workspace root without a package).\n\n"
"If you intended to build for a workspace member, set `path` for the extension to the member's Cargo.toml file."
)

cargo_args = self._cargo_args(
ext=ext, target_triple=target_triple, release=not debug, quiet=quiet
)
Expand Down Expand Up @@ -212,7 +218,7 @@ def build_extension(
"wasm32",
"emscripten",
):
rustc_args.extend(["-C", f"link-args=-sSIDE_MODULE=2 -sWASM_BIGINT"])
rustc_args.extend(["-C", "link-args=-sSIDE_MODULE=2 -sWASM_BIGINT"])

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

dylib_paths = []
package_id = ext.metadata(quiet=quiet)["resolve"]["root"]

if ext._uses_exec_binding():
# Find artifact from cargo messages
Expand Down Expand Up @@ -396,7 +401,7 @@ def install_extension(
args.insert(0, "strip")
args.append(ext_path)
try:
output = subprocess.check_output(args)
subprocess.check_output(args)
except subprocess.CalledProcessError:
pass

Expand Down Expand Up @@ -643,7 +648,7 @@ def _binding_features(
python_version = py_limited_api[2:]
features.add(f"pyo3/abi3-py{python_version}")
elif py_limited_api:
features.add(f"pyo3/abi3")
features.add("pyo3/abi3")
return features
elif ext.binding is Binding.RustCPython:
return {"cpython/python3-sys", "cpython/extension-module"}
Expand Down
2 changes: 1 addition & 1 deletion setuptools_rust/clean.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,5 @@ def run_for_extension(self, ext: RustExtension) -> None:
# Execute cargo command
try:
subprocess.check_output(args)
except:
except Exception:
pass

0 comments on commit 7785db8

Please sign in to comment.