diff --git a/.bazelrc b/.bazelrc new file mode 100644 index 0000000..94b9560 --- /dev/null +++ b/.bazelrc @@ -0,0 +1,2 @@ +common --registry=https://raw.githubusercontent.com/eclipse-score/bazel_registry/main/ +common --registry=https://bcr.bazel.build diff --git a/BUILD b/BUILD new file mode 100644 index 0000000..69c35d4 --- /dev/null +++ b/BUILD @@ -0,0 +1,24 @@ +# ******************************************************************************* +# Copyright (c) 2025 Contributors to the Eclipse Foundation +# +# See the NOTICE file(s) distributed with this work for additional +# information regarding copyright ownership. +# +# This program and the accompanying materials are made available under the +# terms of the Apache License Version 2.0 which is available at +# https://www.apache.org/licenses/LICENSE-2.0 +# +# SPDX-License-Identifier: Apache-2.0 +# ******************************************************************************* +load("@score_cr_checker//:cr_checker.bzl", "copyright_checker") + +copyright_checker( + name = "copyright", + srcs = [ + "examples", + "//:BUILD", + ], + template = "@score_cr_checker//resources:templates", # shared template. + config = "@score_cr_checker//resources:config", #shared template. + visibility = ["//visibility:public"], +) diff --git a/MODULE.bazel b/MODULE.bazel index 2e24dee..202c8e2 100644 --- a/MODULE.bazel +++ b/MODULE.bazel @@ -40,3 +40,10 @@ use_repo(llvm, "llvm_toolchain") use_repo(llvm, "llvm_toolchain_llvm") register_toolchains("@llvm_toolchain//:all") + +############################################################################### +# +# CopyRight checker - checker for copyright headers +# +############################################################################### +bazel_dep(name = "score_cr_checker", version = "0.2.0") diff --git a/README.md b/README.md index f618af3..f0ad72d 100644 --- a/README.md +++ b/README.md @@ -2,18 +2,46 @@ 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. -## Available Toolchains +> NOTE: The example directory only exist to show how configurations work and it's not mandatory to keep it in derivative repositories. -Currently, the repository includes: +## Available Tools & Toolchains -- LLVM from the Bazel community +The repository includes: -## Setting Up Toolchains in Your Module +- LLVM from the Bazel community - Host C++ toolchain which is by default registered for host platform. +- CopyRight checker tool `cr_checker` - Small utility tool which will check presence of copyright header in selected source files. -To integrate a toolchain into your Bazel module, follow these steps: +## Setting Up Your Module -- Copy the relevant content from MODULE.bazel in this repository. -- Add the necessary bazel_dep() entries to your module’s MODULE.bazel file. -- Ensure your build configurations align with the toolchain requirements. +To integrate default tools & toolchain into your Bazel module, the best practise is to follow these steps: + +- Setup module name in `MODULE.bazel` file, that needs to be in the root of new module. Assuming that the new module name is `score_guidelines`, the first lines of `MODULE.bazel` file are: + + ```python + module( + name = "score_guidelines", # the module name + version = "0.1", # the version of module + compatibility_level = 0, # the compatibility level of the module. + ) + ``` + + > NOTE: To see all available attributes of `module` function, visit [MODULE.bazel](https://bazel.build/rules/lib/globals/module#module) on Bazel documentation webpage. + +- The next step is to copy the relevant content from [MODULE.bazel](https://github.com/eclipse-score/examples/blob/main/MODULE.bazel#L20-L49) (everything except the `examples` module name) in new module `MODULE.bazel` file. If `cr_checker` is the only tool that needs to be integrated in new module (repo) from all tools available in `examples` repo, we only need to copy following line: + + ```python + bazel_dep(name = "score_cr_checker", version = "0.2.0") + ``` + + The same approuch needs to be done with any other tool that is in `examples/MODULE.bazel` file or, as already said, + +- Copy the `.bazelrc` file as is since it holds essential configuration for setting up [SBR](https://github.com/eclipse-score/bazel_registry) (S-CORE Bazel registry). + + ```ini + common --registry=https://raw.githubusercontent.com/eclipse-score/bazel_registry/main/ + common --registry=https://bcr.bazel.build + ``` + +- Copy the .gitignore file. This approach allows developers to quickly set up and reuse toolchains in their own projects with minimal effort. diff --git a/examples/cpp/company/company.cpp b/examples/cpp/company/company.cpp index 59b00df..431f3c7 100644 --- a/examples/cpp/company/company.cpp +++ b/examples/cpp/company/company.cpp @@ -1,4 +1,16 @@ /******************************************************************************** +* Copyright (c) 2025 Contributors to the Eclipse Foundation +* +* See the NOTICE file(s) distributed with this work for additional +* information regarding copyright ownership. +* +* This program and the accompanying materials are made available under the +* terms of the Apache License Version 2.0 which is available at +* https://www.apache.org/licenses/LICENSE-2.0 +* +* SPDX-License-Identifier: Apache-2.0 +********************************************************************************/ +/******************************************************************************** * Copyright (c) {year} Contributors to the Eclipse Foundation * * See the NOTICE file(s) distributed with this work for additional diff --git a/examples/cpp/company/includes/company.h b/examples/cpp/company/includes/company.h index bad8abd..02ea0d6 100644 --- a/examples/cpp/company/includes/company.h +++ b/examples/cpp/company/includes/company.h @@ -1,4 +1,16 @@ /******************************************************************************** +* Copyright (c) 2025 Contributors to the Eclipse Foundation +* +* See the NOTICE file(s) distributed with this work for additional +* information regarding copyright ownership. +* +* This program and the accompanying materials are made available under the +* terms of the Apache License Version 2.0 which is available at +* https://www.apache.org/licenses/LICENSE-2.0 +* +* SPDX-License-Identifier: Apache-2.0 +********************************************************************************/ +/******************************************************************************** * Copyright (c) {year} Contributors to the Eclipse Foundation * * See the NOTICE file(s) distributed with this work for additional diff --git a/examples/cpp/department/department.cpp b/examples/cpp/department/department.cpp index c7d9106..ce9a5b5 100644 --- a/examples/cpp/department/department.cpp +++ b/examples/cpp/department/department.cpp @@ -1,4 +1,16 @@ /******************************************************************************** +* Copyright (c) 2025 Contributors to the Eclipse Foundation +* +* See the NOTICE file(s) distributed with this work for additional +* information regarding copyright ownership. +* +* This program and the accompanying materials are made available under the +* terms of the Apache License Version 2.0 which is available at +* https://www.apache.org/licenses/LICENSE-2.0 +* +* SPDX-License-Identifier: Apache-2.0 +********************************************************************************/ +/******************************************************************************** * Copyright (c) {year} Contributors to the Eclipse Foundation * * See the NOTICE file(s) distributed with this work for additional diff --git a/examples/cpp/department/includes/department.h b/examples/cpp/department/includes/department.h index ea03d3b..3be7fed 100644 --- a/examples/cpp/department/includes/department.h +++ b/examples/cpp/department/includes/department.h @@ -1,4 +1,16 @@ /******************************************************************************** +* Copyright (c) 2025 Contributors to the Eclipse Foundation +* +* See the NOTICE file(s) distributed with this work for additional +* information regarding copyright ownership. +* +* This program and the accompanying materials are made available under the +* terms of the Apache License Version 2.0 which is available at +* https://www.apache.org/licenses/LICENSE-2.0 +* +* SPDX-License-Identifier: Apache-2.0 +********************************************************************************/ +/******************************************************************************** * Copyright (c) {year} Contributors to the Eclipse Foundation * * See the NOTICE file(s) distributed with this work for additional diff --git a/examples/cpp/main.cpp b/examples/cpp/main.cpp index 86d2c29..297f2f3 100644 --- a/examples/cpp/main.cpp +++ b/examples/cpp/main.cpp @@ -1,4 +1,16 @@ /******************************************************************************** +* Copyright (c) 2025 Contributors to the Eclipse Foundation +* +* See the NOTICE file(s) distributed with this work for additional +* information regarding copyright ownership. +* +* This program and the accompanying materials are made available under the +* terms of the Apache License Version 2.0 which is available at +* https://www.apache.org/licenses/LICENSE-2.0 +* +* SPDX-License-Identifier: Apache-2.0 +********************************************************************************/ +/******************************************************************************** * Copyright (c) {year} Contributors to the Eclipse Foundation * * See the NOTICE file(s) distributed with this work for additional diff --git a/examples/cpp/test.cpp b/examples/cpp/test.cpp index e8d5db8..c0fa8db 100644 --- a/examples/cpp/test.cpp +++ b/examples/cpp/test.cpp @@ -1,4 +1,16 @@ /******************************************************************************** +* Copyright (c) 2025 Contributors to the Eclipse Foundation +* +* See the NOTICE file(s) distributed with this work for additional +* information regarding copyright ownership. +* +* This program and the accompanying materials are made available under the +* terms of the Apache License Version 2.0 which is available at +* https://www.apache.org/licenses/LICENSE-2.0 +* +* SPDX-License-Identifier: Apache-2.0 +********************************************************************************/ +/******************************************************************************** * Copyright (c) {year} Contributors to the Eclipse Foundation * * See the NOTICE file(s) distributed with this work for additional