Skip to content

Commit 1a26eef

Browse files
authored
Merge branch 'develop2' into release/2.17
2 parents cf59bc4 + 810316b commit 1a26eef

35 files changed

+674
-110
lines changed

examples/cross_build.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,6 @@ Cross-building examples
99
cross_build/toolchain_packages
1010
cross_build/android/ndk
1111
cross_build/android/android_studio
12+
cross_build/emscripten
1213
cross_build/tricore
1314
cross_build/linux_to_windows_mingw

examples/cross_build/emscripten.rst

Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
.. _examples_cross_build_emscripten:
2+
3+
Cross-building with Emscripten - WebAssembly and asm.js
4+
=======================================================
5+
6+
This example demonstrates how to cross-build a simple C++ project using Emscripten and Conan.
7+
8+
Conan supports `WASM <https://webassembly.org>`_ cross compilation, giving you the flexibility to target different
9+
JavaScript/WebAssembly runtimes in the browser.
10+
11+
We recommend creating separate Conan profiles for each target. Below are
12+
recommended profiles and instructions on how to build with them.
13+
14+
15+
Setting up Conan profile for WebAssembly (WASM)
16+
-----------------------------------------------
17+
18+
.. code-block:: text
19+
20+
[settings]
21+
arch=wasm
22+
build_type=Release
23+
compiler=emcc
24+
compiler.cppstd=17
25+
compiler.libcxx=libc++
26+
# Optional settings to enable multithreading (see note below)
27+
# compiler.threads=posix
28+
compiler.version=4.0.10
29+
os=Emscripten
30+
31+
[tool_requires]
32+
emsdk/4.0.10
33+
34+
[conf]
35+
# Optional settings to enable memory allocation
36+
tools.build:exelinkflags=['-sALLOW_MEMORY_GROWTH=1', '-sMAXIMUM_MEMORY=4GB', '-sINITIAL_MEMORY=64MB']
37+
tools.build:sharedlinkflags=['-sALLOW_MEMORY_GROWTH=1', '-sMAXIMUM_MEMORY=4GB', '-sINITIAL_MEMORY=64MB']
38+
39+
40+
.. note::
41+
42+
Conan also supports building for `asm.js <http://asmjs.org>`_ targets, which is a nowadays considered deprecated.
43+
44+
What’s the difference between asm.js and WASM?
45+
46+
- **asm.js** is a subset of JavaScript optimized for speed. It is fully supported by all browsers (even older ones) and compiles to a large ``.js`` file.
47+
- **WebAssembly (WASM)** is a binary format that is smaller and faster to load and execute. Most modern browsers support it, and it is generally recommended for new projects. **WASM** is also easier to integrate with native browser APIs compared to **asm.js**.
48+
49+
50+
Even though Emscripten is not a true runtime environment (like Linux or
51+
Windows), it is part of a toolchain ecosystem that compiles C/C++ to
52+
WebAssembly (WASM) and asm.js.
53+
54+
Conan uses ``os=Emscripten`` to:
55+
56+
- Align with the toolchain: Emscripten integrates the compiler, runtime glue, and JavaScript environment, making it practical to treat as an "OS-like" target.
57+
58+
- Support backward compatibility: Many recipes in Conan Center Index use ``os=Emscripten`` to enable or disable features and dependencies that specifically target Emscripten.
59+
60+
- Maintain stability: Changing this setting would break recipes that rely on it, and would complicate compatibility with alternative WASM toolchains.
61+
62+
63+
.. note::
64+
65+
``wasm`` arch refers to ``WASM 32-bit`` target architecture, which is the
66+
default. If you wish to target ``WASM64``, set ``arch=wasm64`` in your profile.
67+
**Note that WASM64 is still experimental** and requires Node.js v20+ and a browser that supports it.
68+
69+
.. important::
70+
71+
According to `emscripten documentation <https://emscripten.org/docs/api_reference/wasm_workers.html>`_ Emscripten supports two multithreading APIs:
72+
73+
- POSIX Threads API (``posix`` in conan profile)
74+
- Wasm Workers API (``wasm_workers`` in conan profile)
75+
76+
These two APIs are incompatible with each other and incompatibles with binaries compiled without threading support.
77+
This incompatibility necessitates the modeling of threading usage within
78+
the compiler's binary model, allowing conan to distinguish between binaries
79+
compiled with threading and those compiled without it.
80+
81+
Conan will automatically set compiler and linker flags to enable threading if configured in the profile.
82+
83+
84+
The profiles above use the ``emsdk`` package from `Conan Center Index repository <https://conan.io/center/recipes/emsdk>`_, which provides the Emscripten SDK, including ``emcc``, ``em++``, and tools like ``emrun`` and ``node``.
85+
86+
If you prefer to use your system-installed Emscripten instead of the Conan-provided one, ``tool_requires`` could be replaced by custom ``compiler_executables`` and ``buildenv``:
87+
88+
.. code-block:: text
89+
90+
[conf]
91+
tools.build:compiler_executables={'c':'/path/to/emcc', 'cpp':'/path/to/em++'}
92+
93+
[buildenv]
94+
CC=emcc
95+
CXX=em++
96+
AR=emar
97+
NM=emnm
98+
RANLIB=emranlib
99+
STRIP=emstrip
100+
101+
102+
This way conan could configure `emsdk` local installation to be used from `CMake`, `Meson`, `Autotools` or other build systems.
103+
104+
In some cases, you might also need the ``Emscripten.cmake`` toolchain file
105+
for advanced scenarios. This toolchais is already added in our packaged
106+
`emsdk` but if you are using your own Emscripten installation, you can
107+
specify it in the profile by using
108+
:ref:`tools.cmake.cmaketoolchain:user_toolchain<conan_cmake_user_toolchain>`
109+
and providing the absolute path to your toolchain file.
110+
111+
.. note::
112+
113+
The ``tools.build:exelinkflags`` and ``tools.build:sharedlinkflags`` in
114+
previous profiles are recomendations but users can modify them or define
115+
their values in the CMakeLists.txt file using the
116+
``set_target_properties()`` command.
117+
118+
- By enabling ``ALLOW_MEMORY_GROWTH`` we allow the runtime to grow its
119+
memory dynamically at runtime by calling ``emscripten_resize_heap()``. Without
120+
this flag, memory is allocated at startup and cannot grow.
121+
122+
- The ``MAXIMUM_MEMORY`` and ``INITIAL_MEMORY`` values specifies the maximum
123+
and initial memory size for the Emscripten runtime. These values can be
124+
adjusted based on your application's needs.
125+
126+
Take into account that ``arch=wasm64`` has a theorical exabytes maximum
127+
memory size, but runtime currently limits it to 16GB, while ``arch=wasm32``
128+
has a maximum memory size of 4GB and ``arch=asm.js`` has a maximum memory size of 2GB.
129+
130+
131+
.. important::
132+
133+
``emcc`` compiler does not guarantee any ABI compatibility between different versions (patches included)
134+
To ensure a new ``package_id`` is generated when the Emscripten version
135+
changes, it is recommended to update the ``compiler.version`` setting in your profile accordingly.
136+
137+
This will ensure that the package ID is generated based on the Emscripten
138+
version, allowing Conan to detect changes in the Emscripten toolchain and
139+
rebuild the project accordingly.

