Skip to content

Commit

Permalink
Merge pull request #11 from alecmocatta/wasm
Browse files Browse the repository at this point in the history
Add support for WASM
  • Loading branch information
pmarks authored Jul 31, 2020
2 parents 17d64df + 730a83d commit 59cc025
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 3 deletions.
23 changes: 23 additions & 0 deletions lz4-sys/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,31 @@
#![no_std]
extern crate libc;

#[cfg(not(all(
target_arch = "wasm32",
not(any(target_env = "wasi", target_os = "wasi"))
)))]
use libc::{c_void, c_char, c_uint, size_t, c_int};

#[cfg(all(
target_arch = "wasm32",
not(any(target_env = "wasi", target_os = "wasi"))
))]
extern crate std;

#[cfg(all(
target_arch = "wasm32",
not(any(target_env = "wasi", target_os = "wasi"))
))]
use std::os::raw::{c_void, c_char, c_uint, c_int};

#[cfg(all(
target_arch = "wasm32",
not(any(target_env = "wasi", target_os = "wasi"))
))]
#[allow(non_camel_case_types)]
type size_t = usize;

#[derive(Clone, Copy)]
#[repr(C)]
pub struct LZ4FCompressionContext(pub *mut c_void);
Expand Down
2 changes: 1 addition & 1 deletion src/block/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
//! assert_eq!(v, decompress(&comp_wo_prefix, Some(1024)).unwrap());
//! ```

use super::c_char;
use super::liblz4::*;
use libc::c_char;
use std::io::{Error, ErrorKind, Result};

/// Represents the compression mode do be used.
Expand Down
2 changes: 1 addition & 1 deletion src/decoder.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use super::liblz4::*;
use libc::size_t;
use super::size_t;
use std::io::{Error, ErrorKind, Read, Result};
use std::ptr;

Expand Down
2 changes: 1 addition & 1 deletion src/encoder.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use super::liblz4::*;
use libc::size_t;
use super::size_t;
use std::cmp;
use std::io::Result;
use std::io::Write;
Expand Down
19 changes: 19 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,22 @@ pub use crate::liblz4::version;
pub use crate::liblz4::BlockMode;
pub use crate::liblz4::BlockSize;
pub use crate::liblz4::ContentChecksum;

#[cfg(not(all(
target_arch = "wasm32",
not(any(target_env = "wasi", target_os = "wasi"))
)))]
use libc::{c_char, size_t};

#[cfg(all(
target_arch = "wasm32",
not(any(target_env = "wasi", target_os = "wasi"))
))]
use std::os::raw::c_char;

#[cfg(all(
target_arch = "wasm32",
not(any(target_env = "wasi", target_os = "wasi"))
))]
#[allow(non_camel_case_types)]
type size_t = usize;

0 comments on commit 59cc025

Please sign in to comment.