Skip to content

Commit 96080bd

Browse files
committed
Adapt to be able to build with msvc toolchain: need further work especially for bindgen i32/u32 issue
1 parent 392eea0 commit 96080bd

File tree

10 files changed

+29
-17
lines changed

10 files changed

+29
-17
lines changed

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ RUN strip /build/${DIRNAME}/lib/x86_64-linux-android/libcblite.so -o /build/${DI
99
RUN strip /build/${DIRNAME}/lib/i686-linux-android/libcblite.so -o /build/${DIRNAME}/lib/i686-linux-android/libcblite.stripped.so
1010
RUN /usr/aarch64-linux-gnu/bin/strip /build/${DIRNAME}/lib/aarch64-linux-android/libcblite.so -o /build/${DIRNAME}/lib/aarch64-linux-android/libcblite.stripped.so
1111
RUN /usr/aarch64-linux-gnu/bin/strip /build/${DIRNAME}/lib/arm-linux-androideabi/libcblite.so -o /build/${DIRNAME}/lib/arm-linux-androideabi/libcblite.stripped.so
12-
RUN strip /build/${DIRNAME}/lib/x86_64-pc-windows-gnu/cblite.dll -o /build/${DIRNAME}/lib/x86_64-pc-windows-gnu/cblite.stripped.dll
12+
RUN strip /build/${DIRNAME}/lib/windows/cblite.dll -o /build/${DIRNAME}/lib/windows/cblite.stripped.dll
1313

1414
FROM scratch AS strip
1515
COPY --from=strip-stage /build/${DIRNAME}/ .

build.rs

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,10 @@ fn generate_bindings() -> Result<(), Box<dyn Error>> {
172172
.clang_arg(format!("--target={}", "x86_64-pc-windows-gnu"));
173173
}
174174

175+
bindings = bindings
176+
.clang_arg("-IC:\\Program Files\\Microsoft Visual Studio\\2022\\Enterprise\\VC\\Tools\\MSVC\\14.40.33807\\include".to_string())
177+
.clang_arg("-IC:\\Program Files (x86)\\Windows Kits\\10\\Include\\10.0.17763.0\\ucrt");
178+
175179
let out_dir = env::var("OUT_DIR")?;
176180
bindings
177181
.allowlist_type("CBL.*")
@@ -221,6 +225,13 @@ fn configure_rustc() -> Result<(), Box<dyn Error>> {
221225
env!("CARGO_MANIFEST_DIR"),
222226
CBL_LIB_DIR
223227
);
228+
} else if target_os == "windows" {
229+
println!("cargo:rustc-link-lib=dylib=cblite");
230+
println!(
231+
"cargo:rustc-link-search={}/{}/windows",
232+
env!("CARGO_MANIFEST_DIR"),
233+
CBL_LIB_DIR
234+
);
224235
} else {
225236
println!("cargo:rustc-link-lib=dylib=cblite");
226237
println!(
@@ -239,10 +250,8 @@ pub fn copy_lib() -> Result<(), Box<dyn Error>> {
239250
"{}/{}/{}/",
240251
env!("CARGO_MANIFEST_DIR"),
241252
CBL_LIB_DIR,
242-
if target_os == "ios" {
243-
"ios".to_string()
244-
} else if target_os == "macos" {
245-
"macos".to_string()
253+
if target_os == "ios" || target_os == "macos" || target_os == "windows" {
254+
target_os.clone()
246255
} else {
247256
env::var("TARGET").unwrap()
248257
}
File renamed without changes.
File renamed without changes.
File renamed without changes.

src/error.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ impl Error {
212212
}
213213

214214
pub(crate) fn as_cbl_error(&self) -> CBLError {
215-
let domain: u32;
215+
let domain: i32;
216216
let code: i32;
217217
match &self.code {
218218
ErrorCode::CouchbaseLite(e) => {
@@ -278,7 +278,7 @@ impl fmt::Display for Error {
278278

279279
impl ErrorCode {
280280
fn new(err: &CBLError) -> Self {
281-
match u32::from(err.domain) {
281+
match i32::from(err.domain) {
282282
kCBLDomain => CouchbaseLiteError::from_i32(err.code)
283283
.map_or(Self::untranslatable(), Self::CouchbaseLite),
284284
kCBLNetworkDomain => {

src/fleece.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ impl Fleece {
7171
pub fn parse(data: &[u8], trust: Trust) -> Result<Self> {
7272
unsafe {
7373
let copied = FLSlice_Copy(from_bytes(data).get_ref());
74-
let doc = FLDoc_FromResultData(copied, trust as u32, ptr::null_mut(), NULL_SLICE);
74+
let doc = FLDoc_FromResultData(copied, trust as i32, ptr::null_mut(), NULL_SLICE);
7575
if doc.is_null() {
7676
return Err(Error::fleece_error(FLError_kFLInvalidData));
7777
}

src/fleece_mutable.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ impl MutableArray {
8080
pub fn from_array_(array: &Array, flags: CopyFlags) -> Self {
8181
unsafe {
8282
Self {
83-
cbl_ref: FLArray_MutableCopy(array.get_ref(), flags as u32),
83+
cbl_ref: FLArray_MutableCopy(array.get_ref(), flags as i32),
8484
}
8585
}
8686
}
@@ -274,7 +274,7 @@ impl MutableDict {
274274
pub fn from_dict_(dict: &Dict, flags: CopyFlags) -> Self {
275275
unsafe {
276276
Self {
277-
cbl_ref: FLDict_MutableCopy(dict.get_ref(), flags as u32),
277+
cbl_ref: FLDict_MutableCopy(dict.get_ref(), flags as i32),
278278
}
279279
}
280280
}

src/replicator.rs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ pub enum ReplicatorType {
170170

171171
impl From<CBLReplicatorType> for ReplicatorType {
172172
fn from(repl_type: CBLReplicatorType) -> Self {
173-
match u32::from(repl_type) {
173+
match i32::from(repl_type) {
174174
kCBLReplicatorTypePushAndPull => Self::PushAndPull,
175175
kCBLReplicatorTypePush => Self::Push,
176176
kCBLReplicatorTypePull => Self::Pull,
@@ -197,7 +197,7 @@ pub enum ProxyType {
197197

198198
impl From<CBLProxyType> for ProxyType {
199199
fn from(proxy_type: CBLProxyType) -> Self {
200-
match u32::from(proxy_type) {
200+
match i32::from(proxy_type) {
201201
kCBLProxyHTTP => Self::HTTP,
202202
kCBLProxyHTTPS => Self::HTTPS,
203203
_ => unreachable!(),
@@ -297,7 +297,10 @@ unsafe extern "C" fn c_replication_pull_filter(
297297
}
298298
}
299299
fn read_document_flags(flags: CBLDocumentFlags) -> (bool, bool) {
300-
(flags & DELETED != 0, flags & ACCESS_REMOVED != 0)
300+
(
301+
flags & DELETED as u32 != 0,
302+
flags & ACCESS_REMOVED as u32 != 0,
303+
)
301304
}
302305

303306
/** Conflict-resolution callback for use in replications. This callback will be invoked
@@ -1085,7 +1088,7 @@ pub enum ReplicatorActivityLevel {
10851088

10861089
impl From<u8> for ReplicatorActivityLevel {
10871090
fn from(level: u8) -> Self {
1088-
match u32::from(level) {
1091+
match i32::from(level) {
10891092
kCBLReplicatorStopped => Self::Stopped,
10901093
kCBLReplicatorOffline => Self::Offline,
10911094
kCBLReplicatorConnecting => Self::Connecting,
@@ -1178,8 +1181,8 @@ unsafe extern "C" fn c_replicator_document_change_listener(
11781181
}
11791182

11801183
/** Flags describing a replicated document. */
1181-
pub static DELETED: u32 = kCBLDocumentFlagsDeleted;
1182-
pub static ACCESS_REMOVED: u32 = kCBLDocumentFlagsAccessRemoved;
1184+
pub static DELETED: i32 = kCBLDocumentFlagsDeleted;
1185+
pub static ACCESS_REMOVED: i32 = kCBLDocumentFlagsAccessRemoved;
11831186

11841187
/** Information about a document that's been pushed or pulled. */
11851188
pub struct ReplicatedDocument {

update_cblite_c.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ do
183183
;;
184184

185185
windows)
186-
platformFolder="${libFolder}/x86_64-pc-windows-gnu"
186+
platformFolder="${libFolder}/windows"
187187
mkdir $platformFolder
188188

189189
libFile="${unzipPlatformFolder}/libcblite-${version}/lib/cblite.lib"

0 commit comments

Comments
 (0)