images/conan-report-diff_html.png

1.13 MB
Loading
18.8 KB
Loading

incubating.rst

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,20 @@ The new fields that can be defined in the ``cpp_info`` or ``cpp_info.components`
4646
self.cpp_info.languages # same as "languages" attribute, it can be "C", "C++"
4747
self.cpp_info.exe # Definition of an executable artifact
4848
self.cpp_info.package_framework # Definition of an Apple Framework (new since Conan 2.14)
49+
self.cpp_info.sources # List of paths to source files in the package (for packages that provide source code to consumers)
4950
5051
5152
These fields will be auto-deduced from the other ``cpp_info`` and ``components`` definitions, like the ``libs`` or ``libdirs`` fields, but the automatic deduction might have limitations. Defining them explicitly will inhibit the auto deduction and use the value as provided by the recipe.
5253

54+
Declare sources for targets with:
55+
56+
.. code-block:: python
57+
58+
self.cpp_info.sources = ["src/mylib.cpp", "src/other.cpp"]
59+
60+
This allows packages to provide source code as a dependency to consumers. The paths should be relative to the package folder.
61+
The source files will be added as `INTERFACE_SOURCES` property to the CMake library (or component) target and consumers that
62+
link with this target will compile the sources when building their own targets.
5363

5464
This feature is enabled with the ``-c tools.cmake.cmakedeps:new=will_break_next`` configuration. The value ``will_break_next`` will change in next releases to emphasize the fact that this feature is not suitable for usage beyond testing. Just by enabling this conf and forcing the build of packages that use ``CMakeDeps`` will trigger the usage of the new generator.
5565

integrations.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ Xcode.
2222
integrations/makefile
2323
integrations/xcode
2424
integrations/meson
25+
integrations/emscripten
2526
integrations/premake
2627
integrations/android
2728
integrations/jfrog

integrations/emscripten.rst

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
.. _integrations_emscripten:
2+
3+
|emscripten_logo| Emscripten
4+
============================
5+
6+
Conan provides support for cross-building for both `asm.js <http://asmjs.org>`_ and `WASM <https://webassembly.org>`_ (Web Assembly) targets
7+
using `Emscripten <https://emscripten.org>`__. This enables developers to compile C/C++ code for the browser
8+
and other JavaScript environments.
9+
10+
For detailed examples and step-by-step instructions, refer to:
11+
12+
- :ref:`Cross-building with Emscripten <examples_cross_build_emscripten>`
13+
14+
.. |emscripten_logo| image:: ../images/integrations/conan-emscripten-logo.png

