From e62b2acf8b4212b1b7dd52f1d5a46368e973aa07 Mon Sep 17 00:00:00 2001 From: Youyuan Wu Date: Sat, 18 Nov 2023 11:20:25 -0800 Subject: [PATCH] rewrite pal in rust --- .devcontainer/devcontainer.json | 6 ++- Cargo.lock | 8 ++++ Cargo.toml | 1 + bintemp/libfabric_pal.so | Bin 20232 -> 0 bytes build.rs | 26 ++++-------- crates/fabric/pal/Cargo.toml | 19 +++++++++ crates/fabric/pal/src/lib.rs | 69 ++++++++++++++++++++++++++++++++ 7 files changed, 108 insertions(+), 21 deletions(-) delete mode 100755 bintemp/libfabric_pal.so create mode 100644 crates/fabric/pal/Cargo.toml create mode 100644 crates/fabric/pal/src/lib.rs 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 26d37b1c72dee91c024a8a147dc8a04cd81faeca..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 20232 zcmeHPdvILUc|UhoE3K`^u3ol`Q@l1dn1EKY{J;hbdab+y$r5^CLm}6z-K*V&)$V2= zen8wfC{To9#wG-YRx^-CXWZ#Dz%=bZP0Aw#=pQYR(3vDnCo07=a$u-2G%*C&{=Re1 zw~woJ$aK=qbY_o7_dDP3dz^E>``B~tIiJ7k8yc`_n&4s=*9gfqnn<@2+&jP;LUfDm zq87(>Vy)DzDu|ZUMx7?aRJcu^+Hg=+@m6}b-PB{saVb@kM;?W++P$jmtaQE7 zXDVX>Z2VLv^gn5DRN3V_!W~lde$^gRZtn)z$#^RH=MlclW8B_(u7lwCE2_dP<4Hc~ zp4qi~lGL83zNp(o%3Bmq^7U7Az5M9ONB19{e)H@D_qm^0obg2krhWGv{kpiEWYkU*{$Bcq|B8>#Jf~m%&+m1{uYc$E3r}u(E$rU&h^>C_%fGGr zi%Y(8&%F=)s_NdRpFi>5^>6*^E{`kx=^B`oEe`@EpVsnS0OfG%gU6~2{xtr|>ECr8 zoZ{!fpS8pRl=E{raF10P`~d#emBHtLHHikXK{?x`bY4^V6AEuucs)8q`s)<1R^eHt zA6EKbQ1}^zFDQJ2!e3PQqY7W4@JWR~quyUGh5tg~FDm^D6`oVLL-ps66uwIJvrpk& z3jbTBKWl0C5ryBVaMipBDg0Fh+^YNtT@TMB;(9t0NM&?g=z|l(ddNr_;b=Nzq$Y;@ zVu`ph5txb@rmVa~4;~EY)6sY!7QMp|yNt|eDiJi&X}=Lj3Oe+}Vu_%b2}m+-WQGFi zj4zc+q{NIdlQuF^X&_}7Vww){P|(nIBbACLba)74qKP<3rR`vRIw9b!zzih=Ci( zRM4AFc(+k)Ixv-r2K8hh21x808tm=UyS!cAtrS$7e5UzGymsDyLP|E`8q;$|C3``1 z8QJs!lSRGf`Mvz4x_(Xzo>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 @@ 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 +}