This is an automated email from the ASF dual-hosted git repository.

pnoltes pushed a commit to branch feature/599-rust-hello-world-bundle
in repository https://gitbox.apache.org/repos/asf/celix.git

commit bb2c5585d1a867aa6478063a62695cceed9ea0b3
Author: Pepijn Noltes <[email protected]>
AuthorDate: Sun Jul 30 20:55:31 2023 +0200

    Add initial "hello world" rust bundle example
---
 misc/experimental/bundles/CMakeLists.txt           |  1 +
 misc/experimental/bundles/rust/CMakeLists.txt      | 43 ++++++++++++++++++++++
 .../bundles/{CMakeLists.txt => rust/Cargo.toml}    | 13 ++++---
 misc/experimental/bundles/rust/README.md           | 27 ++++++++++++++
 misc/experimental/bundles/rust/src/lib.rs          | 37 +++++++++++++++++++
 5 files changed, 115 insertions(+), 6 deletions(-)

diff --git a/misc/experimental/bundles/CMakeLists.txt 
b/misc/experimental/bundles/CMakeLists.txt
index b96038d7..10d871ac 100644
--- a/misc/experimental/bundles/CMakeLists.txt
+++ b/misc/experimental/bundles/CMakeLists.txt
@@ -20,4 +20,5 @@ if (NOT APPLE)
     add_subdirectory(config_admin)
     add_subdirectory(event_admin)
     add_subdirectory(pubsub_admin_nanomsg)
+    add_subdirectory(rust)
 endif ()
diff --git a/misc/experimental/bundles/rust/CMakeLists.txt 
b/misc/experimental/bundles/rust/CMakeLists.txt
new file mode 100644
index 00000000..68812a86
--- /dev/null
+++ b/misc/experimental/bundles/rust/CMakeLists.txt
@@ -0,0 +1,43 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+option(CELIX_RUST_EXPERIMENTAL "Enable experimental rust bundle" OFF)
+if (CELIX_RUST_EXPERIMENTAL)
+    include(FetchContent)
+    FetchContent_Declare(
+            Corrosion
+            GIT_REPOSITORY https://github.com/corrosion-rs/corrosion.git
+            GIT_TAG v0.4.2
+    )
+    FetchContent_MakeAvailable(Corrosion)
+
+    corrosion_import_crate(MANIFEST_PATH Cargo.toml)
+
+    #Note corrosion_import_crate import creates a rust_bundle_activator CMake 
target, but this is a INTERFACE target.
+    #For no using abs path to expected bundle activator lib as ACTIVATOR 
argument
+    add_celix_bundle(rust_bundle ACTIVATOR 
${CMAKE_BINARY_DIR}/misc/experimental/bundles/rust/librust_bundle_activator.so)
+    add_dependencies(rust_bundle rust_bundle_activator)
+
+    add_celix_container(rust_container
+        NO_COPY
+        BUNDLES
+            Celix::shell
+            Celix::shell_tui
+            rust_bundle
+    )
+
+endif ()
diff --git a/misc/experimental/bundles/CMakeLists.txt 
b/misc/experimental/bundles/rust/Cargo.toml
similarity index 80%
copy from misc/experimental/bundles/CMakeLists.txt
copy to misc/experimental/bundles/rust/Cargo.toml
index b96038d7..bcfb71a8 100644
--- a/misc/experimental/bundles/CMakeLists.txt
+++ b/misc/experimental/bundles/rust/Cargo.toml
@@ -15,9 +15,10 @@
 # specific language governing permissions and limitations
 # under the License.
 
-if (NOT APPLE)
-    #Note note sure if these bundles build on OSX
-    add_subdirectory(config_admin)
-    add_subdirectory(event_admin)
-    add_subdirectory(pubsub_admin_nanomsg)
-endif ()
+[package]
+name = "rust_bundle_example"
+version = "0.1.0"
+
+[lib]
+name = "rust_bundle_activator"
+crate-type = ["cdylib"]
diff --git a/misc/experimental/bundles/rust/README.md 
b/misc/experimental/bundles/rust/README.md
new file mode 100644
index 00000000..28096e8e
--- /dev/null
+++ b/misc/experimental/bundles/rust/README.md
@@ -0,0 +1,27 @@
+---
+title: Experimental
+---
+
+<!--
+Licensed to the Apache Software Foundation (ASF) under one or more
+contributor license agreements.  See the NOTICE file distributed with
+this work for additional information regarding copyright ownership.
+The ASF licenses this file to You under the Apache License, Version 2.0
+(the "License"); you may not use this file except in compliance with
+the License.  You may obtain a copy of the License at
+   
+    http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+-->
+
+# Experimental Rust Bundle 
+
+This experimental bundles shows that it is possible to write a bundle in Rust, 
it directly uses the Apache Celix C api 
+and is not intended to be used in production.
+
+Ideally Rust support in Apache Celix is done by first adding a Rust api and 
use that for Rust bundles.
diff --git a/misc/experimental/bundles/rust/src/lib.rs 
b/misc/experimental/bundles/rust/src/lib.rs
new file mode 100644
index 00000000..eb78bbd2
--- /dev/null
+++ b/misc/experimental/bundles/rust/src/lib.rs
@@ -0,0 +1,37 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+use std::os::raw::c_void;
+
+// TODO use celix_bundleActivator_create to create a bundle activator
+// pub struct RustBundleActivator {
+//     bundle_context: *mut c_void, /*TODO use bindgen to generate the correct 
ctx type*/
+// }
+
+#[no_mangle]
+pub unsafe extern "C" fn celix_bundleActivator_start(_data: *mut c_void, 
_context: *mut c_void) -> i32 {
+    println!("Rust Bundle started!");
+    0
+}
+
+#[no_mangle]
+pub unsafe extern "C" fn celix_bundleActivator_stop(_data: *mut c_void, 
_context: *mut c_void) -> i32 {
+    println!("Rust Bundle stopped!");
+    0
+}

Reply via email to