From bd72844b8b01669cf39e43f3dd692c2e04310ea4 Mon Sep 17 00:00:00 2001 From: southorange0929 Date: Tue, 4 Jun 2024 09:57:33 +0800 Subject: [PATCH] feat: add example code --- .taplo.toml | 2 +- Cargo.toml | 8 ++++++-- crates/hilog/Cargo.toml | 2 +- crates/hilog/src/lib.rs | 20 ++++++++++---------- examples/.gitignore | 8 ++++++++ examples/Cargo.toml | 23 +++++++++++++++++++++++ examples/build.rs | 3 +++ examples/src/hilog.rs | 12 ++++++++++++ examples/src/lib.rs | 1 + 9 files changed, 65 insertions(+), 14 deletions(-) create mode 100755 examples/.gitignore create mode 100755 examples/Cargo.toml create mode 100755 examples/build.rs create mode 100644 examples/src/hilog.rs create mode 100755 examples/src/lib.rs diff --git a/.taplo.toml b/.taplo.toml index 71b6be1..3d21ba4 100644 --- a/.taplo.toml +++ b/.taplo.toml @@ -1,4 +1,4 @@ -include = ["Cargo.toml", "crates/**/*.toml", "tools/**/*.toml", "sys/**/*.toml", "taplo.toml", ".typos.toml"] +include = ["Cargo.toml", "crates/**/*.toml", "tools/**/*.toml", "sys/**/*.toml", "taplo.toml", ".typos.toml","examples/*.toml"] [formatting] align_entries = true diff --git a/Cargo.toml b/Cargo.toml index a55bb3e..cd8002a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,12 +1,16 @@ [workspace] -members = ["crates/*", "sys/*", "tools/*"] +members = ["crates/*", "sys/*", "tools/*", "examples"] resolver = "2" [workspace.dependencies] ohos-bundle-binding = { version = "0.0.1", path = "crates/bundle" } ohos-init-binding = { version = "0.0.3", path = "crates/init" } -ohos-hilog-binding = { version = "0.0.2", path = "crates/hilog" } +ohos-hilog-binding = { version = "0.0.3", path = "crates/hilog" } ohos-bundle-sys = { version = "0.0.1", path = "sys/ohos-bundle-sys" } ohos-init-sys = { version = "0.0.1", path = "sys/ohos-init-sys" } ohos-hilogs-sys = { version = "0.0.1", path = "sys/ohos-hilogs-sys" } + +napi-ohos = { version = "1.0.0-beta.2" } +napi-derive-ohos = { version = "1.0.0-beta.2" } +napi-build-ohos = { version = "1.0.0-beta.2" } diff --git a/crates/hilog/Cargo.toml b/crates/hilog/Cargo.toml index 42e801b..dc7dccb 100644 --- a/crates/hilog/Cargo.toml +++ b/crates/hilog/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "ohos-hilog-binding" -version = "0.0.2" +version = "0.0.3" edition = "2021" license = "MIT OR Apache-2.0" description = "hilog binding for rust" diff --git a/crates/hilog/src/lib.rs b/crates/hilog/src/lib.rs index ea9e8c2..015dcd2 100644 --- a/crates/hilog/src/lib.rs +++ b/crates/hilog/src/lib.rs @@ -77,49 +77,49 @@ log_factory!(fatal, LogLevel::LogFatal.into()); #[macro_export] macro_rules! hilog_debug { ($info: expr) => { - hilog_binding::debug($info, None); + ohos_hilog_binding::debug($info, None); }; ($info: expr,$option: expr) => { - hilog_binding::debug($info, Some($option)); + ohos_hilog_binding::debug($info, Some($option)); }; } #[macro_export] macro_rules! hilog_info { ($info: expr) => { - hilog_binding::info($info, None); + ohos_hilog_binding::info($info, None); }; ($info: expr,$option: expr) => { - hilog_binding::info($info, Some($option)); + ohos_hilog_binding::info($info, Some($option)); }; } #[macro_export] macro_rules! hilog_warn { ($info: expr) => { - hilog_binding::warn($info, None); + ohos_hilog_binding::warn($info, None); }; ($info: expr,$option: expr) => { - hilog_binding::warn($info, Some($option)); + ohos_hilog_binding::warn($info, Some($option)); }; } #[macro_export] macro_rules! hilog_error { ($info: expr) => { - hilog_binding::error($info, None); + ohos_hilog_binding::error($info, None); }; ($info: expr,$option: expr) => { - hilog_binding::error($info, Some($option)); + ohos_hilog_binding::error($info, Some($option)); }; } #[macro_export] macro_rules! hilog_fatal { ($info: expr) => { - hilog_binding::fatal($info, None); + ohos_hilog_binding::fatal($info, None); }; ($info: expr,$option: expr) => { - hilog_binding::fatal($info, Some($option)); + ohos_hilog_binding::fatal($info, Some($option)); }; } diff --git a/examples/.gitignore b/examples/.gitignore new file mode 100755 index 0000000..5194bdb --- /dev/null +++ b/examples/.gitignore @@ -0,0 +1,8 @@ +dist/ +target/ +.DS_Store +.idea/ + +*.har + +Cargo.lock diff --git a/examples/Cargo.toml b/examples/Cargo.toml new file mode 100755 index 0000000..fd93fcb --- /dev/null +++ b/examples/Cargo.toml @@ -0,0 +1,23 @@ +[package] +name = "examples" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[lib] +crate-type = ["cdylib"] + +[dependencies] +napi-ohos = { workspace = true } +napi-derive-ohos = { workspace = true } + +ohos-hilog-binding = { workspace = true } +ohos-bundle-binding = { workspace = true } +ohos-init-binding = { workspace = true } + +[build-dependencies] +napi-build-ohos = { workspace = true } + +[profile.release] +lto = true diff --git a/examples/build.rs b/examples/build.rs new file mode 100755 index 0000000..a6e4623 --- /dev/null +++ b/examples/build.rs @@ -0,0 +1,3 @@ +fn main() { + napi_build_ohos::setup(); +} diff --git a/examples/src/hilog.rs b/examples/src/hilog.rs new file mode 100644 index 0000000..5e65206 --- /dev/null +++ b/examples/src/hilog.rs @@ -0,0 +1,12 @@ +use napi_derive_ohos::napi; +use ohos_hilog_binding::{hilog_info, hilog_warn}; + +#[napi] +pub fn hi_log_info() { + hilog_info!("hello rust"); +} + +#[napi] +pub fn hi_log_warn() { + hilog_warn!("hello rust"); +} diff --git a/examples/src/lib.rs b/examples/src/lib.rs new file mode 100755 index 0000000..a29b89a --- /dev/null +++ b/examples/src/lib.rs @@ -0,0 +1 @@ +pub mod hilog;