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

uniffi_testing does not have cargo configuration options for building cdylib #2269

Open
ElusAegis opened this issue Oct 14, 2024 · 0 comments

Comments

@ElusAegis
Copy link

Background

The uniffi_testing allows users to test their bindings using the generic macro:

uniffi::build_foreign_language_testcases!(
    "tests/bindings/test_docstring.kts",
    "tests/bindings/test_docstring.swift",
    "tests/bindings/test_docstring.py",
);

Under the hood, to do this, the uniffi_testing builds the cargo crate for the test target and then extracts the generated cdylib to be used to build bindings.

Currently, it is built in the following way:

    let mut child = Command::new(env!("CARGO"))
        .arg("test")
        .arg("--no-run")
        .arg("--message-format=json")
        .stdout(Stdio::piped())
        .spawn()
        .expect("Error running cargo build");

Problem

This implementation does not allow users to provide additional configuration arguments such as features, architectures, or optimization levels when building the cdylib. Which is particularaly important when working with bindings defined with uniffi procedural macros, which can be conditionally compiled with #[cfg_attr(feature = "optional", uniffi::export)].

As a result, it becomes impossible to test bindings that are gated by feature flags and are conditionally compiled, or when bindings generation is an optional feature of the crate (for example, under a --features "bindings" flag). This can lead to incomplete testing, missing test coverage for important functionality.

Steps to Reproduce

1.	Attempt to run binding tests for a crate where bindings are an optional feature.
2.	Observe that the generated cdylib does not include the optional feature, and the tests fail as a result.

Sample Project

optional-bindings.

Proposed Solution

A potential solution would be to allow users to specify extra cargo arguments via an optional environment variable. For example, adding support for an UNIFFI_CARGO_BUILD_EXTRA_ARGS variable:

    let mut child = Command::new(env!("CARGO"))
        .arg("test")
        .args(UNIFFI_CARGO_BUILD_EXTRA_ARGS)
        .arg("--no-run")
        .arg("--message-format=json")
        .stdout(Stdio::piped())
        .spawn()
        .expect("Error running cargo build");

This would allow users to pass arguments like --features "bindings" or specify different architectures or optimization levels for cdylib generation when running binding tests.

Sample Solution

Allow to configure how create is built for testing

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant