diff --git a/Cargo.lock b/Cargo.lock index e40381a65..dbd88bc44 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -19,16 +19,6 @@ dependencies = [ "pkg-config", ] -[[package]] -name = "c2rust_out" -version = "0.0.0" -dependencies = [ - "crc32fast", - "libbz2-rs-sys", - "libc", - "tempfile", -] - [[package]] name = "cc" version = "1.1.31" @@ -71,11 +61,21 @@ checksum = "486f806e73c5707928240ddc295403b1b93c96a02038563881c4a2fd84b81ac4" [[package]] name = "libbz2-rs-sys" -version = "0.0.0" +version = "0.1.0" dependencies = [ "libc", ] +[[package]] +name = "libbzip2-rs" +version = "0.1.0" +dependencies = [ + "crc32fast", + "libbz2-rs-sys", + "libc", + "tempfile", +] + [[package]] name = "libc" version = "0.2.161" diff --git a/Cargo.toml b/Cargo.toml index 674e7d644..517d34c07 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -6,17 +6,34 @@ members = [ exclude = [ "libbz2-rs-sys-cdylib", ] -package.edition = "2021" - -[package] -name = "c2rust_out" -authors = ["C2Rust"] -version = "0.0.0" -publish = false +[workspace.package] +version = "0.1.0" edition = "2021" +license = "bzip2-1.0.6" +repository = "https://github.com/trifectatechfoundation/libbzip2-rs" +homepage = "https://github.com/trifectatechfoundation/libbzip2-rs" +readme = "./README.md" +description = "a drop-in compatible rust bzip2 implementation" +publish = true rust-version = "1.82" # MSRV +[workspace.dependencies] +libc = "0.2" +libbz2-rs-sys = { path = "libbz2-rs-sys/", default-features = false } + +[package] +name = "libbzip2-rs" +readme.workspace = true +description.workspace = true +version.workspace = true +edition.workspace = true +license.workspace = true +repository.workspace = true +homepage.workspace = true +publish.workspace = true +rust-version.workspace = true + [[bin]] name = "bzip2" path = "bzip2.rs" @@ -25,14 +42,11 @@ path = "bzip2.rs" name = "bzip2recover" path = "bzip2recover.rs" -[workspace.dependencies] -libc = "0.2" -libbz2-rs-sys = { path = "libbz2-rs-sys/", default-features = false } - - [dependencies] -libc = "0.2" -libbz2-rs-sys = { path = "libbz2-rs-sys/" } +libc.workspace = true +# we need `std` here, because we test the log output of the binaries, and those only +# get printed when std is enabled. +libbz2-rs-sys = { workspace = true, features = ["stdio", "c-allocator"] } [dev-dependencies] tempfile = "3.13.0" diff --git a/libbz2-rs-sys-cdylib/Cargo.lock b/libbz2-rs-sys-cdylib/Cargo.lock index edde934e0..d684ee4d7 100644 --- a/libbz2-rs-sys-cdylib/Cargo.lock +++ b/libbz2-rs-sys-cdylib/Cargo.lock @@ -4,14 +4,14 @@ version = 3 [[package]] name = "libbz2-rs-sys" -version = "0.0.0" +version = "0.1.0" dependencies = [ "libc", ] [[package]] name = "libbz2-rs-sys-cdylib" -version = "0.0.0" +version = "0.1.0" dependencies = [ "libbz2-rs-sys", "libc", diff --git a/libbz2-rs-sys-cdylib/Cargo.toml b/libbz2-rs-sys-cdylib/Cargo.toml index b0de5dec1..fe75dd69b 100644 --- a/libbz2-rs-sys-cdylib/Cargo.toml +++ b/libbz2-rs-sys-cdylib/Cargo.toml @@ -1,13 +1,13 @@ [package] name = "libbz2-rs-sys-cdylib" -version = "0.0.0" +version = "0.1.0" edition = "2021" -readme = "README.md" license = "bzip2-1.0.6" repository = "https://github.com/trifectatechfoundation/libbzip2-rs" homepage = "https://github.com/trifectatechfoundation/libbzip2-rs" +readme = "./README.md" +description = "a drop-in compatible libbz2 cdylib" publish = true -description = "A memory-safe bzip2 implementation written in rust" rust-version = "1.82" # MSRV [lib] @@ -22,7 +22,7 @@ custom-prefix = ["libbz2-rs-sys/custom-prefix"] # use the LIBBZ2_RS_SYS_PREFIX t capi = [] [dependencies] -libbz2-rs-sys = { version = "0.0.0", path = "../libbz2-rs-sys", default-features = false, features = ["c-allocator"] } +libbz2-rs-sys = { version = "0.1.0", path = "../libbz2-rs-sys", default-features = false, features = ["c-allocator"] } libc = "0.2" [package.metadata.capi.library] diff --git a/libbz2-rs-sys-cdylib/LICENSE b/libbz2-rs-sys-cdylib/LICENSE new file mode 100644 index 000000000..604eb1c1d --- /dev/null +++ b/libbz2-rs-sys-cdylib/LICENSE @@ -0,0 +1,42 @@ + +-------------------------------------------------------------------------- + +This program, "bzip2", the associated library "libbzip2", and all +documentation, are copyright (C) 1996-2010 Julian R Seward. All +rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions +are met: + +1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + +2. The origin of this software must not be misrepresented; you must + not claim that you wrote the original software. If you use this + software in a product, an acknowledgment in the product + documentation would be appreciated but is not required. + +3. Altered source versions must be plainly marked as such, and must + not be misrepresented as being the original software. + +4. The name of the author may not be used to endorse or promote + products derived from this software without specific prior written + permission. + +THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS +OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY +DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE +GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, +WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING +NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +Julian Seward, jseward@acm.org +bzip2/libbzip2 version 1.1.0 of 6 September 2010 + +-------------------------------------------------------------------------- diff --git a/libbz2-rs-sys-cdylib/src/lib.rs b/libbz2-rs-sys-cdylib/src/lib.rs index 05e5d213c..0fdc94927 100644 --- a/libbz2-rs-sys-cdylib/src/lib.rs +++ b/libbz2-rs-sys-cdylib/src/lib.rs @@ -14,9 +14,8 @@ impl core::fmt::Write for StderrWritter { use core::ffi::c_void; use libc::write; - unsafe { - write(2, s.as_ptr() as *const c_void, s.len()); - } + unsafe { write(2, s.as_ptr() as *const c_void, s.len() as _) }; + Ok(()) } } diff --git a/libbz2-rs-sys/Cargo.toml b/libbz2-rs-sys/Cargo.toml index d523c3ab4..85dd9739c 100644 --- a/libbz2-rs-sys/Cargo.toml +++ b/libbz2-rs-sys/Cargo.toml @@ -1,7 +1,14 @@ [package] name = "libbz2-rs-sys" readme = "README.md" +description.workspace = true +version.workspace = true edition.workspace = true +license.workspace = true +repository.workspace = true +homepage.workspace = true +publish.workspace = true +rust-version.workspace = true [features] default = ["std", "stdio"] diff --git a/libbz2-rs-sys/LICENSE b/libbz2-rs-sys/LICENSE new file mode 120000 index 000000000..012065c85 --- /dev/null +++ b/libbz2-rs-sys/LICENSE @@ -0,0 +1 @@ +../COPYING \ No newline at end of file diff --git a/libbz2-rs-sys/src/bzlib.rs b/libbz2-rs-sys/src/bzlib.rs index 7e436d3d1..a3603e166 100644 --- a/libbz2-rs-sys/src/bzlib.rs +++ b/libbz2-rs-sys/src/bzlib.rs @@ -307,7 +307,7 @@ mod stream { let bzalloc = strm.bzalloc.get_or_insert(default_bzalloc); let bzfree = strm.bzfree.get_or_insert(default_bzfree); - Some(Allocator::custom(*bzalloc, *bzfree, (*strm).opaque)) + Some(Allocator::custom(*bzalloc, *bzfree, strm.opaque)) } } } diff --git a/libbz2-rs-sys/src/lib.rs b/libbz2-rs-sys/src/lib.rs index 11fac3228..04b6f82b9 100644 --- a/libbz2-rs-sys/src/lib.rs +++ b/libbz2-rs-sys/src/lib.rs @@ -83,10 +83,30 @@ pub(crate) use libbz2_rs_sys_version; // --- debug logs +#[cfg(all(not(feature = "std"), feature = "stdio"))] +pub(crate) struct StderrWritter; + +#[cfg(all(not(feature = "std"), feature = "stdio"))] +impl core::fmt::Write for StderrWritter { + fn write_str(&mut self, s: &str) -> core::fmt::Result { + use core::ffi::c_void; + use libc::write; + + unsafe { write(2, s.as_ptr() as *const c_void, s.len() as _) }; + + Ok(()) + } +} + macro_rules! debug_log { ($($arg:tt)*) => { #[cfg(feature = "std")] std::eprint!($($arg)*); + #[cfg(all(not(feature = "std"), feature = "stdio"))] + { + use core::fmt::Write; + let _ = write!($crate::StderrWritter, $($arg)*); + } }; } @@ -94,6 +114,11 @@ macro_rules! debug_logln { ($($arg:tt)*) => { #[cfg(feature = "std")] std::eprintln!($($arg)*); + #[cfg(all(not(feature = "std"), feature = "stdio"))] + { + use core::fmt::Write; + let _ = writeln!($crate::StderrWritter, $($arg)*); + } }; }