Skip to content

Commit

Permalink
rewrite pal in rust
Browse files Browse the repository at this point in the history
  • Loading branch information
youyuanwu committed Nov 18, 2023
1 parent 9284f58 commit e62b2ac
Show file tree
Hide file tree
Showing 7 changed files with 108 additions and 21 deletions.
6 changes: 4 additions & 2 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
8 changes: 8 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Binary file removed bintemp/libfabric_pal.so
Binary file not shown.
26 changes: 7 additions & 19 deletions build.rs
Original file line number Diff line number Diff line change
@@ -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");
}
}
19 changes: 19 additions & 0 deletions crates/fabric/pal/Cargo.toml
Original file line number Diff line number Diff line change
@@ -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"
]
69 changes: 69 additions & 0 deletions crates/fabric/pal/src/lib.rs
Original file line number Diff line number Diff line change
@@ -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
}

0 comments on commit e62b2ac

Please sign in to comment.