Skip to content
This repository has been archived by the owner on Sep 11, 2024. It is now read-only.

Linux compatibility: Guard Windows-only modules with cfg macro #153

Merged
merged 4 commits into from
Oct 20, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions .github/workflows/ci-workflow.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: Build and Test

on:
on:
pull_request:
push:
branches:
Expand All @@ -11,10 +11,11 @@ env:

jobs:
test:
runs-on: windows-latest
strategy:
matrix:
strategy:
matrix:
rust: [1.42.0, stable]
os: [windows-latest, ubuntu-latest]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v2
- uses: actions-rs/toolchain@v1
Expand All @@ -25,8 +26,8 @@ jobs:
components: rustfmt

- name: tests
run: cargo test --all
run: cargo test --all

- name: fmt
if: matrix.rust == 'stable'
run: cargo fmt --all -- --check
if: matrix.rust == 'stable'
19 changes: 12 additions & 7 deletions examples/basic/client/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
use com::{
interfaces::iclass_factory::IClassFactory,
interfaces::iunknown::IUnknown,
runtime::{create_instance, get_class_object, init_apartment, ApartmentType},
};
use interface::{Food, IAnimal, ICat, IDomesticAnimal, IExample, CLSID_CAT_CLASS};

fn main() {
#[cfg(windows)]
run()
}

#[cfg(windows)]
fn run() {
use com::{
interfaces::iclass_factory::IClassFactory,
interfaces::iunknown::IUnknown,
runtime::{create_instance, get_class_object, init_apartment, ApartmentType},
};
use interface::{Food, IAnimal, ICat, IDomesticAnimal, IExample, CLSID_CAT_CLASS};
// Initialize the COM apartment
init_apartment(ApartmentType::SingleThreaded)
.unwrap_or_else(|hr| panic!("Failed to initialize COM Library{:x}", hr));
Expand Down
2 changes: 2 additions & 0 deletions examples/basic/server/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![cfg(windows)]

mod british_short_hair_cat;

use british_short_hair_cat::BritishShortHairCat;
Expand Down
32 changes: 17 additions & 15 deletions examples/basic/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,23 @@ fn main() {
return;
}

let mut child_proc = Command::new("cmd")
.args(&["/C", "regsvr32 /s ../../target/release/server.dll"])
.spawn()
.expect("Something went wrong!");
if !child_proc.wait().unwrap().success() {
println!("Failed to register server.dll! Make sure you have administrator rights!");
return;
}
if cfg!(windows) {
let mut child_proc = Command::new("cmd")
.args(&["/C", "regsvr32 /s ../../target/release/server.dll"])
.spawn()
.expect("Something went wrong!");
if !child_proc.wait().unwrap().success() {
println!("Failed to register server.dll! Make sure you have administrator rights!");
return;
}

let mut child_proc = Command::new("cmd")
.args(&["/C", "cargo run --release --package client"])
.spawn()
.expect("Something went wrong!");
if !child_proc.wait().unwrap().success() {
println!("Execution of client failed.");
return;
let mut child_proc = Command::new("cmd")
.args(&["/C", "cargo run --release --package client"])
.spawn()
.expect("Something went wrong!");
if !child_proc.wait().unwrap().success() {
println!("Execution of client failed.");
return;
}
}
}
Loading