Skip to content

Commit f9c2bf0

Browse files
authored
doc: improve error message for missing Rust compiler (#117)
1 parent 8b35cc2 commit f9c2bf0

File tree

3 files changed

+32
-4
lines changed

3 files changed

+32
-4
lines changed

setuptools_rust/command.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,15 @@ def run(self):
2525

2626
all_optional = all(ext.optional for ext in self.extensions)
2727
try:
28-
version = get_rust_version()
28+
version = get_rust_version(
29+
min_version=max(
30+
filter(
31+
lambda version: version is not None,
32+
(ext.get_rust_version() for ext in self.extensions),
33+
),
34+
default=None
35+
)
36+
)
2937
except DistutilsPlatformError as e:
3038
if not all_optional:
3139
raise

setuptools_rust/extension.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ def get_rust_version(self):
123123
if self.rust_version is None:
124124
return None
125125
try:
126-
return semantic_version.Spec(self.rust_version)
126+
return semantic_version.SimpleSpec.parse(self.rust_version)
127127
except ValueError:
128128
raise DistutilsSetupError(
129129
"Can not parse rust compiler version: %s", self.rust_version

setuptools_rust/utils.py

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,12 +57,32 @@ def rust_features(ext=True, binding=Binding.PyO3):
5757
raise DistutilsPlatformError(f"unknown Rust binding: '{binding}'")
5858

5959

60-
def get_rust_version():
60+
def get_rust_version(min_version=None):
6161
try:
6262
output = subprocess.check_output(["rustc", "-V"]).decode("latin-1")
6363
return semantic_version.Version(output.split(" ")[1], partial=True)
6464
except (subprocess.CalledProcessError, OSError):
65-
raise DistutilsPlatformError("can't find Rust compiler")
65+
raise DistutilsPlatformError(
66+
"can't find Rust compiler\n\n"
67+
"If you are using an outdated pip version, it is possible a "
68+
"prebuilt wheel is available for this package but pip is not able "
69+
"to install from it. Installing from the wheel would avoid the "
70+
"need for a Rust compiler.\n\n"
71+
"To update pip, run:\n\n"
72+
" pip install --upgrade pip\n\n"
73+
"and then retry package installation.\n\n"
74+
"If you did intend to build this package from source, try "
75+
"installing a Rust compiler from your system package manager and "
76+
"ensure it is on the PATH during installation. Alternatively, "
77+
"rustup (available at https://rustup.rs) is the recommended way "
78+
"to download and update the Rust compiler toolchain."
79+
+ (
80+
81+
f"\n\nThis package requires Rust {min_version}."
82+
if min_version is not None
83+
else ""
84+
)
85+
)
6686
except Exception as exc:
6787
raise DistutilsPlatformError(f"can't get rustc version: {str(exc)}")
6888

0 commit comments

Comments
 (0)