1.. _external-contributions:
2
3Contributing External Components
4################################
5
6In some cases it is desirable to leverage existing, external source code in
7order to avoid re-implementing basic functionality or features that are readily
8available in other open source projects.
9
10This section describes the circumstances under which external source code can be
11imported into Zephyr, and the process that governs the inclusion.
12
13There are three main factors that will be considered during the inclusion
14process in order to determine whether it will be accepted. These will be
15described in the following sections.
16
17Note that most of this page deals with external components that end up being
18compiled and linked into the final image, and programmed into the target
19hardware. For external tooling that is only used during compilation,
20code analysis, testing or simulation please refer to the
21:ref:`external-tooling` section at the end of the page.
22
23Software License
24****************
25
26.. note::
27
28   External source code licensed under the Apache-2.0 license is not subject to
29   this section.
30
31Integrating code into the Zephyr Project from other projects that use a license
32other than the Apache 2.0 license needs to be fully understood in
33context and approved by the `Zephyr governing board`_, as described in the
34`Zephyr project charter`_. The board will automatically reject licenses that
35have not been approved by the `Open Source Initiative (OSI)`_. See the
36:ref:`external-src-process` section for more details.
37
38.. _Zephyr governing board:
39   https://www.zephyrproject.org/governance/
40
41.. _Zephyr project charter:
42   https://www.zephyrproject.org/wp-content/uploads/2023/08/LF-Zephyr-Charter-2023.08.21.pdf
43
44.. _Open Source Initiative (OSI):
45   https://opensource.org/licenses/alphabetical
46
47By carefully reviewing potential contributions and also enforcing a :ref:`DCO`
48for contributed code, we ensure that the Zephyr community can develop products
49with the Zephyr Project without concerns over patent or copyright issues.
50
51Merit
52*****
53
54Just like with any other regular contribution, one that contains external code
55needs to be evaluated for merit. However, in the particular case of code that
56comes from an existing project, there are additional questions that must be
57answered in order to accept the contribution.
58More specifically, the following will be considered by the Technical Steering
59Committee and evaluated carefully before the external source code is accepted
60into the project:
61
62- Is this the most optimal way to introduce the functionality to the project?
63  Both the cost of implementing this internally and the one incurred in
64  maintaining an externally developed codebase need to be evaluated.
65- Is the external project being actively maintained? This is particularly
66  important for source code that deals with security or cryptography.
67- Have alternatives to the particular implementation proposed been considered?
68  Are there other open source project that implement the same functionality?
69
70Mode of integration
71*******************
72
73There are two ways of integrating external source code into the Zephyr Project,
74and careful consideration must be taken to choose the appropriate one for each
75particular case.
76
77Integration in the main tree
78============================
79
80The first way to integrate external source code into the project is to simply
81import the source code files into the main ``zephyr`` repository. This
82automatically implies that the imported source code becomes part of the
83"mainline" codebase, which in turn requires that:
84
85- The code is formatted according to the Zephyr :ref:`coding_style`
86- The code adheres to the project's :ref:`coding_guidelines`
87- The code is subject to the same checks and verification requirements as the
88  rest of the code in the main tree, including static analysis
89- All files contain an SPDX tag if not already present
90- If the source is not Apache 2.0 licensed,
91  an entry is added to the :ref:`licensing page <zephyr_licensing>`.
92
93This mode of integration can be applicable to both small and large external
94codebases, but it is typically used more commonly with the former.
95
96Integration as a module
97=======================
98
99The second way of integrating external source code into the project is to import
100the whole or parts of the third-party open source project into a separate
101repository, and then include it under the form of a :ref:`module <modules>`.
102With this approach the code is considered as being developed externally, and
103thus it is not automatically subject to the requirements of the previous
104section.
105
106Integration in main manifest file (west.yaml)
107---------------------------------------------
108
109Integrating external code into the main :file:`west.yml` manifest file is
110limited to code that is used by a Zephyr subsystem (libraries), by a platform,
111drivers (HAL) or tooling needed to test or build Zephyr components.
112
113The integration of modules in this group is validated by the Zephyr project CI,
114and verified to be working with each Zephyr release.
115
116Integrated modules will not be removed from the tree without a detailed
117migration plan.
118
119Integration as optional modules
120-------------------------------
121
122Standalone or loose integration of modules/projects without any incoming
123dependencies shall be made optional and shall be kept standalone. Optional
124projects that provide value to users directly and through a Zephyr subsystem or
125platform shall be added to an optional manifest file that is filtered by
126default. (:file:`submanifests/optional.yml`).
127
128Such optional projects might include samples and tests in their own repositories.
129
130There shall not be any direct dependency added in the Zephyr code tree (Git
131repository) and all sample or test code shall be maintained as part of the module.
132
133.. note::
134
135   This is valid for all new optional modules. Existing optional modules with
136   samples and test code in the Zephyr Git repository will be transitioned out
137   over time.
138
139Integration as external modules
140-------------------------------
141
142Similar to optional modules, but added to the Zephyr project as an entry in the
143documentation using a pre-defined template. This type of modules exists outside the
144Zephyr project manifest with documentation instructing users and developers how
145to integrate the functionality.
146
147Ongoing maintenance
148*******************
149
150Regardless of the mode of integration, external source code that is integrated
151in Zephyr requires regular ongoing maintenance. The submitter of the proposal to
152integrate external source code must therefore commit to maintain the integration
153of such code for the foreseeable future.
154This may require adding an entry in the :file:`MAINTAINERS.yml` as part of the
155process.
156
157.. _external-src-process:
158
159Submission and review process
160*****************************
161
162Before external source code can be included in the project, it must be reviewed
163and accepted by the Technical Steering Committee (TSC) and, in some cases, by
164the Zephyr governing board.
165
166A request for external source code integration must be made by creating a new
167issue in the Zephyr project issue tracking system on GitHub with details
168about the source code and how it integrates into the project.
169
170Follow the steps below to begin the submission process:
171
172#. Make sure to read through the :ref:`external-contributions` section in
173   detail, so that you are informed of the criteria used by the TSC and board in
174   order to approve or reject a request
175#. Use the :github:`New External Source Code Issue
176   <new?assignees=&labels=RFC&template=007_ext-source.md&title=>` to open an issue
177#. Fill out all required sections, making sure you provide enough detail for the
178   TSC to assess the merit of the request. Optionally you can also create a Pull
179   Request that demonstrates the integration of the external source code and
180   link to it from the issue
181#. Wait for feedback from the TSC, respond to any additional questions added as
182   GitHub issue comments
183
184If, after consideration by the TSC, the conclusion is that integrating external
185source code is the best solution, and the external source code is licensed under
186the Apache-2.0 license, the submission process is complete and the external
187source code can be integrated.
188
189If, however, the external source code uses a license other than Apache-2.0,
190then these additional steps must be followed:
191
192#. The TSC chair will forward the link to the GitHub issue created during the
193   early submission process to the Zephyr governing board for further review
194
195#. The Zephyr governing board has two weeks to review and ask questions:
196
197   - If there are no objections, the matter is closed. Approval can be
198     accelerated by unanimous approval of the board before the two
199     weeks are up
200
201   - If a governing board member raises an objection that cannot be resolved
202     via email, the board will meet to discuss whether to override the
203     TSC approval or identify other approaches that can resolve the
204     objections
205
206#. On approval of the Zephyr TSC and governing board the submission process is
207   complete
208
209The flowchart below shows an overview of the process:
210
211.. figure:: media/ext-src-flowchart.svg
212   :align: center
213
214   Submission process
215
216.. _external-tooling:
217
218Contributing External Tooling
219*****************************
220
221This section deals exclusively with the inclusion of external tooling in the
222Zephyr project, where tooling is defined as software that assists the
223compilation, testing or simulation processes but in no case ends up being part
224of the code compiled and linked into the final image. "Inclusion" in this
225context means becoming part of the Zephyr default distribution either in the
226main tree directly under the :file:`scripts/` folder or indirectly as a west
227project in the main :file:`west.yml` manifest. Therefore, this section does not
228apply to 3rd-party tooling such as toolchains, simulators or others, which may
229still be referenced by the Zephyr build system or docs without being included in
230Zephyr.
231
232Tooling components must be released under a license approved by the
233`Open Source Initiative (OSI)`_.
234
235Just like with regular external components, tooling that is imported from
236another project can be integrated either in the main tree or as a :ref:`west
237project <west-workspace>`. Note that in this case the corresponding west project
238will not be a :ref:`module <modules>`, because tooling does not make use of the
239Zephyr build system and does not need to be processed by it. Please see
240:ref:`modules-vs-projects` for additional information on the differences.
241
242If the tool is integrated in the main tree it should be placed under the
243:file:`scripts/` folder.
244If the tool is integrated as a west project, then the project repository can be
245hosted outside the zephyrproject-rtos GitHub organization, provided that the
246project is made optional via the ``group-filter:`` field in the main
247:file:`west.yml` manifest. More info on optional projects can be found in
248:ref:`this section <west-manifest-groups>`.
249
250The TSC must approve every Pull Request that introduces a new external tooling
251component. This will be done on a case-by-case, individual analysis of the
252proposed addition by the TSC representatives.
253
254Additional considerations about the main manifest
255*************************************************
256
257In general, any additions or removals whatsoever to the ``projects:`` section of
258the `main manifest file`_ requires TSC approval. This includes, but is not
259limited to:
260
261- Adding and removing groups and group filters
262- Adding and removing projects
263- Adding and removing ``import`` statements
264
265.. _main manifest file:
266   https://github.com/zephyrproject-rtos/zephyr/blob/main/west.yml
267