diff --git a/.config/nextest.toml b/.config/nextest.toml index 1e3325b5c..5d951813c 100644 --- a/.config/nextest.toml +++ b/.config/nextest.toml @@ -1,6 +1,6 @@ [profile.default] -# Terminate slow tests after 5 minutes -slow-timeout = { period = "60s", terminate-after = 5 } +# Terminate slow tests after 10 minutes +slow-timeout = { period = "60s", terminate-after = 10 } [[profile.default.overrides]] # See https://nexte.st/book/threads-required.html diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index e137b62b2..cb2777f7c 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -281,6 +281,8 @@ jobs: runs-on: ubuntu-latest env: RUST_BACKTRACE: '1' + CARGO_INCREMENTAL: '0' + CARGO_TERM_COLOR: always container: alpine:edge steps: - uses: actions/checkout@v3 @@ -342,6 +344,9 @@ jobs: name: Test Docker if: github.event_name != 'pull_request' runs-on: ubuntu-latest + env: + CARGO_INCREMENTAL: '0' + CARGO_TERM_COLOR: always steps: - uses: actions/checkout@v3 - uses: actions/setup-python@v4 diff --git a/src/module_writer.rs b/src/module_writer.rs index 50ff83c90..c890dbd3e 100644 --- a/src/module_writer.rs +++ b/src/module_writer.rs @@ -813,7 +813,31 @@ pub fn write_cffi_module( Ok(()) } -fn generate_uniffi_bindings(crate_dir: &Path, target_dir: &Path) -> Result { +/// uniffi.toml +#[derive(Debug, serde::Deserialize)] +struct UniFfiToml { + #[serde(default)] + bindings: HashMap, +} + +/// `bindings` section of uniffi.toml +#[derive(Debug, serde::Deserialize)] +struct UniFfiBindingsConfig { + cdylib_name: Option, +} + +#[derive(Debug, Clone)] +struct UniFfiBindings { + name: String, + cdylib: String, + path: PathBuf, +} + +fn generate_uniffi_bindings( + crate_dir: &Path, + target_dir: &Path, + target_os: Os, +) -> Result { let binding_dir = target_dir.join("maturin").join("uniffi"); fs::create_dir_all(&binding_dir)?; @@ -831,9 +855,29 @@ fn generate_uniffi_bindings(crate_dir: &Path, target_dir: &Path) -> Result Result name, + None => format!("uniffi_{}", name), + }; + let cdylib = match target_os { + Os::Macos => format!("lib{}.dylib", cdylib_name), + Os::Windows => format!("{}.dll", cdylib_name), + _ => format!("lib{}.so", cdylib_name), + }; + + Ok(UniFfiBindings { + name, + cdylib, + path: py_binding, + }) } /// Creates the uniffi module with the shared library @@ -862,15 +923,12 @@ pub fn write_uniffi_module( editable: bool, pyproject_toml: Option<&PyProjectToml>, ) -> Result<()> { - let uniffi_binding = generate_uniffi_bindings(crate_dir, target_dir)?; - let binding_name = uniffi_binding.file_stem().unwrap().to_str().unwrap(); + let UniFfiBindings { + name: binding_name, + cdylib, + path: uniffi_binding, + } = generate_uniffi_bindings(crate_dir, target_dir, target_os)?; let py_init = format!("from .{} import * # NOQA\n", binding_name); - // uniffi bindings hardcoded the extension filenames - let dylib_name = match target_os { - Os::Macos => format!("libuniffi_{}.dylib", binding_name), - Os::Windows => format!("uniffi_{}.dll", binding_name), - _ => format!("libuniffi_{}.so", binding_name), - }; let module; @@ -883,7 +941,7 @@ pub fn write_uniffi_module( if editable { let base_path = python_module.join(module_name); fs::create_dir_all(&base_path)?; - let target = base_path.join(&dylib_name); + let target = base_path.join(&cdylib); fs::copy(artifact, &target).context(format!( "Failed to copy {} to {}", artifact.display(), @@ -891,7 +949,7 @@ pub fn write_uniffi_module( ))?; File::create(base_path.join("__init__.py"))?.write_all(py_init.as_bytes())?; - let target = base_path.join(binding_name).with_extension("py"); + let target = base_path.join(&binding_name).with_extension("py"); fs::copy(&uniffi_binding, &target).context(format!( "Failed to copy {} to {}", uniffi_binding.display(), @@ -926,7 +984,7 @@ pub fn write_uniffi_module( module.join(binding_name).with_extension("py"), uniffi_binding, )?; - writer.add_file_with_permissions(&module.join(dylib_name), artifact, 0o755)?; + writer.add_file_with_permissions(&module.join(cdylib), artifact, 0o755)?; } Ok(()) diff --git a/test-crates/uniffi-pure/uniffi.toml b/test-crates/uniffi-pure/uniffi.toml new file mode 100644 index 000000000..86f350f53 --- /dev/null +++ b/test-crates/uniffi-pure/uniffi.toml @@ -0,0 +1,2 @@ +[bindings.python] +cdylib_name = "example"