-
Notifications
You must be signed in to change notification settings - Fork 0
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
Add minimal LibC
module
#347
Merged
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
edsko
approved these changes
Jan 8, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewed over meet. Feel free to merge after making the changes discussed.
* References to standards are added. * Headers that are not included in musl are commented out and documented.
This is just done so that we have a place to put the Musl `VERSION` and `COPYRIGHT` files.
Using `appendFile` caused the log file to accumulate logs over multiple executions. This commit instead opens the log file in `Main`, overwriting any existing log file. Since we already use a tracer for logging, logging to this file is also done using a tracer for consistency.
The Clang default is `gnu17`, which is not what we want. This commit implements a new `--standard` CLI option that defaults to `c17`. To avoid confusion, `-std` options are prohibited from being specified in a `--clang-option`.
This is done so that we can work with the headers for different architectures.
The headers can be installed *without* any compilation if configuration is done manually, not using the `configure` script since it checks for cross-compilation toolchains. The script no longer has to run on an `x86_64` architecture. Since toolchains are no longer needed, this enables us to easily vendor headers for more architectures.
The type is still `String`, since the target triple is system-dependent in that it depends on the name of the toolchains installed. If/when we need to use this value for other purposes, we will likely need to parse it to a different type.
Setting an include directory is required for the command to work. This option sets a default when there are vendored Musl headers for the host architecture. When there are not vendored Musl headers for the host architecture, the user must specify the option. Option `-nostdinc` is now always set for this command. Oddly, this option is not displayed in the `--help` output on my system, but there is no error when using it, and I see it in the current documentation online. The include directory is passed to Clang via `-isystem`.
This commit includes the "easy" types. Once merged, we can start work on integrating using of the library while simultaneously filling in the details. Notes: * The `x86_64` architecture `Arch` module is put in place, though no architecture-specific types that require it are implemented yet. TODO comments marked "`arch`" need to be implemented in `Arch` modules. * As decided on in our last call, integral types with a specific bit width are implemented using corresponding Haskell types. This allows them to be implemented in general, not in `Arch` modules. * Documentation indicates that `stdint.h` should define types `int_fast8_t`, `int_fast16_t`, `int_fast32_t`, and `int_fast64_t` (as well as the unsigned versions), but Musl does *not* define `int_fast16_t` or `int_fast32_t` (or the unsigned versions). I went ahead and implemented them in the module anyway. * No types from `stdatomic.h`, `stdbit.h`, or `stdckdint.h` are implemented yet. These are not (yet) supported by Musl. * The types implemented use names that match those in `base`. I can rename them to use our default name mangling rules if we decide to do that instead. I did not implement any structures or enumerations yet; I will do so once we decide on naming.
TravisCardwell
force-pushed
the
c-types-prelude
branch
from
January 8, 2025 22:00
6f53d26
to
bd1706c
Compare
Changes:
We will do doubt make further changes as we refine the design, but I am merging this as an initial implementation. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The purpose of this PR is to merge a minimal
LibC
implementation so that we can start thinking about how to integrate it intohs-bindgen
.Here is the relevant commit message:
Other changes included in this PR:
bootstrap/standard_headers.h
is documented, with links to references.musl-update.sh
can be used to easily add architectures as well as update to new versions, without requiring any cross-compilation toolchains.VERSION
andCOPYRIGHT
files are now included.hs-bindgen
top-level options are added:--standard
allows selection of the C standard.--gnu
enables GNU extensions.--target
allows specification of the target architecture (triple).c17
by default, instead ofgnu17
(the Clang default).prelude
command no longer appends to the log file; it instead overwrites any existing log file with a new one.prelude
command now has an--include
option for specifying the header directory to use. When Musl headers for the host architecture are vendored, it defaults using them. Otherwise, the user must specify a directory.