diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index 278a45a6..e590ab77 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -22,9 +22,11 @@ "customizations": { "vscode": { - "extensions": ["ms-vscode.cpptools-extension-pack"] + "extensions": [ + "ms-vscode.cpptools-extension-pack", + "rust-lang.rust-analyzer"] } - }, + } // Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root. // "remoteUser": "root" diff --git a/Cargo.lock b/Cargo.lock index 423d534e..826962ff 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -166,6 +166,13 @@ dependencies = [ "libc", ] +[[package]] +name = "pal" +version = "0.1.0" +dependencies = [ + "windows", +] + [[package]] name = "parking_lot" version = "0.12.1" @@ -284,6 +291,7 @@ name = "service-fabric-rs" version = "0.0.2" dependencies = [ "fabric-metadata", + "pal", "windows", ] diff --git a/Cargo.toml b/Cargo.toml index b781e06b..8b06e54f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -23,6 +23,7 @@ targets = [] [dependencies] fabric-metadata = { git = "https://github.com/youyuanwu/fabric-metadata.git", rev = "2e6a471c7752148c4dc8d0968c0f1161c2a6c76a"} +pal = { path = "./crates/fabric/pal" } [dependencies.windows] version = "0.43" diff --git a/bintemp/libfabric_pal.so b/bintemp/libfabric_pal.so deleted file mode 100755 index 26d37b1c..00000000 Binary files a/bintemp/libfabric_pal.so and /dev/null differ diff --git a/build.rs b/build.rs index 1dff69a9..876b2920 100644 --- a/build.rs +++ b/build.rs @@ -1,28 +1,16 @@ use std::path::Path; fn main() { - // add link dir for fabric support libs. This is propagated to downstream targets - // let dir = String::from("build\\_deps\\fabric_metadata-build\\src"); - // let package_root = env::var("CARGO_MANIFEST_DIR").unwrap(); - // let abs_dir = package_root + &dir; - // println!( - // "cargo:rustc-link-search=native={}", - // Path::new(&abs_dir).display() - // ); - - // add link dir for fabric support libs. This is propagated to downstream targets + if cfg!(unix) { + // Add link dir for fabric libs on linux. let dir = String::from("/opt/microsoft/servicefabric/bin/Fabric/Fabric.Code/"); println!( "cargo:rustc-link-search={}", Path::new(&dir).display() ); - let dir2 = String::from("/workspaces/service-fabric-rs/bintemp"); - println!( - "cargo:rustc-link-search={}", - Path::new(&dir2).display() - ); - // println!("cargo:rustc-link-lib=dylib=FabricCommon"); - // println!("cargo:rustc-link-lib=dylib=FabricResources"); - // pal - println!("cargo:rustc-link-lib=dylib=fabric_pal"); + + // On linux, for windows-rs to work we need have a pal shared lib. + // No need to have search dir since it is in the target dir + println!("cargo:rustc-link-lib=dylib=fabric_rust_pal"); + } } diff --git a/crates/fabric/pal/Cargo.toml b/crates/fabric/pal/Cargo.toml new file mode 100644 index 00000000..56834b72 --- /dev/null +++ b/crates/fabric/pal/Cargo.toml @@ -0,0 +1,19 @@ +[package] +name = "pal" +version = "0.1.0" +edition = "2021" + + +[lib] +name = "fabric_rust_pal" +path = "src/lib.rs" +crate-type = ["cdylib"] + + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies.windows] +version = "0.43" +features = [ + "Win32_Foundation" +] diff --git a/crates/fabric/pal/src/lib.rs b/crates/fabric/pal/src/lib.rs new file mode 100644 index 00000000..67ed1140 --- /dev/null +++ b/crates/fabric/pal/src/lib.rs @@ -0,0 +1,69 @@ +#[allow( + non_camel_case_types, + non_snake_case, + dead_code)] + +use std::ffi::c_void; + +use windows::core::{HRESULT, PCSTR, PWSTR}; + + +#[no_mangle] +pub unsafe extern "system" fn GetLastError() -> u32 { + 0 +} + +#[no_mangle] +pub unsafe extern "system" fn GetProcessHeap() -> isize{ + 0 +} + +#[no_mangle] +pub unsafe extern "system" fn HeapAlloc(_heap: isize, _flags: u32, _len: usize) -> *mut c_void{ + std::ptr::null_mut() +} + +#[no_mangle] +pub unsafe extern "system" fn HeapFree(_heap: isize, _flags: u32, _ptr: *const c_void) -> i32{ + 0 +} + +#[no_mangle] +pub unsafe extern "system" fn GetErrorInfo(_reserved: u32, _info: *mut *mut c_void) -> HRESULT{ + HRESULT(0) +} + +#[no_mangle] +pub unsafe extern "system" fn SetErrorInfo(_reserved: u32, _info: *const c_void) -> HRESULT{ + HRESULT(0) +} + +#[no_mangle] +pub unsafe extern "system" fn LoadLibraryA(_name: PCSTR) -> isize{ + 0 +} + +#[no_mangle] +pub unsafe extern "system" fn FreeLibrary(_library: isize) -> i32{ + 0 +} + +#[no_mangle] +pub unsafe extern "system" fn GetProcAddress(_library: isize, _name: PCSTR) -> *const c_void{ + std::ptr::null() +} + +#[no_mangle] +pub unsafe extern "system" fn SysFreeString(_bstr: *const u16){ + +} + +#[no_mangle] +pub unsafe extern "system" fn SysStringLen(_bstr: *const u16) -> u32{ + 0 +} + +#[no_mangle] +pub unsafe extern "system" fn FormatMessageW(_flags: u32, _source: *const c_void, _code: u32, _lang: u32, _buffer: PWSTR, _len: u32, _args: *const *const i8) -> u32{ + 0 +}