Skip to content

Commit

Permalink
Merge pull request apache#600 from apache/feature/599-rust-hello-worl…
Browse files Browse the repository at this point in the history
…d-bundle

Feature/599 rust hello world bundle
  • Loading branch information
pnoltes authored Aug 1, 2023
2 parents 2683e8b + 5d8f5bb commit 88bec1d
Show file tree
Hide file tree
Showing 7 changed files with 170 additions and 1 deletion.
3 changes: 2 additions & 1 deletion misc/experimental/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,5 @@
celix_subproject(EXPERIMENTAL "Options to enable building the experimental - non stable - bundles/libraries. " OFF)
if (EXPERIMENTAL)
add_subdirectory(bundles)
endif ()
add_subdirectory(rust)
endif ()
18 changes: 18 additions & 0 deletions misc/experimental/rust/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# 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.

Cargo.lock
45 changes: 45 additions & 0 deletions misc/experimental/rust/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# 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)
corrosion_add_target_local_rustflags(rust_bundle_activator "-Cprefer-dynamic")

#Note corrosion_import_crate import creates a rust_bundle_activator CMake target, but this is a INTERFACE target.
#Using the INTERFACE_LINK_LIBRARIES property we can get the actual target.
get_target_property(ACTUAL_LIB_TARGET rust_bundle_activator INTERFACE_LINK_LIBRARIES)
add_celix_bundle(rust_bundle ACTIVATOR ${ACTUAL_LIB_TARGET})
add_dependencies(rust_bundle rust_bundle_activator)

add_celix_container(rust_container
NO_COPY
BUNDLES
Celix::shell
Celix::shell_tui
rust_bundle
)

endif ()
21 changes: 21 additions & 0 deletions misc/experimental/rust/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# 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.

[workspace]
members = [
"hello_world_activator",
]
28 changes: 28 additions & 0 deletions misc/experimental/rust/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
---
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 is done by adding a Rust API for Apache Celix and use that API for Rust bundles, the current
implementation only shows that is possible to write a bundle in Rust that gets called by Apache Celix framework.
24 changes: 24 additions & 0 deletions misc/experimental/rust/hello_world_activator/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# 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.

[package]
name = "rust_bundle_activator"
version = "0.1.0"

[lib]
name = "rust_bundle_activator"
crate-type = ["cdylib"]
32 changes: 32 additions & 0 deletions misc/experimental/rust/hello_world_activator/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* 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;

#[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
}

0 comments on commit 88bec1d

Please sign in to comment.