Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor abi tag to use EXT_SUFFIX #1648

Merged
merged 1 commit into from Jun 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 0 additions & 6 deletions src/build_options.rs
Expand Up @@ -261,8 +261,6 @@ impl BuildOptions {
.get("EXT_SUFFIX")
.context("syconfig didn't define an `EXT_SUFFIX` ಠ_ಠ")?;
let soabi = sysconfig_data.get("SOABI");
let abi_tag =
soabi.and_then(|abi| abi.split('-').nth(1).map(ToString::to_string));
let interpreter_kind = soabi
.and_then(|tag| {
if tag.starts_with("pypy") {
Expand All @@ -283,7 +281,6 @@ impl BuildOptions {
interpreter_kind,
abiflags,
ext_suffix: ext_suffix.to_string(),
abi_tag,
pointer_width: None,
},
executable: PathBuf::new(),
Expand Down Expand Up @@ -351,7 +348,6 @@ impl BuildOptions {
interpreter_kind: InterpreterKind::CPython,
abiflags: "".to_string(),
ext_suffix: ".pyd".to_string(),
abi_tag: None,
pointer_width: None,
},
executable: PathBuf::new(),
Expand All @@ -378,7 +374,6 @@ impl BuildOptions {
interpreter_kind: InterpreterKind::CPython,
abiflags: "".to_string(),
ext_suffix: ".pyd".to_string(),
abi_tag: None,
pointer_width: None,
},
executable: PathBuf::new(),
Expand Down Expand Up @@ -418,7 +413,6 @@ impl BuildOptions {
interpreter_kind: InterpreterKind::CPython,
abiflags: "".to_string(),
ext_suffix: "".to_string(),
abi_tag: None,
pointer_width: None,
},
executable: PathBuf::new(),
Expand Down
53 changes: 12 additions & 41 deletions src/python_interpreter/config.rs
Expand Up @@ -29,10 +29,6 @@ pub struct InterpreterConfig {
pub abiflags: String,
/// Suffix to use for extension modules as given by sysconfig.
pub ext_suffix: String,
/// Part of sysconfig's SOABI specifying {major}{minor}{abiflags}
///
/// Note that this always `None` on windows
pub abi_tag: Option<String>,
/// Pointer width
pub pointer_width: Option<usize>,
}
Expand Down Expand Up @@ -78,34 +74,29 @@ impl InterpreterConfig {
} else {
"".to_string()
};
let abi_tag = format!("{}{}{}", major, minor, abiflags);
let ldversion = format!("{}{}{}", major, minor, abiflags);
let ext_suffix = format!(
".cpython-{}-{}-linux-{}.so",
abi_tag, python_arch, target_env
ldversion, python_arch, target_env
);
Some(Self {
major,
minor,
interpreter_kind: CPython,
abiflags,
ext_suffix,
abi_tag: Some(abi_tag),
pointer_width: Some(target.pointer_width()),
})
}
(Os::Linux, PyPy) => {
let abi_tag = PYPY_ABI_TAG.to_string();
let ext_suffix = format!(
".pypy{}{}-{}-{}-linux-{}.so",
major, minor, abi_tag, python_arch, target_env
);
let abi_tag = format!("pypy{}{}-{}", major, minor, PYPY_ABI_TAG);
let ext_suffix = format!(".{}-{}-linux-{}.so", abi_tag, python_arch, target_env);
Some(Self {
major,
minor,
interpreter_kind: PyPy,
abiflags: String::new(),
ext_suffix,
abi_tag: Some(abi_tag),
pointer_width: Some(target.pointer_width()),
})
}
Expand All @@ -115,28 +106,25 @@ impl InterpreterConfig {
} else {
"".to_string()
};
let abi_tag = format!("{}{}{}", major, minor, abiflags);
let ext_suffix = format!(".cpython-{}-darwin.so", abi_tag);
let ldversion = format!("{}{}{}", major, minor, abiflags);
let ext_suffix = format!(".cpython-{}-darwin.so", ldversion);
Some(Self {
major,
minor,
interpreter_kind: CPython,
abiflags,
ext_suffix,
abi_tag: Some(abi_tag),
pointer_width: Some(target.pointer_width()),
})
}
(Os::Macos, PyPy) => {
let abi_tag = PYPY_ABI_TAG.to_string();
let ext_suffix = format!(".pypy{}{}-{}-darwin.so", major, minor, abi_tag);
let ext_suffix = format!(".pypy{}{}-{}-darwin.so", major, minor, PYPY_ABI_TAG);
Some(Self {
major,
minor,
interpreter_kind: PyPy,
abiflags: String::new(),
ext_suffix,
abi_tag: Some(abi_tag),
pointer_width: Some(target.pointer_width()),
})
}
Expand All @@ -158,7 +146,6 @@ impl InterpreterConfig {
interpreter_kind: CPython,
abiflags: String::new(),
ext_suffix,
abi_tag: None,
pointer_width: Some(target.pointer_width()),
})
}
Expand All @@ -167,15 +154,13 @@ impl InterpreterConfig {
// PyPy on Windows only supports x86_64
return None;
}
let abi_tag = PYPY_ABI_TAG.to_string();
let ext_suffix = format!(".pypy{}{}-{}-win_amd64.pyd", major, minor, abi_tag);
let ext_suffix = format!(".pypy{}{}-{}-win_amd64.pyd", major, minor, PYPY_ABI_TAG);
Some(Self {
major,
minor,
interpreter_kind: PyPy,
abiflags: String::new(),
ext_suffix,
abi_tag: Some(abi_tag),
pointer_width: Some(target.pointer_width()),
})
}
Expand All @@ -185,53 +170,47 @@ impl InterpreterConfig {
} else {
("".to_string(), format!(".cpython-{}{}.so", major, minor))
};
let abi_tag = format!("{}{}{}", major, minor, abiflags);
Some(Self {
major,
minor,
interpreter_kind: CPython,
abiflags,
ext_suffix,
abi_tag: Some(abi_tag),
pointer_width: Some(target.pointer_width()),
})
}
(Os::NetBsd, CPython) => {
let abi_tag = format!("{}{}", major, minor);
let ext_suffix = ".so".to_string();
Some(Self {
major,
minor,
interpreter_kind: CPython,
abiflags: String::new(),
ext_suffix,
abi_tag: Some(abi_tag),
pointer_width: Some(target.pointer_width()),
})
}
(Os::OpenBsd, CPython) => {
let abi_tag = format!("{}{}", major, minor);
let ext_suffix = format!(".cpython-{}.so", abi_tag);
let ldversion = format!("{}{}", major, minor);
let ext_suffix = format!(".cpython-{}.so", ldversion);
Some(Self {
major,
minor,
interpreter_kind: CPython,
abiflags: String::new(),
ext_suffix,
abi_tag: Some(abi_tag),
pointer_width: Some(target.pointer_width()),
})
}
(Os::Emscripten, CPython) => {
let abi_tag = format!("{}{}", major, minor);
let ext_suffix = format!(".cpython-{}-{}-emscripten.so", abi_tag, python_arch);
let ldversion = format!("{}{}", major, minor);
let ext_suffix = format!(".cpython-{}-{}-emscripten.so", ldversion, python_arch);
Some(Self {
major,
minor,
interpreter_kind: CPython,
abiflags: String::new(),
ext_suffix,
abi_tag: Some(abi_tag),
pointer_width: Some(target.pointer_width()),
})
}
Expand Down Expand Up @@ -382,7 +361,6 @@ impl InterpreterConfig {
interpreter_kind,
abiflags: abiflags.unwrap_or_default(),
ext_suffix,
abi_tag: Some(abi_tag),
pointer_width,
})
}
Expand Down Expand Up @@ -482,7 +460,6 @@ mod test {
)
.unwrap();
assert_eq!(sysconfig.abiflags, "");
assert_eq!(sysconfig.abi_tag.as_deref(), Some("pp73"));
assert_eq!(sysconfig.ext_suffix, ".pypy39-pp73-x86_64-linux-gnu.so");

