Skip to content

Commit

Permalink
sample
Browse files Browse the repository at this point in the history
  • Loading branch information
kennykerr committed May 23, 2024
1 parent 2850a0b commit 6ae2905
Show file tree
Hide file tree
Showing 7 changed files with 96 additions and 4 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/clippy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ jobs:
run: cargo clippy -p sample_component_json_validator_winrt
- name: Clippy sample_component_json_validator_winrt_client
run: cargo clippy -p sample_component_json_validator_winrt_client
- name: Clippy sample_component_json_validator_winrt_client_cpp
run: cargo clippy -p sample_component_json_validator_winrt_client_cpp
- name: Clippy sample_consent
run: cargo clippy -p sample_consent
- name: Clippy sample_core_app
Expand Down
10 changes: 6 additions & 4 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ jobs:
run: cargo test -p sample_component_json_validator_winrt --target ${{ matrix.target }} ${{ matrix.etc }}
- name: Test sample_component_json_validator_winrt_client
run: cargo test -p sample_component_json_validator_winrt_client --target ${{ matrix.target }} ${{ matrix.etc }}
- name: Test sample_component_json_validator_winrt_client_cpp
run: cargo test -p sample_component_json_validator_winrt_client_cpp --target ${{ matrix.target }} ${{ matrix.etc }}
- name: Test sample_consent
run: cargo test -p sample_consent --target ${{ matrix.target }} ${{ matrix.etc }}
- name: Test sample_core_app
Expand Down Expand Up @@ -154,10 +156,10 @@ jobs:
run: cargo test -p test_alternate_success_code --target ${{ matrix.target }} ${{ matrix.etc }}
- name: Test test_arch
run: cargo test -p test_arch --target ${{ matrix.target }} ${{ matrix.etc }}
- name: Test test_arch_feature
run: cargo test -p test_arch_feature --target ${{ matrix.target }} ${{ matrix.etc }}
- name: Clean
run: cargo clean
- name: Test test_arch_feature
run: cargo test -p test_arch_feature --target ${{ matrix.target }} ${{ matrix.etc }}
- name: Test test_array
run: cargo test -p test_array --target ${{ matrix.target }} ${{ matrix.etc }}
- name: Test test_bcrypt
Expand Down Expand Up @@ -256,10 +258,10 @@ jobs:
run: cargo test -p test_standalone --target ${{ matrix.target }} ${{ matrix.etc }}
- name: Test test_string_param
run: cargo test -p test_string_param --target ${{ matrix.target }} ${{ matrix.etc }}
- name: Test test_structs
run: cargo test -p test_structs --target ${{ matrix.target }} ${{ matrix.etc }}
- name: Clean
run: cargo clean
- name: Test test_structs
run: cargo test -p test_structs --target ${{ matrix.target }} ${{ matrix.etc }}
- name: Test test_sys
run: cargo test -p test_sys --target ${{ matrix.target }} ${{ matrix.etc }}
- name: Test test_targets
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
/target
*.lock
*.winmd
winrt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
[package]
name = "sample_component_json_validator_winrt_client_cpp"
version = "0.0.0"
edition = "2021"
publish = false

[build-dependencies]
cc = "1.0"

[build-dependencies.cppwinrt]
path = "../../../../crates/libs/cppwinrt"

[dependencies.windows-targets]
path = "../../../../crates/libs/targets"

# TODO: this causes a warning about lack of linkage target. The point is to ensure that this binary dependency is built first but
# Cargo doesn't respect cdylib targets. https://github.com/rust-lang/cargo/issues/7825
[dependencies.sample_component_json_validator_winrt]
path = "../json_validator_winrt"
23 changes: 23 additions & 0 deletions crates/samples/components/json_validator_winrt_client_cpp/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
fn main() {
if !cfg!(target_env = "msvc") {
return;
}

println!("cargo:rerun-if-changed=src/client.cpp");
println!("cargo:rustc-link-lib=windows.0.52.0");

cppwinrt::cppwinrt([
"-in",
"../json_validator_winrt/sample.winmd",
&format!("{}\\System32\\WinMetadata", env!("windir")),
"-out",
"src",
])
.unwrap();

cc::Build::new()
.cpp(true)
.std("c++20")
.file("src/client.cpp")
.compile("client");
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#include "winrt/Sample.h"

using namespace winrt::Sample;

extern "C" {
void __stdcall client() {
auto schema = LR"(
{
"properties": {
"name": {
"type": "string"
},
"age": {
"type": "integer"
}
}
}
)";

auto value = LR"(
{
"name": "Kenny",
"age": 21
}
)";

// Create a validator with the given schema.
auto validator = JsonValidator(schema);

// Validate and check the sanitized return value.
auto sanitized = validator.Validate(value);
assert(sanitized == LR"({"age":21,"name":"Kenny"})");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#![cfg(target_env = "msvc")]

#[test]
fn test() {
extern "system" {
fn client();
}
unsafe {
client();
}
}

0 comments on commit 6ae2905

Please sign in to comment.