Skip to content

Commit 823ed39

Browse files
committed
bazel: add placeholder as an example
- Make examples and tests work, both with Cargo and Bazel. - Remove obsolete test examples. - Add Python dependency.
1 parent e13e85f commit 823ed39

File tree

15 files changed

+151
-69
lines changed

15 files changed

+151
-69
lines changed

Cargo.lock

Lines changed: 21 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
[workspace]
22
resolver = "2"
3-
# Split to default members without component integration tests.
3+
# Split to default members without tests and examples.
44
# Used when executing cargo from project root.
5-
default-members = []
6-
# Include component integration tests as a member for IDE support and Bazel builds.
7-
members = []
5+
default-members = ["src/mw/_placeholder"]
6+
# Include tests and examples as a member for IDE support and Bazel builds.
7+
members = [
8+
"src/mw/_placeholder",
9+
"examples/mw/_placeholder_example",
10+
"tests/mw/_placeholder",
11+
]
812

913

1014
[workspace.package]
@@ -15,6 +19,7 @@ authors = ["S-CORE Contributors"]
1519

1620

1721
[workspace.dependencies]
22+
_placeholder = { path = "src/mw/_placeholder" }
1823

1924

2025
[workspace.lints.clippy]

MODULE.bazel

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ module(
1717
)
1818

1919
# Bazel global rules
20+
bazel_dep(name = "rules_python", version = "1.7.0")
2021
bazel_dep(name = "bazel_skylib", version = "1.8.2")
2122
bazel_dep(name = "rules_rust", version = "0.67.0")
2223
bazel_dep(name = "rules_cc", version = "0.2.14")
@@ -45,24 +46,12 @@ bazel_dep(name = "custom_qemu", version = "1.0.0", dev_dependency = True)
4546
bazel_dep(name = "googletest", version = "1.17.0")
4647

4748
# Overrides
48-
# git_override(
49-
# module_name = "score_platform",
50-
# commit = "bcab25561cdce7bd4eeebdb20b0ba4e2a4becc12",
51-
# remote = "https://github.com/eclipse-score/score.git",
52-
# )
53-
5449
git_override(
5550
module_name = "score_toolchains_rust",
5651
commit = "6651945b4ba8e7c342d9740e9cb2d37842f56261",
5752
remote = "https://github.com/eclipse-score/toolchains_rust.git",
5853
)
5954

60-
# git_override(
61-
# module_name = "score_toolchains_qnx",
62-
# commit = "3477ac13a8015a4e2016588fba573c2f9519237d",
63-
# remote = "https://github.com/eclipse-score/toolchains_qnx.git",
64-
# )
65-
6655
git_override(
6756
module_name = "score_virtualization",
6857
commit = "1d9e73212cc291c37a1b7c1427e0f34368ef25e0",
@@ -103,6 +92,15 @@ toolchains_qnx.sdp(
10392
url = "https://www.qnx.com/download/download/79858/installation.tgz",
10493
)
10594

95+
PYTHON_VERSION = "3.12"
96+
97+
python = use_extension("@rules_python//python/extensions:python.bzl", "python", dev_dependency = True)
98+
python.toolchain(
99+
is_default = True,
100+
python_version = PYTHON_VERSION,
101+
)
102+
use_repo(python)
103+
106104
use_repo(toolchains_qnx, "toolchains_qnx_sdp")
107105
use_repo(toolchains_qnx, "toolchains_qnx_qcc")
108106
use_repo(toolchains_qnx, "toolchains_qnx_ifs")
@@ -129,7 +127,10 @@ crate.from_cargo(
129127
name = "score_baselibs_rust_crates",
130128
cargo_lockfile = "//:Cargo.lock",
131129
manifests = [
132-
# TODO: expand along with `Cargo.toml`.
130+
"//:Cargo.toml",
131+
"//:src/mw/_placeholder/Cargo.toml",
132+
"//:examples/mw/_placeholder_example/Cargo.toml",
133+
"//:tests/mw/_placeholder/Cargo.toml",
133134
],
134135

135136
# This shall not be here but rules_rust 0.61.0 or even 0.67.0 does not correct finds out that when we use out platform it shall append
Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,16 @@
1010
#
1111
# SPDX-License-Identifier: Apache-2.0
1212
# *******************************************************************************
13-
cc_test(
14-
name = "cpp_test_main",
15-
srcs = ["test_main.cpp"],
16-
deps = [
17-
"@googletest//:gtest_main", # GoogleTest dependency via Bazel Modules
13+
14+
load("@rules_rust//rust:defs.bzl", "rust_binary")
15+
load("@score_baselibs_rust_crates//:defs.bzl", "all_crate_deps")
16+
17+
rust_binary(
18+
name = "_placeholder_example",
19+
srcs = glob(["src/**/*.rs"]),
20+
deps = all_crate_deps(
21+
normal = True,
22+
) + [
23+
"//src/mw/_placeholder",
1824
],
1925
)
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
[package]
2+
name = "_placeholder_example"
3+
version.workspace = true
4+
edition.workspace = true
5+
license-file.workspace = true
6+
authors.workspace = true
7+
8+
[dependencies]
9+
_placeholder.workspace = true
10+
11+
[lints]
12+
workspace = true
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
fn main() {
2+
let result = _placeholder::add(4, 8);
3+
println!("Result: {result}");
4+
}

src/mw/_placeholder/BUILD

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# *******************************************************************************
2+
# Copyright (c) 2025 Contributors to the Eclipse Foundation
3+
#
4+
# See the NOTICE file(s) distributed with this work for additional
5+
# information regarding copyright ownership.
6+
#
7+
# This program and the accompanying materials are made available under the
8+
# terms of the Apache License Version 2.0 which is available at
9+
# https://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# SPDX-License-Identifier: Apache-2.0
12+
# *******************************************************************************
13+
load("@rules_rust//rust:defs.bzl", "rust_library", "rust_test")
14+
load("@score_baselibs_rust_crates//:defs.bzl", "all_crate_deps")
15+
16+
rust_library(
17+
name = "_placeholder",
18+
srcs = glob(["src/**/*.rs"]),
19+
visibility = ["//visibility:public"],
20+
)
21+
22+
rust_test(
23+
name = "_placeholder_tests",
24+
crate = ":_placeholder",
25+
deps = all_crate_deps(
26+
normal = True,
27+
) + [
28+
"//src/mw/_placeholder",
29+
],
30+
)

src/mw/_placeholder/Cargo.toml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
[package]
2+
name = "_placeholder"
3+
version.workspace = true
4+
edition.workspace = true
5+
license-file.workspace = true
6+
authors.workspace = true
7+
8+
[dependencies]
9+
10+
[lints]
11+
workspace = true

src/mw/_placeholder/README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# `_placeholder`
2+
3+
This project is only used to check Cargo/Bazel integration in `baselibs_rust`.
4+
It is meant to be removed once **any other component** is added to this repo.

src/mw/_placeholder/src/lib.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
pub fn add(left: u64, right: u64) -> u64 {
2+
left + right
3+
}
4+
5+
#[cfg(test)]
6+
mod tests {
7+
use super::*;
8+
9+
#[test]
10+
fn it_works() {
11+
let result = add(2, 2);
12+
assert_eq!(result, 4);
13+
}
14+
}

0 commit comments

Comments
 (0)