let sysconfig = InterpreterConfig::lookup_one(
Expand Down Expand Up @@ -560,7 +537,6 @@ mod test {
)
.unwrap();
assert_eq!(sysconfig.abiflags, "m");
assert_eq!(sysconfig.abi_tag.as_deref(), Some("37m"));
assert_eq!(sysconfig.ext_suffix, ".cpython-37m-darwin.so");

// PyPy
Expand All @@ -571,7 +547,6 @@ mod test {
)
.unwrap();
assert_eq!(sysconfig.abiflags, "");
assert_eq!(sysconfig.abi_tag.as_deref(), Some("pp73"));
assert_eq!(sysconfig.ext_suffix, ".pypy39-pp73-darwin.so");

let sysconfig = InterpreterConfig::lookup_one(
Expand Down Expand Up @@ -630,7 +605,6 @@ mod test {
)
.unwrap();
assert_eq!(sysconfig.abiflags, "m");
assert_eq!(sysconfig.abi_tag.as_deref(), Some("37m"));
assert_eq!(sysconfig.ext_suffix, ".so");

let sysconfig = InterpreterConfig::lookup_one(
Expand All @@ -640,7 +614,6 @@ mod test {
)
.unwrap();
assert_eq!(sysconfig.abiflags, "");
assert_eq!(sysconfig.abi_tag.as_deref(), Some("310"));
assert_eq!(sysconfig.ext_suffix, ".cpython-310.so");

let sysconfig = InterpreterConfig::lookup_one(
Expand Down Expand Up @@ -678,7 +651,6 @@ mod test {
)
.unwrap();
assert_eq!(sysconfig.abiflags, "");
assert_eq!(sysconfig.abi_tag.as_deref(), Some("37"));
assert_eq!(sysconfig.ext_suffix, ".so");

let sysconfig = InterpreterConfig::lookup_one(
Expand Down Expand Up @@ -728,7 +700,6 @@ mod test {
)
.unwrap();
assert_eq!(sysconfig.abiflags, "");
assert_eq!(sysconfig.abi_tag.as_deref(), Some("310"));
assert_eq!(sysconfig.ext_suffix, ".cpython-310-wasm32-emscripten.so");
}

Expand Down
18 changes: 0 additions & 18 deletions src/python_interpreter/get_interpreter_metadata.py
Expand Up @@ -19,23 +19,6 @@
else:
ext_suffix = sysconfig.get_config_var("EXT_SUFFIX")


def get_abi_tag():
# This should probably return the ABI tag based on EXT_SUFFIX in the same
# way as pypa/packaging. See https://github.com/pypa/packaging/pull/607.
# For simplicity, we just fix it up for GraalPy for now and leave the logic
# for the other interpreters untouched, but this should be fixed properly
# down the road.
if platform.python_implementation() == "GraalVM":
ext_suffix = sysconfig.get_config_var("EXT_SUFFIX")
parts = ext_suffix.split(".")
soabi = parts[1]
abi = "-".join(soabi.split("-")[:3])
return abi.replace(".", "_").replace("-", "_")
else:
return (sysconfig.get_config_var("SOABI") or "-").split("-")[1]


metadata = {
# sys.implementation.name can differ from platform.python_implementation(), for example
# Pyston has sys.implementation.name == "pyston" while platform.python_implementation() == cpython
Expand All @@ -47,7 +30,6 @@ def get_abi_tag():
"interpreter": platform.python_implementation().lower(),
"ext_suffix": ext_suffix,
"soabi": sysconfig.get_config_var("SOABI") or None,
"abi_tag": get_abi_tag() or None,
"platform": sysconfig.get_platform(),
# This one isn't technically necessary, but still very useful for sanity checks
"system": platform.system().lower(),
Expand Down