Skip to content

Commit

Permalink
squash linux work
Browse files Browse the repository at this point in the history
  • Loading branch information
youyuanwu committed Nov 19, 2023
1 parent f67bf95 commit f6b5a90
Show file tree
Hide file tree
Showing 19 changed files with 310 additions and 78 deletions.
4 changes: 4 additions & 0 deletions .cargo/config.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[target.x86_64-unknown-linux-gnu]
rustflags = [
"-C", "link-arg=-fuse-ld=lld",
]
28 changes: 28 additions & 0 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
FROM ubuntu:20.04

RUN apt-get update && apt-get upgrade

# install sf
RUN apt-get install apt-transport-https curl lsb-release wget gnupg2 software-properties-common debconf-utils -y

RUN wget -q https://packages.microsoft.com/config/ubuntu/$(lsb_release -rs)/packages-microsoft-prod.deb \
&& dpkg -i packages-microsoft-prod.deb \
&& curl -fsSL https://packages.microsoft.com/keys/msopentech.asc | apt-key add - \
&& curl -fsSL https://download.docker.com/linux/ubuntu/gpg | apt-key add - \
&& add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" \
&& apt-get update

RUN echo "servicefabric servicefabric/accepted-eula-ga select true" | debconf-set-selections \
&& echo "servicefabricsdkcommon servicefabricsdkcommon/accepted-eula-ga select true" | debconf-set-selections \
&& apt-get install servicefabricsdkcommon -y

# install rust
RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs > ./rustup.sh
RUN chmod u+x ./rustup.sh && ./rustup.sh -y

# more tools
RUN apt-get install cmake git -y
RUN apt-get install clang lld -y

# expose sf shared libs
ENV LD_LIBRARY_PATH "$LD_LIBRARY_PATH:/opt/microsoft/servicefabric/bin/Fabric/Fabric.Code:/workspaces/service-fabric-rs/bintemp"
33 changes: 33 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// For format details, see https://aka.ms/devcontainer.json. For config options, see the
// README at: https://github.com/devcontainers/templates/tree/main/src/cpp
{
"name": "C++",
"build": {
"dockerfile": "Dockerfile"
},

// "image" : "fabric-metadata:v1",

// Features to add to the dev container. More info: https://containers.dev/features.
// "features": {},

// Use 'forwardPorts' to make a list of ports inside the container available locally.
// "forwardPorts": [],

// Use 'postCreateCommand' to run commands after the container is created.
// "postCreateCommand": "gcc -v",

// Configure tool-specific properties.
// "customizations": {},

"customizations": {
"vscode": {
"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"
}
18 changes: 14 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ endif()
# generate rust code
find_program (
cargo_exe
NAMES cargo.exe
NAMES cargo.exe cargo
REQUIRED
)

Expand All @@ -48,7 +48,7 @@ add_custom_target(build_rust
add_custom_target(build_rust_sample_client ALL
COMMAND ${cargo_exe} build -p samples_client
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
DEPENDS generate_import_libs
#DEPENDS generate_import_libs
)

add_custom_target(run_rust_sample_client
Expand All @@ -65,12 +65,22 @@ add_custom_target(force_clean
add_custom_target(build_rust_sample_echomain ALL
COMMAND ${cargo_exe} build -p samples_echomain
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
DEPENDS generate_import_libs
#DEPENDS generate_import_libs
)

set(_pkg_root ${CMAKE_BINARY_DIR}/echoapp_root)
set(_pkg_src ${CMAKE_CURRENT_SOURCE_DIR}/crates/samples/echomain)
set(_pkg_exe ${CMAKE_CURRENT_SOURCE_DIR}/target/debug/samples_echomain.exe)
if(WIN32)
set(_pkg_exe ${CMAKE_CURRENT_SOURCE_DIR}/target/debug/samples_echomain.exe)
else()
set(_pkg_exe ${CMAKE_CURRENT_SOURCE_DIR}/target/debug/samples_echomain)
set(_pal_so ${CMAKE_CURRENT_SOURCE_DIR}/bintemp/libfabric_pal.so)
add_custom_command(TARGET build_rust_sample_echomain POST_BUILD
COMMAND ${CMAKE_COMMAND} -E make_directory ${_pkg_root}
COMMAND ${CMAKE_COMMAND}
-E copy_if_different ${_pal_so} ${_pkg_root}/EchoAppServicePackage/Code/libfabric_pal.so
)
endif(WIN32)
add_custom_command(TARGET build_rust_sample_echomain POST_BUILD
COMMAND ${CMAKE_COMMAND} -E make_directory ${_pkg_root}
COMMAND ${CMAKE_COMMAND}
Expand Down
79 changes: 72 additions & 7 deletions Cargo.lock

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

5 changes: 3 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,12 @@ members = [
]

[package.metadata.docs.rs]
default-target = "x86_64-pc-windows-msvc"
# default-target = "x86_64-pc-windows-msvc"
targets = []

[dependencies]
fabric-metadata = { git = "https://github.com/youyuanwu/fabric-metadata.git", rev = "9d62ca15573a0716fb9828dce03a489ae4b8a4a7"}
fabric-metadata = { git = "https://github.com/youyuanwu/fabric-metadata.git", rev = "2e6a471c7752148c4dc8d0968c0f1161c2a6c76a"}
pal = { path = "./crates/fabric/pal" }
windows-core = "0.51"

[dependencies.windows]
Expand Down
22 changes: 13 additions & 9 deletions build.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
//use std::{path::Path, env};
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()
// );
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()
);

// 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");
}
}
18 changes: 5 additions & 13 deletions crates/fabric/ext/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,8 @@

pub mod fasync;

use std::os::windows::prelude::OsStrExt;
use std::{
ffi::OsString,
sync::{Arc, Condvar, Mutex},
};
//use std::os::windows::prelude::OsStrExt;
use std::sync::{Arc, Condvar, Mutex};

use log::info;
use service_fabric_rs::FabricCommon::{
Expand All @@ -21,7 +18,7 @@ use service_fabric_rs::FabricCommon::{
IFabricAsyncOperationContext_Impl, IFabricStringResult, IFabricStringResult_Impl,
};
use windows::core::implement;
use windows_core::PCWSTR;
use windows_core::{HSTRING, PCWSTR};

// Interface for waitable async callback.
// This is a common use case to combine fabric Begin* and End* apis.
Expand Down Expand Up @@ -144,13 +141,8 @@ pub struct StringResult {
}

impl StringResult {
pub fn new(data: OsString) -> StringResult {
let data_vec = data
.as_os_str()
.encode_wide()
.chain(Some(0))
.collect::<Vec<_>>();
let ret = StringResult { vec_: data_vec };
pub fn new(data: HSTRING) -> StringResult {
let ret = StringResult { vec_: data.as_wide().to_vec() };
return ret;
}
}
Expand Down
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"
]
2 changes: 2 additions & 0 deletions crates/fabric/pal/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#[cfg(unix)]
pub mod pal;
Loading

0 comments on commit f6b5a90

Please sign in to comment.