Skip to content

Commit

Permalink
Fix compilation issues with MSVC 2022.
Browse files Browse the repository at this point in the history
  • Loading branch information
Danny committed Mar 3, 2024
1 parent 3d02a82 commit f9fa5f9
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 20 deletions.
18 changes: 18 additions & 0 deletions build.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,24 @@
use std::env;

fn main() {
// For the MSVC compiler, it seems that (at least with VS2022) the
// browser-window-c crate gets compiled with the x86 target. Not sure how to
// prevent that, but adding the browser-window-c static lib to the linker at
// least shows a meaningful error message.
let target = env::var("TARGET").unwrap();
if target.ends_with("msvc") {
println!("cargo:rustc-link-lib=static=browser-window-c");

if target.starts_with("x86_64") {
println!(
"cargo:warning=There seems to be a bug in rust/cargo when compiling with MSVC for \
x86_64. If compiling for x86_64 doesn't work, try using target \
`i686-pc-windows-msvc` instead."
);
}
}

// Make sure one of the browser frameworks is actually selected.
if env::var("DOCS_RS").is_err()
&& !cfg!(feature = "cef")
&& !cfg!(feature = "webkitgtk")
Expand Down
5 changes: 4 additions & 1 deletion c/src/application/edge2.c
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
#include "edge2.h"
#include "impl.h"
#include "../common.h"

#include <windows.h>


void bw_ApplicationEngineImpl_free( bw_ApplicationEngineImpl* ) {}
void bw_ApplicationEngineImpl_free(bw_ApplicationEngineImpl* app) {
UNUSED(app);
}

bw_Err bw_ApplicationEngineImpl_initialize( bw_ApplicationEngineImpl* impl, bw_Application* app, int argc, char** argv, const bw_ApplicationSettings* settings ) {
CoInitializeEx(NULL, COINIT_APARTMENTTHREADED);
Expand Down
4 changes: 2 additions & 2 deletions c/src/application/win32.c
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ bw_ApplicationTimerMapEntry* bw_ApplicationWin32_findInTimerMap(UINT_PTR timer_i
return entry;
}

void bw_ApplicationImpl_free(bw_ApplicationImpl*) {}
void bw_ApplicationImpl_free(bw_ApplicationImpl* app) {}

void bw_ApplicationWin32_freeTimerMap() {
bw_ApplicationTimerMapEntry* entry = timer_map;
Expand Down Expand Up @@ -174,7 +174,7 @@ bool bw_ApplicationWin32_removeFromTimerMap(bw_ApplicationTimerMapEntry* entry)
}

void bw_ApplicationWin32_setTimer(bw_Application* app, bw_ApplicationDispatchData* dispatch_data, uint64_t delay) {
UINT_PTR timer_id = SetTimer(0, 0, delay, (TIMERPROC)bw_ApplicationWin32_timerHandler);
UINT_PTR timer_id = SetTimer(0, 0, (UINT)delay, (TIMERPROC)bw_ApplicationWin32_timerHandler);

bw_ApplicationWin32_addToTimerMap(app, timer_id, dispatch_data);
}
Expand Down
4 changes: 1 addition & 3 deletions c/src/application/win32.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@
extern "C" {
#endif

#include <synchapi.h>
#include <windef.h>
#include <winuser.h>
#include <windows.h>



Expand Down
9 changes: 8 additions & 1 deletion c/src/win32.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,19 @@ extern "C" {
#endif

#include <assert.h>
#include <windef.h>

#include "err.h"
#include "string.h"


// Some definitions as defined in windef.h:
// https://learn.microsoft.com/en-us/windows/win32/winprog/windows-data-types
// Because including windef.h with MinGW can cause some issues
typedef unsigned char BYTE;
typedef unsigned long DWORD;
typedef long HRESULT;
typedef wchar_t WCHAR;


#define BW_WIN32_PANIC_LAST_ERROR \
{ bw_win32_print_error( GetLastError() ); assert(0); }
Expand Down
7 changes: 1 addition & 6 deletions c/src/window/win32.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,9 @@
extern "C" {
#endif

#include "../win32.h"
#include <stdbool.h>

// Some definitions as defined in windef.h:
// https://learn.microsoft.com/en-us/windows/win32/winprog/windows-data-types
// Because including windef.h with MinGW can cause some issues
typedef unsigned char BYTE;
typedef unsigned long DWORD;


typedef struct bw_Window bw_Window;
typedef void (*bw_WindowDispatchFn)( bw_Window* window, void* data );
Expand Down
15 changes: 8 additions & 7 deletions src/core/browser_window/edge2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,7 @@ impl BrowserWindowExt for BrowserWindowImpl {
}
}

fn navigate(&self, uri: &str) {
self.webview().navigate(uri);
}
fn navigate(&self, uri: &str) { self.webview().navigate(uri); }

fn new(
app: ApplicationImpl, parent: WindowImpl, source: Source, title: &str, width: Option<u32>,
Expand Down Expand Up @@ -178,10 +176,13 @@ fn dispatch_eval_js(_app: ApplicationImpl, dispatch_data: *mut ()) {
let callback = data.callback.clone();
let handle = data.handle.clone();
let callback_data = data.data.clone();
handle.clone().webview().execute_script(&data.code, move |result| {
callback(handle, callback_data, Ok(JsValue::Other(result)));
Ok(())
});
handle
.clone()
.webview()
.execute_script(&data.code, move |result| {
callback(handle, callback_data, Ok(JsValue::Other(result)));
Ok(())
});
}

unsafe extern "C" fn ffi_handler(
Expand Down

0 comments on commit f9fa5f9

Please sign in to comment.