pub fn write_cffi_module(
    writer: &mut impl ModuleWriter,
    project_layout: &ProjectLayout,
    crate_dir: &Path,
    module_name: &str,
    artifact: &Path,
    python: &PathBuf,
    develop: bool,
) -> Result<()> {
    let cffi_declarations = generate_cffi_declarations(&crate_dir, python)?;

    let module;

    match project_layout {
        ProjectLayout::Mixed(ref python_module) => {
            write_python_part(writer, python_module, &module_name)
                .context("Failed to add the python module to the package")?;

            if develop {
                let base_path = python_module.join(&module_name);
                fs::create_dir_all(&base_path)?;
                let target = base_path.join("native.so");
                fs::copy(&artifact, &target).context(format!(
                    "Failed to copy {} to {}",
                    artifact.display(),
                    target.display()
                ))?;
                File::create(base_path.join("__init__.py"))?
                    .write_all(cffi_init_file().as_bytes())?;
                File::create(base_path.join("ffi.py"))?.write_all(cffi_declarations.as_bytes())?;
            }

            module = PathBuf::from(module_name).join(module_name);
        }
        ProjectLayout::PureRust => module = PathBuf::from(module_name),
    };

    writer.add_directory(&module)?;
    writer.add_bytes(&module.join("__init__.py"), cffi_init_file().as_bytes())?;
    writer.add_bytes(&module.join("ffi.py"), cffi_declarations.as_bytes())?;
    writer.add_file_with_permissions(&module.join("native.so"), &artifact, 0o755)?;

    Ok(())
}
/// Creates the cffi module with the shared library, the cffi declarations and the cffi loader
Creates the cffi module with the shared library, the cffi declarations and the cffi loader
Creates the cffi module with the shared library the cffi declarations and the cffi loader
pub fn write_cffi_module(
    writer: &mut impl ModuleWriter,
    project_layout: &ProjectLayout,
    crate_dir: &Path,
    module_name: &str,
    artifact: &Path,
    python: &PathBuf,
    develop: bool,
) -> Result<()> {
    let cffi_declarations = generate_cffi_declarations(&crate_dir, python)?;
    let module;
    match project_layout {
        ProjectLayout::Mixed(ref python_module) => {
            write_python_part(writer, python_module, &module_name)
                .context("Failed to add the python module to the package")?;
            if develop {
                let base_path = python_module.join(&module_name);
                fs::create_dir_all(&base_path)?;
                let target = base_path.join("native.so");
                fs::copy(&artifact, &target).context(format!(
                    "Failed to copy {} to {}",
                    artifact.display(),
                    target.display()
                ))?;
                File::create(base_path.join("__init__.py"))?
                    .write_all(cffi_init_file().as_bytes())?;
                File::create(base_path.join("ffi.py"))?.write_all(cffi_declarations.as_bytes())?;
            }
            module = PathBuf::from(module_name).join(module_name);
        }
        ProjectLayout::PureRust => module = PathBuf::from(module_name),
    };
    writer.add_directory(&module)?;
    writer.add_bytes(&module.join("__init__.py"), cffi_init_file().as_bytes())?;
    writer.add_bytes(&module.join("ffi.py"), cffi_declarations.as_bytes())?;
    writer.add_file_with_permissions(&module.join("native.so"), &artifact, 0o755)?;
    Ok(())
}
pub fn write_cffi_module ( writer : & mut impl ModuleWriter , project_layout : & ProjectLayout , crate_dir : & Path , module_name : & str , artifact : & Path , python : & PathBuf , develop : bool , ) -> Result < ( ) > { let cffi_declarations = generate_cffi_declarations ( & crate_dir , python ) ? ; let module ; match project_layout { ProjectLayout :: Mixed ( ref python_module ) => { write_python_part ( writer , python_module , & module_name ) . context ( " " ) ? ; if develop { let base_path = python_module . join ( & module_name ) ; fs :: create_dir_all ( & base_path ) ? ; let target = base_path . join ( " " ) ; fs :: copy ( & artifact , & target ) . context ( format ! ( " " artifact display ( ) target display ( ) ) ) ? ; File :: create ( base_path . join ( " " ) ) ? . write_all ( cffi_init_file ( ) . as_bytes ( ) ) ? ; File :: create ( base_path . join ( " " ) ) ? . write_all ( cffi_declarations . as_bytes ( ) ) ? ; } module = PathBuf :: from ( module_name ) . join ( module_name ) ; } ProjectLayout :: PureRust => module = PathBuf :: from ( module_name ) , } ; writer . add_directory ( & module ) ? ; writer . add_bytes ( & module . join ( " " ) , cffi_init_file ( ) . as_bytes ( ) ) ? ; writer . add_bytes ( & module . join ( " " ) , cffi_declarations . as_bytes ( ) ) ? ; writer . add_file_with_permissions ( & module . join ( " " ) , & artifact , 0o755 ) ? ; Ok ( ( ) ) }
Creates the cffi module with the shared library, the cffi declarations and the cffi loader
Creates the cffi module with the shared library the cffi declarations and the cffi loader
writer
&mut impl ModuleWriter
project_layout
&ProjectLayout
crate_dir
&Path
module_name
&str
artifact
&Path
python
&PathBuf
develop
bool
writer
&mut impl ModuleWriter
project_layout
&ProjectLayout
crate_dir
&Path
module_name
&str
artifact
&Path
python
&PathBuf
develop
bool