Skip to content

Commit

Permalink
fixup
Browse files Browse the repository at this point in the history
  • Loading branch information
indygreg committed Aug 29, 2021
1 parent fc2a5dd commit b5f872b
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 61 deletions.
1 change: 1 addition & 0 deletions pyoxidizer/src/new-project-cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,7 @@ dependencies = [
"memory-module-sys",
"once_cell",
"pyo3",
"pyo3-build-config",
"python-packaging",
"python-packed-resources",
"snmalloc-sys",
Expand Down
36 changes: 8 additions & 28 deletions pyoxidizer/src/py_packaging/binary.rs
Original file line number Diff line number Diff line change
Expand Up @@ -533,25 +533,8 @@ pub struct LinkStaticLibraryData {
}

impl LinkStaticLibraryData {
/// Name of the static library containing Python.
///
/// python3-sys uses `#[link(name="pythonXY")]` attributes heavily on Windows. Its
/// build.rs then remaps ``pythonXY`` to e.g. ``python37``. This causes Cargo to
/// link against ``python37.lib`` (or ``pythonXY.lib`` if the
/// ``rustc-link-lib=pythonXY:python{}{}`` line is missing, which is the case
/// in our invocation).
///
/// We don't want the "real" libpython being linked. And this is a very real
/// possibility since the path to it could be in an environment variable
/// outside of our control!
///
/// In addition, we can't naively remap ``pythonXY`` ourselves without adding
/// a ``#[link]`` to the crate.
///
/// Our current workaround is to produce a ``pythonXY.lib`` file. This satisfies
/// the requirement of ``python3-sys`` that a ``pythonXY.lib`` file exists.
fn library_name(&self) -> &'static str {
"pythonXY"
"python3"
}

fn library_path(&self, dest_dir: impl AsRef<Path>, target_triple: &str) -> PathBuf {
Expand Down Expand Up @@ -707,11 +690,8 @@ impl<'a> EmbeddedPythonContext<'a> {
let dest_dir = dest_dir.as_ref();

self.link_settings
.write_files(dest_dir)
.write_files(dest_dir, &self.target_triple)
.context("writing files needed for linking")?;
let extra_build_script_lines = self
.link_settings
.build_script_lines(dest_dir, self.target_triple.contains("-windows-"))?;

Ok(PyO3InterpreterConfig {
implementation: if self.python_implementation.starts_with("cpython") {
Expand All @@ -726,12 +706,14 @@ impl<'a> EmbeddedPythonContext<'a> {
},
version: self.python_version.clone(),
// Irrelevant since we control link settings below.
shared: false,
shared: matches!(
&self.link_settings,
LibpythonLinkSettings::ExistingDynamic(_)
),
// pyembed requires the full Python API.
abi3: false,
// Don't define library metadata since we control link settings below.
lib_name: None,
lib_dir: None,
lib_name: Some("python3".to_string()),
lib_dir: Some(dest_dir.to_path_buf()),
executable: Some(self.python_exe_host.clone()),
// TODO set from Python distribution metadata.
pointer_width: Some(if self.target_triple.starts_with("i686-") {
Expand All @@ -740,8 +722,6 @@ impl<'a> EmbeddedPythonContext<'a> {
64
}),
build_flags: self.python_build_flags.clone(),
suppress_build_script_link_lines: Some(true),
extra_build_script_lines,
})
}

Expand Down
33 changes: 0 additions & 33 deletions python-packaging/src/pyo3.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,6 @@ pub struct PyO3InterpreterConfig {
///
/// Used for influencing conditional PyO3 features.
pub build_flags: BTreeSet<String>,

/// Whether to suppress emission of `cargo:rustc` lines to configure linking.
pub suppress_build_script_link_lines: Option<bool>,

/// Additional lines to `println!()` from Cargo build scripts.
pub extra_build_script_lines: Vec<String>,
}

impl PyO3InterpreterConfig {
Expand All @@ -72,8 +66,6 @@ impl PyO3InterpreterConfig {
let mut executable = None;
let mut pointer_width = None;
let mut build_flags = BTreeSet::new();
let mut suppress_build_script_link_lines = None;
let mut extra_build_script_lines = vec![];

for line in lines {
let line = line?;
Expand Down Expand Up @@ -123,21 +115,6 @@ impl PyO3InterpreterConfig {
"build_flags" => {
build_flags.extend(value.split(',').map(|x| x.to_string()));
}
"suppress_build_script_link_lines" => {
suppress_build_script_link_lines = Some(match value {
"true" => true,
"false" => false,
_ => {
return Err(anyhow!(
"bad suppress_build_script_link_lines value: {}",
value
))
}
});
}
"extra_build_script_line" => {
extra_build_script_lines.push(value.to_string());
}
_ => return Err(anyhow!("unexpected PyO3 config file key: {}", key)),
}
}
Expand All @@ -152,8 +129,6 @@ impl PyO3InterpreterConfig {
executable,
pointer_width,
build_flags,
suppress_build_script_link_lines,
extra_build_script_lines,
})
}

Expand Down Expand Up @@ -183,14 +158,6 @@ impl PyO3InterpreterConfig {
writer
.write_all(format!("build_flags={}\n", self.build_flags.iter().join(",")).as_bytes())?;

if let Some(value) = self.suppress_build_script_link_lines {
writer.write_all(format!("suppress_build_script_link_lines={}\n", value).as_bytes())?;
}

for line in &self.extra_build_script_lines {
writer.write_all(format!("extra_build_script_line={}\n", line).as_bytes())?;
}

Ok(())
}

Expand Down

0 comments on commit b5f872b

Please sign in to comment.