Skip to content

Commit 0c84736

Browse files
authored
target: add -Zunstable-options when querying cfg (#587)
Since Rust 1.95,invoking rustc with --target requires -Zunstable-options when used with custom JSON targets. Without this flag, the command fails. Reference: rust-lang/rust@b4e645f rust-lang/rust@8563312 Signed-off-by: Deepesh Varatharajan <Deepesh.Varatharajan@windriver.com>
1 parent 910fc60 commit 0c84736

1 file changed

Lines changed: 16 additions & 0 deletions

File tree

setuptools_rust/rustc_info.py

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

3+
import os
34
import subprocess
45
from setuptools.errors import PlatformError
56
from functools import lru_cache
@@ -38,6 +39,19 @@ def get_rust_host(env: Optional[Env]) -> str:
3839
RustCfgs = NewType("RustCfgs", Dict[str, Optional[str]])
3940

4041

42+
def _is_custom_target(target: str) -> bool:
43+
if target.endswith(".json"):
44+
return True
45+
paths = os.environ.get("RUST_TARGET_PATH")
46+
if not paths:
47+
return False
48+
for p in paths.split(os.pathsep):
49+
candidate = os.path.join(p, target + ".json")
50+
if os.path.exists(candidate):
51+
return True
52+
return False
53+
54+
4155
def get_rustc_cfgs(target_triple: Optional[str], env: Env) -> RustCfgs:
4256
cfgs = RustCfgs({})
4357
for entry in get_rust_target_info(target_triple, env):
@@ -54,6 +68,8 @@ def get_rustc_cfgs(target_triple: Optional[str], env: Env) -> RustCfgs:
5468
def get_rust_target_info(target_triple: Optional[str], env: Env) -> List[str]:
5569
cmd = ["rustc", "--print", "cfg"]
5670
if target_triple:
71+
if _is_custom_target(target_triple):
72+
cmd.extend(["-Z", "unstable-options"])
5773
cmd.extend(["--target", target_triple.split(".")[0]])
5874
output = check_subprocess_output(cmd, env=env, text=True)
5975
return output.splitlines()

0 commit comments

Comments
 (0)