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

Panics when building a #![no_std] crate on linux #394

Closed
jahartsell opened this issue Aug 15, 2024 · 1 comment
Closed

Panics when building a #![no_std] crate on linux #394

jahartsell opened this issue Aug 15, 2024 · 1 comment

Comments

@jahartsell
Copy link

It seems like some crates can have an empty link line, which causes a panic when determining the static libs here

exec.link_line

I assume static libs should just be empty in that case, and the following at least builds my case.

diff --git a/src/build.rs b/src/build.rs
index 273efc1..59b673c 100644
--- a/src/build.rs
+++ b/src/build.rs
@@ -1160,7 +1160,7 @@ pub fn cbuild(
                     .unwrap()
                     .values()
                     .next()
-                    .unwrap()
+                    .map_or("", |s| s)
                     .to_string()
             };
             let capi_config = &cpkg.capi_config;

The following example reproduces the issue for me using rust 1.80.1 and cargo-c 0.10.3+cargo-0.81.0 on Ubuntu 22.04

Cargo.toml

[package]
name = "testlib"

[features]
capi = []

[package.metadata.capi.library]
rustflags = "-Cpanic=abort"

lib.rs

#![no_std]

#[cfg(feature="capi")]
mod capi {
    #[panic_handler]
    fn panic_handler(_info: &core::panic::PanicInfo) -> ! {
        loop {}
    }

    #[no_mangle]
    extern "C" fn example() -> u32 {
        0
    }
}
@lu-zero
Copy link
Owner

lu-zero commented Sep 4, 2024

If you can send a PR I'd land it before making the next release, sorry for the belated reply but sometimes github messages get lost in the mailbox :/

lu-zero pushed a commit to jahartsell/cargo-c that referenced this issue Sep 4, 2024
nostd crates do not provide a link-line, return an empty one.

Fixes lu-zero#394.
@lu-zero lu-zero closed this as completed in 3a8b13d Sep 4, 2024
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

2 participants