Skip to content

include_cpp reads wrong path for custom output directory #1499

@tolvanea

Description

@tolvanea

Describe the bug
If Buider::custom_gendir is used to output generated code into a custom directory, then include_cpp tries to read that directory relative to itself, rather than relative to cargo root direcotory. That is, custom output location does not work.

To Reproduce
src/main.rs:

use autocxx::prelude::*;
include_cpp! {#include "compute.h"}
fn main() {}

build.rs:

fn main() {
    autocxx_build::Builder::new("src/main.rs", ["src"])
        .custom_gendir("src/subdirectory/".into()) // <-- Comment this line
        .build().unwrap().compile("compute");
}

The custom_gendir(...) generates code to directory src/subdirectory as expected, but following compile error is thrown:

error: couldn't read src/src/subdirectory/rs/autocxx-ffi-default-gen.rs: No such file or directory (os error 2)
--> src/main.rs:2:1
|
2 | include_cpp! {}
| ^^^^^^^^^^^^^^^
|
= note: this error originates in the macro include which comes from the expansion of the macro include_cpp (in Nightly builds, run with -Z macro-backtrace for more info)

error: could not compile my_autocxx (bin "my_autocxx") due to 1 previous error

That is, include tries to read from src/src/subdirectory rather than from src/subdirectory where the code was generated.

Workaround
Create a symlink that directs to the correct directory

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions