Skip to content

Support loading a build.rs compiled .so with -Zmiri-native-lib #4077

Open
@Nemo157

Description

@Nemo157

It's common for projects to build C dependencies in the build-scripts of -sys dependencies. To be able to use these along with miri's new FFI support requires some weird contortions:

> cargo miri test
...
error: unsupported operation: can't call foreign function ...
> MIRIFLAGS=-Zmiri-native-lib=target/shared/miri/x86_64-unknown-linux-gnu/debug/build/foobar-sys-fb396848c056a26f/out/libfoobar.so cargo miri test

(along with making the build script detect CARGO_CFG_MIRI and switch to outputting a shared object instead of the normal staticlib).

It'd be nice if there were some way to inform miri about the native lib from the build script, similar to how we can tell the linker about the native libraries (maybe there's some way miri could reuse these cargo commands?).

cargo:rustc-link-lib=static=foobar
cargo:rustc-link-search=native=$OUT_DIR

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-nativeArea: calling native functions via FFIC-enhancementCategory: a PR with an enhancement or an issue tracking an accepted enhancement

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions