Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement CMake build system #647

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open

Conversation

Timmmm
Copy link
Collaborator

@Timmmm Timmmm commented Dec 18, 2024

Switch from Makefiles to CMake. Some formal outputs are not yet fully supported by the CMake so the old Makefile is retained.

CMake has significant advantages:

  • IDE support is perfect, since it generates compile_commands.json. You can even go-to-definition to the generated code (I can demo this in the meeting if people want). Lots of IDEs also understand CMake and CTest.
  • Building all the emulators and running the tests is easy, parallel, and can generate an XML test result file (I haven't tested this though).
  • Better Windows support, e.g. CMake can generate Visual Studio project files.

This also adds a manual Github actions workflow to generate the JSON doc bundle, to allow inclusion of Sail snippets in the ISA manual.

@Timmmm Timmmm mentioned this pull request Dec 18, 2024
CMakeLists.txt Outdated Show resolved Hide resolved
CMakeLists.txt Outdated Show resolved Hide resolved
Copy link
Collaborator

@arichardson arichardson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall this is looking good!
I've left a few CMake comments, but it's quite hard to review with the softfloat upgrade included here.

@Timmmm Timmmm force-pushed the user/timh/cmake branch 2 times, most recently from bad1feb to 80d0154 Compare January 2, 2025 15:02
@Timmmm
Copy link
Collaborator Author

Timmmm commented Jan 2, 2025

Thanks for the review! I've split the other changes out into separate commits, so the CMake stuff is just the last commit now and hopefully easier to review.

I might drop the upgrade to softfloat actually since it didn't really change the code and hopefully we'll remove it at some point anyway in favour of the pure Sail implementation.

@jordancarlin
Copy link
Collaborator

I think it probably makes sense to skip the softfloat upgrade for the reasons you mentioned, but if we do decide to keep it I have some suggestions so that you don’t have to modify their Makefile.

Copy link
Collaborator

@arichardson arichardson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Regarding the commit that suggests bundling GMP - we could also use https://cmake.org/cmake/help/latest/module/ExternalProject.html#examples to build a known version statically (either opt-in or by default).

Makefile Show resolved Hide resolved
Copy link
Collaborator

@arichardson arichardson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few minor comments but generally looks good to me.

.gitignore Show resolved Hide resolved
CMakeLists.txt Outdated Show resolved Hide resolved
CMakeLists.txt Outdated Show resolved Hide resolved
CMakeLists.txt Outdated Show resolved Hide resolved
CMakeLists.txt Show resolved Hide resolved
emulator/CMakeLists.txt Outdated Show resolved Hide resolved
CMakeLists.txt Outdated Show resolved Hide resolved
cmake/extra_fast.cmake Outdated Show resolved Hide resolved
@Timmmm
Copy link
Collaborator Author

Timmmm commented Jan 3, 2025

if we do decide to keep it I have some suggestions so that you don’t have to modify their Makefile.

We aren't actually using their Makefile at all with the CMake version; I just kept the modifications so that it compiled as a standalone commit. I'll just remove the upgrade anyway though.

@arichardson I think you put a comment somewhere that I can't find now about keeping the Makefile. I think I'll just try and implement all of the features currently in the Makefile before merging this, rather than have two build systems...

Copy link
Collaborator

@arichardson arichardson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding all the other targets may take quite a while, maybe easiest for now to add CMake support and remove targets from the Makefile as we port them over?

E.g. this PR just removes the csim target (or rather have it defer to CMake cmake -S . -B $(BUILD_DIR) -DCMAKE_BUILD_TYPE=Release && $(MAKE) -C $(BUILD_DIR)) and then later commits add the extra features? Otherwise I worry this will be a long standing feature branch that never gets merged.

@jrtc27
Copy link
Collaborator

jrtc27 commented Jan 9, 2025

Adding all the other targets may take quite a while, maybe easiest for now to add CMake support and remove targets from the Makefile as we port them over?

E.g. this PR just removes the csim target (or rather have it defer to CMake cmake -S . -B $(BUILD_DIR) -DCMAKE_BUILD_TYPE=Release && $(MAKE) -C $(BUILD_DIR)) and then later commits add the extra features? Otherwise I worry this will be a long standing feature branch that never gets merged.

Doing CMake incrementally makes sense to me, but I'd rather not incrementally remove things from Makefile. It's annoying to have to use both depending on what you want to do. I don't really see the benefit of it. Just leave Makefile alone until it's entirely subsumed by CMakeLists.txt and then delete it.

@arichardson
Copy link
Collaborator

Adding all the other targets may take quite a while, maybe easiest for now to add CMake support and remove targets from the Makefile as we port them over?
E.g. this PR just removes the csim target (or rather have it defer to CMake cmake -S . -B $(BUILD_DIR) -DCMAKE_BUILD_TYPE=Release && $(MAKE) -C $(BUILD_DIR)) and then later commits add the extra features? Otherwise I worry this will be a long standing feature branch that never gets merged.

Doing CMake incrementally makes sense to me, but I'd rather not incrementally remove things from Makefile. It's annoying to have to use both depending on what you want to do. I don't really see the benefit of it. Just leave Makefile alone until it's entirely subsumed by CMakeLists.txt and then delete it.

That sounds even better to me

@billmcspadden-riscv
Copy link
Collaborator

billmcspadden-riscv commented Jan 9, 2025 via email

@Timmmm
Copy link
Collaborator Author

Timmmm commented Jan 10, 2025

I've rebased it, removed the c_emulator rename and the softfloat update (we can do that later), and added RVFI support. I also updated the CI scripts.

I'm not sure I'm much of a fan of having two build systems during a transition. Verilator has exactly this - an old ./configure && make and an "experimental" CMake build system, and IMO it is quite confusing for users, and probably annoying for developers.

I reckon I can add the other targets without too much trouble, assuming they still work anyway! They aren't tested by CI and are presumably very rarely used.

@@ -1,428 +0,0 @@
# Select architecture: RV32 or RV64.
ARCH ?= RV64
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to keep makefile for now for the prover stuff?

Makefile Outdated Show resolved Hide resolved
Makefile Outdated Show resolved Hide resolved
Copy link
Collaborator

@arichardson arichardson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall I still think this is a great change. A few things that were supported are no longer there.

I wonder if we should keep the Makefile for now and add something like the following to the top:

ifndef I_REALLY_NEED_TO_USE_MAKE
$(error The Makefile build system is deprecated, please use CMake instead. If you are using a target that does not exist there yet, please file and issue and re-run make with I_REALLY_NEED_TO_USE_MAKE=1 until this has been fixed)
endif

@jordancarlin
Copy link
Collaborator

The Makefile is still pointing at the old location for softfloat. I know we want to encourage everyone to use the new CMake flow, but if we are going to keep the old Makefile around I think we should make sure it is still functional. Or remove the c emulator targets from it and only leave the formal backends.

@Timmmm
Copy link
Collaborator Author

Timmmm commented Jan 20, 2025

Good point, I'll fix that. Also I think I forgot to do the RelWithDebInfo change - I'll do that in the morning.

@jordancarlin
Copy link
Collaborator

My other concern is changing the name of the generated executable itself. Currently it's riscv_sim_ARCH, which makes it clear what it is if copied to a bin directory. The switch to c_emulator_ARCH removes this easy recognition and doesn't seem to provide much benefit. If we want to explicitly call out that it is the c emulator (as opposed to the SystemVerilog one) maybe something like riscv_csim_ARCH would be better.

Makefile.old Outdated Show resolved Hide resolved
@Timmmm Timmmm added the tgmm-agenda Tagged for the next Golden Model meeting agenda. label Jan 22, 2025
@Timmmm Timmmm marked this pull request as ready for review January 27, 2025 10:11
@Timmmm
Copy link
Collaborator Author

Timmmm commented Jan 27, 2025

I rebased it, updated it for the Coq output (which now builds with the latest sail2 compiler, but it doesn't do everything the Makefile does), and also added a Github actions workflow to generate the JSON docs.

My aim for the latter is to run it manually and make a Github Release with it attached, so we can start including Sail snippets in the ISA manual (as we do for CHERI).

@Timmmm Timmmm added will be merged Scheduled to be merged in a few days if nobody objects and removed tgmm-agenda Tagged for the next Golden Model meeting agenda. labels Jan 27, 2025
build_simulators.sh Outdated Show resolved Hide resolved
.pre-commit-config.yaml Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
Move the softfloat library to a dependencies directory. In future we can add GMP there too to reduce the number of external dependencies needed and to support static linking.

The directory was renamed from `SoftFloat-3e` to `berkeley-softfloat-3` because that's how the latest version is named.

It hasn't been upgraded in this commit to make it simpler to review and help Git track history. A future commit will upgrade it.
Copy link
Collaborator

@arichardson arichardson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor suggestion on the CI file but still LGTM

.github/workflows/compile.yml Show resolved Hide resolved
.github/workflows/compile.yml Outdated Show resolved Hide resolved
Switch from Makefiles to CMake. Some formal outputs are not yet fully supported by the CMake so the old Makefile is retained.

This also adds a manual Github actions workflow to generate the JSON doc bundle, to allow inclusion of Sail snippets in the ISA manual.
Timmmm and others added 2 commits January 29, 2025 09:05
Co-authored-by: Alexander Richardson <[email protected]>
Signed-off-by: Tim Hutt <[email protected]>
Co-authored-by: Alexander Richardson <[email protected]>
Signed-off-by: Tim Hutt <[email protected]>
Copy link

github-actions bot commented Jan 29, 2025

Test Results

392 tests   - 4   392 ✅  - 4   49s ⏱️ +49s
  1 suites  - 3     0 💤 ±0 
  1 files   ±0     0 ❌ ±0 

Results for commit 8f62c29. ± Comparison against base commit 8a75b29.

This pull request removes 396 and adds 392 tests. Note that renamed tests count towards both.
Building 32-bit RISCV C emulator
Building 32-bit RISCV RVFI C emulator
Building 64-bit RISCV C emulator
Building 64-bit RISCV RVFI C emulator
C-32 rv32mi-p-breakpoint.elf
C-32 rv32mi-p-csr.elf
C-32 rv32mi-p-illegal.elf
C-32 rv32mi-p-ma_addr.elf
C-32 rv32mi-p-ma_fetch.elf
C-32 rv32mi-p-mcsr.elf
…
rv32d_rv32mi-p-breakpoint.elf ‑ rv32d_rv32mi-p-breakpoint.elf
rv32d_rv32mi-p-csr.elf ‑ rv32d_rv32mi-p-csr.elf
rv32d_rv32mi-p-illegal.elf ‑ rv32d_rv32mi-p-illegal.elf
rv32d_rv32mi-p-ma_addr.elf ‑ rv32d_rv32mi-p-ma_addr.elf
rv32d_rv32mi-p-ma_fetch.elf ‑ rv32d_rv32mi-p-ma_fetch.elf
rv32d_rv32mi-p-mcsr.elf ‑ rv32d_rv32mi-p-mcsr.elf
rv32d_rv32mi-p-sbreak.elf ‑ rv32d_rv32mi-p-sbreak.elf
rv32d_rv32mi-p-scall.elf ‑ rv32d_rv32mi-p-scall.elf
rv32d_rv32mi-p-shamt.elf ‑ rv32d_rv32mi-p-shamt.elf
rv32d_rv32si-p-csr.elf ‑ rv32d_rv32si-p-csr.elf
…

♻️ This comment has been updated with latest results.

Copy link
Collaborator

@jordancarlin jordancarlin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Definitely more optimizations to make in the future, but at this point this seems good to go now that CI is properly functioning again.

@Timmmm
Copy link
Collaborator Author

Timmmm commented Jan 29, 2025

Ok I will merge this later today!

@jrtc27
Copy link
Collaborator

jrtc27 commented Jan 29, 2025

Test Results

392 tests   - 4   392 ✅  - 4   49s ⏱️ +49s   1 suites  - 3     0 💤 ±0    1 files   ±0     0 ❌ ±0 

Results for commit 8818308. ± Comparison against base commit 8a75b29.

This pull request removes 396 and adds 392 tests. Note that renamed tests count towards both.

Why have we lost 4 tests and 3 suites?

@Timmmm
Copy link
Collaborator Author

Timmmm commented Jan 29, 2025

Why have we lost 4 tests and 3 suites?

Good question - the 4 lost are because the old output had compiling the models as tests.

Building 32-bit RISCV C emulator
Building 32-bit RISCV RVFI C emulator
Building 64-bit RISCV C emulator
Building 64-bit RISCV RVFI C emulator

The 3 suites are because the previous test runner script split the tests up into suites based on the above 4 models. In the new version they are combined.

I double checked that it is running all the same tests. You can see the list on the build CI job.

Note, the old script compiles the RVFI emulators but doesn't actually run any tests on them. This CMake version does the same.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
will be merged Scheduled to be merged in a few days if nobody objects
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants