Skip to content

Commit 09730ae

Browse files
committed
llvm: Add LLVM as host C++ toolchain
Add LLVM Toolchain which is provuded by Bazel community.
1 parent 6d4cc51 commit 09730ae

File tree

13 files changed

+349
-2
lines changed

13 files changed

+349
-2
lines changed

Diff for: .gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
bazel-*
2+
MODULE.bazel.lock

Diff for: LICENSE

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
Copyright 2025 Contributors to the Eclipse Foundation
2+
3+
Licensed under the Apache License, Version 2.0 (the "License");
4+
you may not use this file except in compliance with the License.
5+
You may obtain a copy of the License at
6+
7+
http://www.apache.org/licenses/LICENSE-2.0
8+
9+
Unless required by applicable law or agreed to in writing, software
10+
distributed under the License is distributed on an "AS IS" BASIS,
11+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
See the License for the specific language governing permissions and
13+
limitations under the License.

Diff for: MODULE.bazel

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
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+
module(
14+
name = "examples",
15+
version = "0.1",
16+
compatibility_level = 0,
17+
)
18+
19+
20+
###############################################################################
21+
#
22+
# CC Rules - Add this section in MODULE.bazel enable Bazel Rules CC
23+
#
24+
###############################################################################
25+
bazel_dep(name = "rules_cc", version = "0.1.1")
26+
27+
###############################################################################
28+
#
29+
# LLVM Toolchains - Add this section in MODULE.bazel enable LLVM Toolchain
30+
#
31+
###############################################################################
32+
bazel_dep(name = "toolchains_llvm", version = "1.2.0")
33+
34+
llvm = use_extension("@toolchains_llvm//toolchain/extensions:llvm.bzl", "llvm")
35+
llvm.toolchain(
36+
cxx_standard = {"": "c++17"},
37+
llvm_version = "19.1.0",
38+
)
39+
use_repo(llvm, "llvm_toolchain")
40+
use_repo(llvm, "llvm_toolchain_llvm")
41+
42+
register_toolchains("@llvm_toolchain//:all")

Diff for: README.md

+19-2
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,19 @@
1-
# examples
2-
Hosts templates and examples for score tools and workflows
1+
# Examples Repository
2+
3+
This repository serves as a template for setting up tools and toolchains used in Score, providing small examples that demonstrate how these tools work in practice.
4+
5+
## Available Toolchains
6+
7+
Currently, the repository includes:
8+
9+
- LLVM from the Bazel community
10+
11+
## Setting Up Toolchains in Your Module
12+
13+
To integrate a toolchain into your Bazel module, follow these steps:
14+
15+
- Copy the relevant content from MODULE.bazel in this repository.
16+
- Add the necessary bazel_dep() entries to your module’s MODULE.bazel file.
17+
- Ensure your build configurations align with the toolchain requirements.
18+
19+
This approach allows developers to quickly set up and reuse toolchains in their own projects with minimal effort.

Diff for: examples/cpp/BUILD

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
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_cc//cc:defs.bzl", "cc_binary", "cc_test")
14+
15+
cc_binary(
16+
name = "example-app",
17+
srcs = ["main.cpp"],
18+
deps = ["//examples/cpp/company"],
19+
)
20+
21+
cc_test(
22+
name = "example-test",
23+
srcs = ["test.cpp"],
24+
deps = [
25+
"@googletest//:gtest",
26+
"@googletest//:gtest_main",
27+
],
28+
)

Diff for: examples/cpp/company/BUILD

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
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_cc//cc:defs.bzl", "cc_library")
14+
15+
cc_library(
16+
name = "company",
17+
srcs = ["company.cpp"],
18+
hdrs = ["includes/company.h"],
19+
includes = ["includes/"],
20+
linkstatic = True,
21+
visibility = ["//examples/cpp:__subpackages__"],
22+
deps = ["//examples/cpp/department"],
23+
)

