Skip to content

Commit

Permalink
Merge pull request #833 from messense/cffi-header-target-dir
Browse files Browse the repository at this point in the history
Use workspace target directory for cffi header lookup
  • Loading branch information
messense authored Mar 6, 2022
2 parents 1710eaf + 3818e73 commit 29a4c26
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
1 change: 1 addition & 0 deletions src/build_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -556,6 +556,7 @@ impl BuildContext {
&mut writer,
&self.project_layout,
self.manifest_path.parent().unwrap(),
&self.target_dir,
&self.module_name,
artifact,
&self.interpreter[0].executable,
Expand Down
15 changes: 10 additions & 5 deletions src/module_writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -441,8 +441,8 @@ where

/// Checks if user has provided their own header at `target/header.h`, otherwise
/// we run cbindgen to generate one.
fn cffi_header(crate_dir: &Path, tempdir: &TempDir) -> Result<PathBuf> {
let maybe_header = crate_dir.join("target").join("header.h");
fn cffi_header(crate_dir: &Path, target_dir: &Path, tempdir: &TempDir) -> Result<PathBuf> {
let maybe_header = target_dir.join("header.h");

if maybe_header.is_file() {
println!("💼 Using the existing header at {}", maybe_header.display());
Expand Down Expand Up @@ -486,9 +486,13 @@ fn cffi_header(crate_dir: &Path, tempdir: &TempDir) -> Result<PathBuf> {
/// how to load the shared library without the header and then writes those instructions to a
/// file called `ffi.py`. This `ffi.py` will expose an object called `ffi`. This object is used
/// in `__init__.py` to load the shared library into a module called `lib`.
pub fn generate_cffi_declarations(crate_dir: &Path, python: &Path) -> Result<String> {
pub fn generate_cffi_declarations(
crate_dir: &Path,
target_dir: &Path,
python: &Path,
) -> Result<String> {
let tempdir = tempdir()?;
let header = cffi_header(crate_dir, &tempdir)?;
let header = cffi_header(crate_dir, target_dir, &tempdir)?;

let ffi_py = tempdir.as_ref().join("ffi.py");

Expand Down Expand Up @@ -679,12 +683,13 @@ pub fn write_cffi_module(
writer: &mut impl ModuleWriter,
project_layout: &ProjectLayout,
crate_dir: &Path,
target_dir: &Path,
module_name: &str,
artifact: &Path,
python: &Path,
editable: bool,
) -> Result<()> {
let cffi_declarations = generate_cffi_declarations(crate_dir, python)?;
let cffi_declarations = generate_cffi_declarations(crate_dir, target_dir, python)?;

let module;

Expand Down

0 comments on commit 29a4c26

Please sign in to comment.