Skip to content

Commit

Permalink
Merge pull request #1002 from Concordium/add-bump-alloc
Browse files Browse the repository at this point in the history
Add bump alloc feature documentation
  • Loading branch information
DOBEN committed Apr 9, 2024
2 parents 50ae91b + c260287 commit 181095f
Showing 1 changed file with 29 additions and 14 deletions.
43 changes: 29 additions & 14 deletions source/mainnet/smart-contracts/guides/no-std.rst
Original file line number Diff line number Diff line change
Expand Up @@ -37,46 +37,54 @@ You can update your `Cargo.toml` file by using:
.. code-block:: rust
[dependencies]
concordium-std = { version = "6.0", default-features = false }
concordium-std = { version = "10.0", default-features = false }
.. note::

To compile your smart contracts, a memory `allocator <https://docs.rs/concordium-std/6.0.0/concordium_std/#use-a-custom-allocator>`_ is used.
``concordium-std`` version ``<6.0.0`` hard-coded the use of the `wee_alloc <https://docs.rs/wee_alloc/>`_ allocator.
In ``concordium-std`` version ``>=6.0.0``, ``wee_alloc`` is a feature and needs to be explicitly enabled.
In ``concordium-std`` version in the range of ``>=6.0.0`` and ``<10.0.0``, ``wee_alloc`` is a feature and needs to be explicitly enabled.
In ``concordium-std`` version ``>=10.0.0``, `bump_alloc <https://docs.rs/concordium-std/10.0.0/concordium_std/#use-a-custom-allocator>`_ is a feature and needs to be explicitly enabled.
When ``std`` feature is enabled, the allocator provided by the Rust standard library is used
by default but when the ``wee_alloc`` feature is enabled in addition, `wee_alloc <https://docs.rs/wee_alloc/>`_ is used instead.
by default but when the ``wee_alloc``/``bump_alloc`` feature is enabled in addition, `bump_alloc <https://docs.rs/concordium-std/10.0.0/concordium_std/#use-a-custom-allocator>`_ ( or `wee_alloc <https://docs.rs/wee_alloc/>`_) is used instead.

You can enable the ``std`` feature and the ``wee_alloc`` feature in ``concordium-std`` version ``>=6.0.0`` by using:
You can enable the ``std`` feature and the ``wee_alloc`` feature in ``concordium-std`` version in the range of ``>=6.0.0`` and ``<10.0.0`` by using:

.. code-block:: rust
[dependencies]
concordium-std = {version = "6.0", features = ["wee_alloc"]}
Alternatively, if you want to test with and without ``wee_alloc`` enabled add a ``wee_alloc`` feature to the smart contract crate as follows:
You can enable the ``std`` feature and the ``bump_alloc`` feature in ``concordium-std`` version ``>=10.0.0`` by using:

.. code-block:: rust
[dependencies]
concordium-std = {version = "10.0", features = ["bump_alloc"]}
Alternatively, if you want to test with and without ``wee_alloc``/``bump_alloc`` enabled add a ``wee_alloc``/``bump_alloc`` feature to the smart contract crate as follows:

.. code-block:: rust
[features]
default = ["std", "wee_alloc"]
default = ["std", "bump_alloc"]
std = ["concordium-std/std"]
wee_alloc = ["concordium-std/wee_alloc"]
bump_alloc = ["concordium-std/bump_alloc"]
The above code blocks will use the `wee_alloc <https://docs.rs/wee_alloc/>`_ allocator and not the allocator
The above code blocks will use the `bump_alloc <https://docs.rs/concordium-std/10.0.0/concordium_std/#use-a-custom-allocator>`_ allocator and not the allocator
provided by the Rust standard library when compiled with the default features as follows:

.. code-block:: console
$cargo concordium build
When ``no_std`` is used either ``wee_alloc`` must be enabled, or another global allocator
must be set in the smart contract. You can add the ``wee_alloc`` feature by using:
When ``no_std`` is used either ``wee_alloc``/``bump_alloc`` must be enabled, or another global allocator
must be set in the smart contract. You can add the ``wee_alloc``/``bump_alloc`` feature by using e.g.:

.. code-block:: rust
[features]
wee_alloc = ["concordium-std/wee_alloc"]
bump_alloc = ["concordium-std/bump_alloc"]
To be able to toggle between with and without std, also add a ``std`` to your
own module, which enables the ``std`` feature of ``concordium-std``:
Expand Down Expand Up @@ -104,12 +112,19 @@ you can pass extra arguments for ``cargo``:

.. code-block:: console
$cargo +nightly concordium build -- --no-default-features --features wee_alloc
$cargo +nightly concordium build -- --no-default-features --features bump_alloc
.. note::

The above command works with ``concordium-std`` version ``>=6.0.0``, because the
``wee_alloc`` feature needs to be explicitly enabled.
The above command works with ``concordium-std`` version ``>=10.0.0``, because the
``bump_alloc`` feature needs to be explicitly enabled.

If you use ``concordium-std`` version in the range of ``>=6.0.0`` and ``<10.0.0`` use the following instead:

.. code-block:: console
$cargo +nightly concordium build -- --no-default-features --features wee_alloc
If you use ``concordium-std`` version ``<6.0.0`` use the following instead:

.. code-block:: console
Expand Down

0 comments on commit 181095f

Please sign in to comment.