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 Meson (take 2) #1836

Open
wants to merge 18 commits into
base: dev
Choose a base branch
from
Open

Implement Meson (take 2) #1836

wants to merge 18 commits into from

Conversation

Kangie
Copy link

@Kangie Kangie commented Jan 14, 2025

This PR picks up after #1097 (thanks @Opaatia) and rebases it on current HEAD.

I was asked to look into completing the port, so I'm not super familiar with c3c - apologies for any obvious oversights / questions!

While some existing CMake logic remains to be ported, there's an opportunity to potentially simplify it. Any guidance on the preferred approach (simplifying vs. following existing logic) would be greatly appreciated.

Progress and remaining tasks:

Done so far:

  • remove tilde-backend sources completely including .gitmodules
  • generate git_hash.h and conifgure git_hash.h.in (new file)
  • set default project arguments c{,pp}_std, warning_level buildtype
  • add summary output
  • llvm rtti detection
  • Wired up CI for Linux (ubuntu-latest), MacOS, msys2, Windows.
  • Docs (patches didn't apply cleanly; just focus on meson for now)
  • LLVM is again optional
  • MacOS support (pending CI testing)
  • Windows/msvc support (pending CI testing)

Not implemented:

  • Fetching LLVM on Windows
  • Mimalloc (would need a submodule, or ideally a Meson WrapDB

Please let me know if there are any changes that I can make while I'm here.

@lerno
Copy link
Collaborator

lerno commented Jan 14, 2025

Wrapper uses LLD for the linker as well. I think the wrapper doesn't need to be compiled if compiling without LLVM. However, the possibility to use the internal linker must then be turned off.

@lerno
Copy link
Collaborator

lerno commented Jan 14, 2025

I think LLVM optional was for people working on additional backends. Normally, LLVM should be required.

@lerno
Copy link
Collaborator

lerno commented Jan 14, 2025

Let me know what else I can help out with.

@Kangie
Copy link
Author

Kangie commented Jan 15, 2025

Excellent, thank you. I can get that logic in re: LLVM.

Re tilde-backend - I note that a lot of the sources have in-repo been removed, but there's still a .gitmodules referencing the repo that doesn't properly init:

c3c/.gitmodules

Lines 1 to 3 in 70da1f7

[submodule "tilde-backend"]
path = tilde-backend
url = https://github.com/c3lang/tilde-backend

Should I fix the submodule or purge the .gitmodules?

@lerno
Copy link
Collaborator

lerno commented Jan 15, 2025

You can drop .gitmodules completely.

@Kangie Kangie force-pushed the meson branch 3 times, most recently from 9e63e93 to f0e6467 Compare January 16, 2025 13:55
@Kangie
Copy link
Author

Kangie commented Jan 16, 2025

Added some CI that will let me get started on 'Windows' and 'MacOS'. Hopefully it's all straightforward!

Rebased on current dev. Test suite mostly running via meson on Linux, and what isn't running I'll look into - I may have fat-fingered some unit tests while removing boilerplate. Edit: Some things had moved around or been split into multiple tests, no actual failures!

Ok:                 404 
Expected Fail:      0   
Fail:               0   
Unexpected Pass:    0   
Skipped:            0   
Timeout:            0   

Can you enlighten me as to the meaning of the c3 file ext instead of the more common c3t in test/unit_suite/*? - I've eyeballed a few files and can't see any obvious differences.

$ ls test/test_suite/assignment/
alignment_index.c3t  int_assign.c3t  var_variable.c3

@Kangie Kangie changed the base branch from master to dev January 16, 2025 13:58
@Kangie Kangie force-pushed the meson branch 2 times, most recently from 718df4c to a7f88e5 Compare January 16, 2025 14:32
@Kangie Kangie force-pushed the meson branch 4 times, most recently from 656443e to 80c5d9f Compare January 17, 2025 05:44
@Kangie
Copy link
Author

Kangie commented Jan 17, 2025

I've squashed down the previous PR into a single commit, and my changes so far down as far as I can at this point.

May need to script up something to generate the list of tests to be 100% sure I got 'em all but we're looking pretty good.

If someone is able to unblock the CI workflow I'll see if I can get Windows and MacOS builds going - Pretty much all of the logic is ported and we're just on to working out what I broke in CI and any edge cases or things I overlooked :)

I think the wrapper doesn't need to be compiled if compiling without LLVM. However, the possibility to use the internal linker must then be turned off.

Do we need to add some preprocessor stuff for that (I don't see any existing toggles) or is the intent that users just don't set --linker=builtin?

@lerno
Copy link
Collaborator

lerno commented Jan 17, 2025

There are two sets of tests: one is the unit test variant, the other is what runs by way of a python script.

The python script accepts two types of files (from the ancient times when the compiler was first written): The regular .c3 files which are just compiled normally, doing type checking, and the .c3t files which actually compile things and check the LLVM IR output. They have slightly different directives (in comments) available to them, and because originally things like /* without terminator */ wasn't available, it needed to be in a slightly different format. But actually this is not strictly needed anymore, so when the c3-based external tester is done, these could also be .c3 files. (Although it's been kind of useful to see which ones are supposed to error and which ones are supposed to compile).

BWindey and others added 6 commits January 17, 2025 12:23
* Fix missing newline and incorrect indentation for 'c3c project' help on fetch

* Use a ternary trick :D

---------

Co-authored-by: Christoffer Lerno <[email protected]>
…ools.

Contracts @require/@Ensure are no longer treated as conditionals, but must be explicitly bool.
@Kangie Kangie force-pushed the meson branch 3 times, most recently from 10a03a0 to 4d668a2 Compare January 19, 2025 09:43
Kangie and others added 6 commits January 19, 2025 19:44
A translation of CMake to Meson Build, pending work required for compatibility check on other platforms like Windows and OSX. This is tested and confirmed to work on Arch Linux latest version.

Features:
  - Option Checks for Hiding Warnings
  - Added check.py for checking the exit code of running a given unit test. Generated a huge 400+ unit test cases list for this build.
    Used to determine whether unit test pass or fail by providing exit code for meson test cases to use. This uses Regular Expressions for determining the number of passed tests out of total tests.
  - A simple utility for generate meson test cases
- handle additional search path required for gentoo (etc)
- sort c3c_deps
- Move tests to test/
  Also programatically generate tests since each is effectively
  identical, this should be a lot easier to maintain (and a lot less
  for eyes to skim over) in future and saves on a _ton_ of boilerplate.

  It would be possible to 'subdir' each of the suites so that they're
  not all defined in one place (or closer to the actual tests!), but
  that's a matter of taste and workflow.

- use `files` for sources

  `files` returns File objects which can be used as sources for build
  targets. File objects remember the subdirectory that they were
  defined in and can be used anywhere in the build, which should
  make it easier to refactor later if desired.

- remove tilde-backend sources - no longer in tree
- remove '`.gitmodules`, only contained tilde-backend
- generate `git_hash.h` from `git_hash.h.in` using `git describe` and
  falling back to the version number set in Meson.
- set default project arguments `c{,pp}_std`
- add summary output
- rtti detection (llvm-config && CMake)
- make LLVM optional
- MacOS and Windows support

Signed-off-by: Matt Jolly <[email protected]>
@Kangie Kangie force-pushed the meson branch 5 times, most recently from 90f4630 to d958665 Compare January 19, 2025 10:10
Meson wants release types in lowercase, and Cmake needs e.g. 'Debug'.

Do some string maniuplation where required.

Ubuntu-latest: 'focal' -> 'noble' - latest has moved

Meson: Set version range >=majver < majver+1 where reqd
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants