cargo-c icon indicating copy to clipboard operation
cargo-c copied to clipboard

Renaming the C library?

Open pcwalton opened this issue 4 years ago • 10 comments

I'm switching Pathfinder to use cargo-c. Pathfinder is built as a series of small crates: to that end, the C bindings are under pathfinder_c. I'd like to have cargo-c rename the resulting library from pathfinder_c to pathfinder. Is this something you'd like to support?

pcwalton avatar Jun 24 '20 00:06 pcwalton

In the roadmap I already planned to add customization through package.metadata.capi entries in Cargo.toml and I'm already overriding the library section in code.

I'm not against to support it, how would it work for you?

lu-zero avatar Jun 24 '20 03:06 lu-zero

Sounds great!

pcwalton avatar Jun 24 '20 16:06 pcwalton

I'm not clear on how it would work though :) you can poke me on riot or zulip if you prefer.

lu-zero avatar Jun 24 '20 16:06 lu-zero

I think this was done in:

commit e74097065577ee4d212ddb985f7927c20b37d631
Author: Sebastian Dröge <[email protected]>
Date:   Mon Aug 24 21:17:14 2020 +0300

    Add configuration for library name and version

anholt avatar Feb 04 '21 05:02 anholt

It does, I think we can close the issue now.

lu-zero avatar Feb 04 '21 06:02 lu-zero

Is it possible that this feature isn't working quite yet, at least not as written in the README? In my case I can only rename the header using package.metadata.capi.header in Cargo.toml. If I try to use

[package]
name = "a"

[package.metadata.capi.library]
name = "b"

to rename the library I get

   Compiling a v0.1.0 (/tmp/mwe)
    Finished dev [unoptimized + debuginfo] target(s) in 0.08s
    Building pkg-config file
    Building pkg-config file
    Building header file using cbindgen
Error: CliError { error: Some(Cannot copy /tmp/a/target/./debug/libb.so to /tmp/a/target/./debug/libb.so.0.1.0.

Caused by:
    No such file or directory (os error 2)), exit_code: 101 }

It seems the first path is wrong.

Finally package.metadata.capi.pkg_config seems to be ignored. The content of the *.pc seems to be correct though:

prefix=/usr/local
exec_prefix=${prefix}
libdir=${exec_prefix}/lib
includedir=${prefix}/include

Name: b
Description: 
Version: 0.1.0
Libs: -L${libdir} -lb
Cflags: -I${includedir}/a
Libs.private: -lgcc_s -lutil -lrt -lpthread -lm -ldl -lc

The complete MWE is here: https://gist.github.com/cschwan/0cb317b682541ed6962dcab65cda1b7a

cschwan avatar Feb 14 '21 11:02 cschwan

Could you please open a new issue? It looks like there is a bug in the implementation.

lu-zero avatar Feb 15 '21 09:02 lu-zero

@sdroege probably we should add a test for it.

lu-zero avatar Feb 15 '21 09:02 lu-zero

Here you go: https://github.com/lu-zero/cargo-c/issues/166.

cschwan avatar Feb 15 '21 09:02 cschwan

@sdroege probably we should add a test for it.

Indeed. I don't use the library renaming feature myself, only the versioning overriding of the library so I didn't notice this not working.

sdroege avatar Feb 15 '21 09:02 sdroege