3
0
Fork 0
mirror of https://github.com/YosysHQ/yosys synced 2026-06-05 16:40:53 +00:00

docs: Resolving todos

Make explicit the location for the `CMakeUserPresets.json` file.
Update docs tests documentation.
Move `BUILD_DIR` and `PROGRAM_PREFIX` comments into the functional tests todo.
Add cmake to MacPorts/FreeBSD install instructions.
Add ccache to example `CMakeUserPresets.json` (it isn't otherwise documented, and is no longer as obvious without an `ENABLE_CCACHE` makevar).

Addressing comments
This commit is contained in:
Krystine Sherwin 2026-06-03 17:30:38 +12:00
parent e1931596ae
commit 72f5836fb1
No known key found for this signature in database
7 changed files with 55 additions and 98 deletions

View file

@ -102,26 +102,28 @@ Once generated, available build variables can be inspected and modified with
$ ccmake build #..or..
$ vi build/CMakeCache.txt
When setting one-off variables, CMake provides the `-D <var>=<value>` command line
option. For example, disabling zlib support:
When setting one-off variables, CMake provides the `-D <var>=<value>` command
line option. For example, disabling zlib support:
$ cmake -B build . -DYOSYS_WITHOUT_ZLIB=ON
For a more persistent configuration, we recommend creating and using a
`CMakeUserPresets.json` file. Below is an example file which sets the default
compiler to clang when calling `cmake --preset clang`:
`CMakeUserPresets.json` file in the root `yosys` directory. Below is an example
file which enables ccache and sets the default compiler to clang when calling
`cmake --preset clang`:
```json
{
"version": 1,
"configurePresets": [
{
"name": "clang",
"name": "default",
"binaryDir": "build",
"generator": "Unix Makefiles",
"cacheVariables": {
"CMAKE_C_COMPILER": "clang",
"CMAKE_CXX_COMPILER": "clang++"
"CMAKE_CXX_COMPILER": "clang++",
"YOSYS_COMPILER_LAUNCHER": "ccache"
}
}
]

View file

@ -56,7 +56,7 @@ function(yosys_check_abc_submodule)
else() #
message(FATAL_ERROR
"${CMAKE_SOURCE_DIR} is not configured as a git repository, and 'abc' folder is missing.\n"
"If you already have ABC, set 'YOSYS_ABC_EXECUTABLE' make variable to point to ABC executable.\n"
"If you already have ABC, set 'YOSYS_ABC_EXECUTABLE' CMake variable to point to ABC executable.\n"
"Otherwise, download release archive 'yosys.tar.gz' from https://github.com/YosysHQ/yosys/releases.\n"
" ('Source code' archive does not contain submodules.)\n"
)

View file

@ -67,7 +67,7 @@ clone these submodules at the same time, use e.g.:
As of Yosys v0.47, releases include a ``yosys.tar.gz`` file which includes
all source code and all sub-modules in a single archive. This can be used as
an alternative which does not rely on ``git``.
an alternative which does not rely on :program:`git`.
Supported platforms
^^^^^^^^^^^^^^^^^^^
@ -122,23 +122,16 @@ Installing all prerequisites:
.. code:: console
sudo port install bison flex readline gawk libffi graphviz \
sudo port install bison cmake flex readline gawk libffi graphviz \
pkgconfig python311 zlib tcl
.. tab:: FreeBSD
.. code:: console
pkg install bison flex readline gawk libffi graphviz \
pkg install bison cmake-core flex readline gawk libffi graphviz \
pkgconf python311 tcl-wrapper
.. note:: On FreeBSD system use gmake instead of make. To run tests use:
``MAKE=gmake CXX=cxx CC=cc gmake test``
.. TODO:: CMAKE_TODO
Is this still required, and (how) does it work with CMake
.. tab:: Cygwin
Use the following command to install all prerequisites, or select these
@ -190,32 +183,35 @@ influence the build process. When setting one-off variables, CMake provides the
.. warning::
Yosys does not support in-tree builds. If calling ``cmake`` from the root
``yosys`` directory the ``-B`` option must be provided.
Yosys does not support in-tree builds. If calling :program:`cmake` from the
root ``yosys`` directory the ``-B`` option must be provided.
For a more persistent configuration, we recommend creating and using a
``CMakeUserPresets.json`` file. Below is an example file which sets the default
compiler to clang when calling ``cmake --preset clang``:
``CMakeUserPresets.json`` file in the root ``yosys`` directory. Below is an
example file which enables ccache and sets the default compiler to clang when
calling ``cmake --preset default``:
.. code:: json
.. code-block:: json
:caption: CMakeUserPresets.json
{
"version": 1,
"configurePresets": [
{
"name": "clang",
"name": "default",
"binaryDir": "build",
"generator": "Unix Makefiles",
"cacheVariables": {
"CMAKE_C_COMPILER": "clang",
"CMAKE_CXX_COMPILER": "clang++"
"CMAKE_CXX_COMPILER": "clang++",
"YOSYS_COMPILER_LAUNCHER": "ccache"
}
}
]
}
Once generated, available build variables can be inspected and modified with
``ccmake`` or opening the generated ``build/CMakeCache.txt`` file:
:program:`ccmake` or opening the generated ``build/CMakeCache.txt`` file:
.. code:: console
@ -233,7 +229,7 @@ from homebrew rather than clang from xcode. For example:
-DCMAKE_C_COMPILER=$(brew --prefix)/opt/llvm/bin/clang \
-DCMAKE_CXX_COMPILER=$(brew --prefix)/opt/llvm/bin/clang++
By default, building (and installing) yosys will build (and install) `ABC`_,
By default, building (and installing) Yosys will build (and install) `ABC`_,
using :program:`yosys-abc` as the executable name. To use an existing ABC
executable instead, set the :makevar:`YOSYS_ABC_EXECUTABLE` CMake variable to
point to the desired executable.
@ -329,11 +325,9 @@ directories:
- if using a sub folder, add it to the parent's ``CMakeLists.txt`` with
``add_subdirectory(<name>)``
The top-level Makefile includes :file:`frontends/{*}/Makefile.inc`,
:file:`passes/{*}/Makefile.inc` and :file:`backends/{*}/Makefile.inc`. So when
extending Yosys it is enough to create a new directory in :file:`frontends/`,
:file:`passes/` or :file:`backends/` with your sources and a
:file:`Makefile.inc`. The Yosys kernel automatically detects all commands linked
- previous:
The Yosys kernel automatically detects all commands linked
with Yosys. So it is not needed to add additional commands to a central list of
commands.

View file

@ -18,7 +18,7 @@ custom passes written in C++.
.. note::
It is recommended to install ``uv`` for managing python environments:
It is recommended to install :program:`uv` for managing python environments:
.. code:: console
@ -30,10 +30,6 @@ Getting Pyosys
Pyosys supports CPython 3.8 or higher. You can access Pyosys using one of two
methods:
.. TODO:: CMAKE_TODO
may still be pending further changes
1. Compiling Yosys with the CMake flag ``-DYOSYS_WITH_PYTHON=ON``
This adds the flag ``-y`` to the Yosys binary, which allows you to execute
@ -42,9 +38,9 @@ methods:
``yosys -y ./my_pyosys_script.py``
Do note this requires some build-time dependencies to be available to Python,
namely, ``pybind11`` and ``cxxheaderparser``. If available, ``uv`` will be
used to create an ephemeral environment with the correct versions of the
tools installed.
namely, ``pybind11`` and ``cxxheaderparser``. :program:`uv` may be used to
create an ephemeral environment with the correct versions of the tools
installed if the current python environment doesn't provide them.
2. Installing the Pyosys wheels

View file

@ -64,12 +64,6 @@ edif edif EDIF support
liberty synlib Liberty file support
============== =========== ===================================
.. TODO:: CMAKE_TODO
``yosys-config --cxxflags`` no longer includes the verific features, and the
CMakeCache.txt doesn't report auto detected :makevar:`YOSYS_VERIFIC_FEATURES`
- can we export these somehow?
.. note::
The YosysHQ specific extensions are only available with the TabbyCAD suite.

View file

@ -16,32 +16,20 @@ tests.
cmake -B build .
cmake --build build --target test --parallel $(nproc)
.. TODO:: CMAKE_TODO
Using ``make -C <docs|tests>`` does work, but only if using default
:makevar:`BUILD_DIR` (``build``) and :makevar:`PROGRAM_PREFIX` (none).
Vanilla tests
~~~~~~~~~~~~~
.. TODO:: update for test infra changes
These make up the majority of our testing coverage. They can be run with the
``test-vanilla`` CMake target, or by calling ``make vanilla-test`` from the
``tests`` directory, and are based on calls to make subcommands (``make
makefile-tests``) and shell scripts (``make seed-tests`` and ``make
abcopt-tests``). Both use ``run-test.sh`` files, but make-based tests only call
``tests/gen-tests-makefile.sh`` to generate a makefile appropriate for the given
directory, so only afterwards when make is invoked do the tests actually run.
Usually their structure looks something like this:
you write a .ys file that gets automatically run,
which runs a frontend like ``read_verilog`` or ``read_rtlil`` with
a relative path or a heredoc, then runs some commands including the command
under test, and then uses :doc:`/using_yosys/more_scripting/selections`
with ``-assert-count``. Usually it's unnecessary to "register" the test anywhere
as if it's being added to an existing directory, depending
on how the ``run-test.sh`` in that directory works.
``test-vanilla`` CMake target. Usually their structure looks something like
this: you write a .ys file that gets automatically run, which runs a frontend
like ``read_verilog`` or ``read_rtlil`` with a relative path or a heredoc, then
runs some commands including the command under test, and then uses
:doc:`/using_yosys/more_scripting/selections` with ``-assert-count``. Usually
it's unnecessary to "register" the test anywhere as if it's being added to an
existing directory, depending on how the ``run-test.sh`` in that directory
works.
Unit tests
~~~~~~~~~~
@ -90,23 +78,21 @@ instructions <https://github.com/Z3Prover/z3>`_.
.. TODO:: CMAKE_TODO
How does this work under CMake? Is it only via ``make -C tests ENABLE_FUNCTIONAL_TESTS=1``
How does this work under CMake? Is it only via ``make -C tests
ENABLE_FUNCTIONAL_TESTS=1`` and then manually setting ``BUILD_DIR`` and
``PROGRAM_PREFIX``? And possibly also setting ``YOSYS`` et al if there is a
``.exe``. Previous instructions:
Then, set the :makevar:`ENABLE_FUNCTIONAL_TESTS` make variable when calling
``make test`` and the functional tests will be run as well.
Then, set the :makevar:`ENABLE_FUNCTIONAL_TESTS` make variable when calling
``make test`` and the functional tests will be run as well.
Docs tests
~~~~~~~~~~
.. TODO:: CMAKE_TODO
Is this available via CMake?
There are some additional tests for checking examples included in the
documentation, which can be run by calling ``make test`` from the
:file:`yosys/docs` sub-directory (or ``make -C docs test`` from the root). This
also includes checking some macro commands to ensure that descriptions of them
are kept up to date, and is mostly intended for CI.
documentation, which can be run with the ``test-docs`` CMake target. This also
includes checking some macro commands to ensure that descriptions of them are
kept up to date, and is mostly intended for CI.
Automatic testing

View file

@ -28,11 +28,7 @@
#include <stdlib.h>
#include <stdio.h>
#include <errno.h>
#if !defined(__wasm)
#include <filesystem>
namespace fs = std::filesystem;
#endif
YOSYS_NAMESPACE_BEGIN
@ -777,10 +773,9 @@ struct HelpPass : public Pass {
bool raise_error = false;
std::map<string, vector<string>> groups;
#if !defined(__wasm)
auto this_path = fs::path(source_location::current().file_name());
// get root path
auto this_path = std::filesystem::path(source_location::current().file_name());
auto source_root = this_path.parent_path().parent_path();
#endif
json.name("cmds"); json.begin_object();
// iterate over commands
@ -922,19 +917,18 @@ struct HelpPass : public Pass {
}
}
// fix path
string source_file = pass->location.file_name();
bool has_source = source_file.compare("unknown") != 0;
#if !defined(__wasm)
// fix path
fs::path source_path;
std::filesystem::path source_path;
auto no_source_group = false;
if (has_source) {
source_path = fs::path(pass->location.file_name());
source_path = std::filesystem::path(pass->location.file_name());
if (source_path.is_absolute()) {
// using proximate instead of relative means that we
// still get the source path if they aren't relative
auto proximate_path = fs::proximate(source_path, source_root);
if (proximate_path == fs::weakly_canonical(proximate_path))
auto proximate_path = std::filesystem::proximate(source_path, source_root);
if (proximate_path == std::filesystem::weakly_canonical(proximate_path))
// we're only interested if it's a subpath of our root dir
source_path = proximate_path;
else
@ -943,7 +937,6 @@ struct HelpPass : public Pass {
}
source_file = source_path.string();
}
#endif
// attempt auto group
if (!cmd_help.has_group()) {
@ -954,16 +947,8 @@ struct HelpPass : public Pass {
else if (source_file.find("frontends/") == 0 || (!has_source && name.find("write_") == 0))
cmd_help.group = "frontends";
else if (has_source) {
#if !defined(__wasm)
if (source_path.has_parent_path() && !no_source_group)
cmd_help.group = source_path.parent_path();
#else
auto last_slash = source_file.find_last_of('/');
if (last_slash != string::npos) {
auto parent_path = source_file.substr(0, last_slash);
cmd_help.group = parent_path;
}
#endif
}
// implicit !has_source
else if (name.find("equiv") == 0)