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

Add targets for tests #10

Open
AndrewGaspar opened this issue Mar 11, 2018 · 4 comments
Open

Add targets for tests #10

AndrewGaspar opened this issue Mar 11, 2018 · 4 comments

Comments

@AndrewGaspar
Copy link
Collaborator

No description provided.

@baszalmstra
Copy link

Would this be as simple as adding:

add_test(
        NAME cargo-test_${target_name}
        COMMAND
        $<TARGET_FILE:Rust::Cargo> test --target ${_CORROSION_RUST_CARGO_TARGET}
        -p ${package_name} --manifest-path ${path_to_toml}
        WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/${build_dir}
    )

to the _add_cargo_build function?

@SanderVocke
Copy link

Looks like this request is way down in the list. But I would like to chime in.

I would like to be able to run cargo build --tests to create a test executable to ship.
AFAIK Corrosion cannot run this directly and also cannot tell me what flags were used so that I can construct this command myself (while re-using the already-built dependencies).

Any suggestion?

@jschwe
Copy link
Collaborator

jschwe commented Aug 2, 2024

I would like to be able to run cargo build --tests to create a test executable to ship.

Well, that means you would basically need corrosion to import this test executable with rules to build it. This requires:

  1. Finding out which test / bench / example executables a package has. AFAIK cargo metadata does not provide this information, so you would need to check if there is a command we can run at configure time which lists all test / example / bench executables of a given package.
  2. CMake needs to know at configure time were an executable will be generated to. Cargo currently doesn't generate the test executable at a predictable location. this comment suggests parsing the output of cargo build. Since this happens at build-time (and not configure time), you would need to wrap the cargo build command in a script which invokes cargo build, parses the actual artifact location and then copies the binary to a predictable location you defined at CMake configure time.

Please do note: If you also want to support windows, then piping into jq is probably not an option. You could write the wrapper script in CMake instead, since CMake supports parsing JSON, and obviously would be available on the build system.

@SanderVocke
Copy link

Thanks, I agree that the use case is complicated and maybe not corrosion's to solve. I don't mind doing some custom cmake scripting for building the tests.

The main thing though is that I would like to match the cargo flags passed by corrosion to the main target (build type). And if possible also prevent re-compilation by using the same target folder as the already-built main corrosion target.

Is there some way to get that information out of the corrosion-generated target in cmake?

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

4 participants