containers / libkrun

A dynamic library providing Virtualization-based process isolation capabilities
Apache License 2.0
901 stars 74 forks source link

having trouble compiling on Alpine 3.17 #111

Closed dmolik closed 1 year ago

dmolik commented 1 year ago

I'm getting the following with rust 1.66.1, and musl 1.2.3-r4:

error[E0425]: cannot find function `copy_file_range` in crate `libc`
    --> src/devices/src/virtio/fs/linux/passthrough.rs:1721:19
     |
1721 |             libc::copy_file_range(
     |                   ^^^^^^^^^^^^^^^
     |
    ::: /usr/local/cargo/registry/src/github.com-1ecc6299db9ec823/libc-0.2.126/src/unix/linux_like/linux/musl/b64/x86_64/mod.rs:576:1
     |
576  | pub const SYS_copy_file_range: ::c_long = 326;
     | --------------------------------------- similarly named constant `SYS_copy_file_range` defined here
     |
help: a constant with a similar name exists
     |
1721 |             libc::SYS_copy_file_range(
     |                   ~~~~~~~~~~~~~~~~~~~
help: consider importing this function
     |
5    | use nix::fcntl::copy_file_range;
     |
help: if you import `copy_file_range`, refer to it directly
     |
1721 -             libc::copy_file_range(
1721 +             copy_file_range(
     |
slp commented 1 year ago

Seems like either musl is missing support for copy_file_range or libc doesn't yet provide a wrapper for it. After a quick look at both projects, seems to be the latter. Should be a quite straightforward PR for libc, do you have plans to send it yourself?

dmolik commented 1 year ago

I don't have a plan. I did poke around today, and it doesn't seem like a huge lift, but I'm not a rust developer, but from what I could tell it was something like a 12 line patch to libc

slp commented 1 year ago

I've just created a PR adding copy_file_range to musl: https://github.com/rust-lang/libc/pull/3133

Meanwhile, it's possible to build libkrun by patching the dependency:

--- a/Cargo.toml
+++ b/Cargo.toml
@@ -7,3 +7,6 @@ members = ["src/libkrun"]
 [profile.release]
 #panic = "abort"
 lto = true
+
+[patch.crates-io]
+libc = { git = "https://github.com/slp/libc", branch = "musl-copy-file-range" }
dmolik commented 1 year ago

thanks!

slp commented 1 year ago

Closing as copy_file_range is now available in musl.