Diff for: examples/cpp/company/company.cpp

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/********************************************************************************
2+
* Copyright (c) {year} 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+
#include "company.h"
14+
15+
#include <utility>
16+
17+
Company::Company(std::string name) : name(std::move(name)) {};
18+
19+
std::string Company::GetName()
20+
{
21+
return this->name;
22+
}
23+
24+
void Company::AddDepartment(int id, std::string dep_name, int employee_nu)
25+
{
26+
this->departments.push_back(Department(id, std::move(dep_name), employee_nu));
27+
}
28+
29+
std::optional<Department> Company::GetDepartmentByName(const std::string& sname)
30+
{
31+
std::list<Department>::iterator it;
32+
33+
for (it = this->departments.begin(); it != this->departments.end(); ++it)
34+
{
35+
if (sname.compare((*it).GetName()) == 0)
36+
{
37+
return *it;
38+
}
39+
}
40+
41+
return std::nullopt;
42+
}
43+
44+
size_t Company::GetNumberOfDepartments()
45+
{
46+
return this->departments.size();
47+
}

Diff for: examples/cpp/company/includes/company.h

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/********************************************************************************
2+
* Copyright (c) {year} 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+
#ifndef SAMPLE_COMPANY_H
14+
#define SAMPLE_COMPANY_H
15+
16+
#include "department.h"
17+
#include <list>
18+
#include <optional>
19+
#include <vector>
20+
21+
class Company
22+
{
23+
24+
public:
25+
explicit Company(std::string name);
26+
std::string GetName();
27+
void AddDepartment(int id, std::string dep_name, int employee_nu);
28+
std::optional<Department> GetDepartmentByName(const std::string& name);
29+
size_t GetNumberOfDepartments();
30+
31+
private:
32+
std::string name;
33+
std::list<Department> departments;
34+
};
35+
36+
#endif // SAMPLE_COMPANY_H

Diff for: examples/cpp/department/BUILD

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
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_cc//cc:defs.bzl", "cc_library")
14+
15+
cc_library(
16+
name = "department",
17+
srcs = ["department.cpp"],
18+
hdrs = ["includes/department.h"],
19+
includes = ["includes/"],
20+
linkstatic = True,
21+
visibility = ["//examples/cpp/company:__pkg__"],
22+
)

Diff for: examples/cpp/department/department.cpp

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/********************************************************************************
2+
* Copyright (c) {year} 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+
#include "department.h"
14+
15+
#include <utility>
16+
17+
Department::Department(int id, std::string name, int employee_nu)
18+
: id(id), name(std::move(name)), employee_nu(employee_nu) {};
19+
20+
int Department::GetEmployeeNumber()
21+
{
22+
return this->employee_nu;
23+
}
24+
25+
std::string Department::GetName()
26+
{
27+
return this->name;
28+
}
29+
30+
int Department::GetID()
31+
{
32+
return this->id;
33+
}

Diff for: examples/cpp/department/includes/department.h

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/********************************************************************************
2+
* Copyright (c) {year} 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+
#ifndef SAMPLE_DEPARTMENT_H
14+
#define SAMPLE_DEPARTMENT_H
15+
16+
#include <string>
17+
18+
class Department
19+
{
20+
21+
public:
22+
Department(int id, std::string name, int employee_nu);
23+
int GetEmployeeNumber();
24+
int GetID();
25+
std::string GetName();
26+
27+
private:
28+
int id;
29+
std::string name;
30+
int employee_nu;
31+
};
32+
33+
#endif // SAMPLE_DEPARTMENT_H

Diff for: examples/cpp/main.cpp

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/********************************************************************************
2+
* Copyright (c) {year} 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+
#include <iostream>
14+
15+
#include "company.h"
16+
17+
int main(int /* argc */, char** /* argv */)
18+
{
19+
20+
Company awesome_company("SuperAwesome Inc.");
21+
std::cout << "Company name: " << awesome_company.GetName() << '\n';
22+
23+
awesome_company.AddDepartment(13, "QX-57", 26262); // NOLINT(cppcoreguidelines-avoid-magic-numbers)
24+
25+
auto department = awesome_company.GetDepartmentByName("QX-57");
26+
if (department)
27+
{
28+
std::cout << "Department ID: " << department->GetID() << '\n';
29+
}
30+
31+
return 0;
32+
}

Diff for: examples/cpp/test.cpp

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/********************************************************************************
2+
* Copyright (c) {year} 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+
#include <gtest/gtest.h>
14+
15+
TEST(HelloTest, BasicAssertions)
16+
{
17+
const int i = 42;
18+
EXPECT_EQ(i, 42);
19+
}

0 commit comments

Comments
 (0)