integrations/premake.rst

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,18 @@
66
Conan provides different tools to help manage your projects using Premake. They can be
77
imported from ``conan.tools.premake``. The most relevant tools are:
88

9-
- ``PremakeDeps``: the dependencies generator for Premake, to allow consuming dependencies from Premake projects
9+
- ``PremakeDeps``: the dependencies generator for Premake, to allow consuming dependencies from Premake projects.
10+
11+
- ``PremakeToolchain``: the toolchain generator for Premake. It will create a
12+
wrapper over premake scripts allowing premake workspace and projects
13+
customization.
1014

1115
- ``Premake``: the Premake build helper. It's simply a wrapper around the command line invocation of Premake.
1216

1317
.. seealso::
1418

1519
- Reference for :ref:`conan_tools_premake_premakedeps`.
20+
- Reference for :ref:`conan_tools_premake_premaketoolchain`.
1621
- Reference for :ref:`conan_tools_premake_premake`.
1722

1823

reference/commands.rst

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ and these :ref:`custom command examples <examples_extensions_custom_commands>`
1616
:maxdepth: 1
1717
:hidden:
1818

19-
commands/audit
2019
commands/cache
2120
commands/config
2221
commands/graph
@@ -32,7 +31,6 @@ and these :ref:`custom command examples <examples_extensions_custom_commands>`
3231
commands/version
3332
commands/workspace
3433

35-
- :doc:`conan audit <commands/audit>`: Check for vulnerabilities in your Conan packages
3634
- :doc:`conan cache <commands/cache>`: Return the path of recipes and packages in the cache
3735
- :doc:`conan config <commands/config>`: Manage Conan configuration (remotes, settings, plugins, etc)
3836
- :doc:`conan graph <commands/graph>`: Obtain information about the dependency graph without fetching binaries
@@ -78,6 +76,18 @@ and these :ref:`custom command examples <examples_extensions_custom_commands>`
7876
- :doc:`conan test <commands/test>`: Test a package
7977
- :doc:`conan upload <commands/upload>`: Upload packages from the local cache to a specified remote
8078

79+
**Security Commands**
80+
81+
.. toctree::
82+
:caption: Security Commands
83+
:maxdepth: 1
84+
:hidden:
85+
86+
commands/audit
87+
commands/report
88+
89+
- :doc:`conan audit <commands/audit>`: Checks for vulnerabilities in your Conan packages.
90+
- :doc:`conan report <commands/report>`: Get information about the packages
8191

8292
.. _commands_output:
8393

reference/commands/audit.rst

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,25 +13,26 @@ See :ref:`the audit devops page<devops_audit>` to see examples on how to use the
1313

1414

1515
conan audit scan
16-
================
16+
^^^^^^^^^^^^^^^^
1717

1818
.. autocommand::
1919
:command: conan audit scan -h
2020

21-
The ``conan audit scan`` checks for vulnerabilities in the given references and their transitive dependencies.
21+
The ``conan audit scan`` command checks for vulnerabilities in the given references and their transitive dependencies.
2222
This command receives configuration arguments such as profiles and settings, to control the expansion of the graph.
2323

2424
conan audit list
25-
================
25+
^^^^^^^^^^^^^^^^
2626

2727
.. autocommand::
2828
:command: conan audit list -h
2929

3030
The ``conan audit list`` command lists vulnerabilities for the given references, without checking their transitive dependencies.
31-
You can pass a single reference, or a pkglist file with multiple references.
31+
You can pass a single reference, a pkglist file with multiple references,
32+
a cyclonedx SBOM file generated with the :ref:`conan.tools.sbom <conan_tools_sbom>` module, or a Conan lockfile.
3233

3334
conan audit provider
34-
====================
35+
^^^^^^^^^^^^^^^^^^^^
3536

3637
.. autocommand::
3738
:command: conan audit provider -h
@@ -42,6 +43,7 @@ By default the ``conan audit`` subcommands use the ConanCenter provider, but you
4243
For now, besides the default ConanCenter provider, only private JFrog Security providers are supported, see :ref:`the audit devops page<devops_audit_private_providers>` for more information.
4344

4445
There are 3 subcommands:
46+
4547
- ``conan audit provider auth``: Authenticates a provider with a token.
4648
- ``conan audit provider add``: Adds a provider to the list.
4749
- ``conan audit provider remove``: Removes a provider from the list.

0 commit comments

Comments
 (0)