opened
jyn514
username_0
### Expected behavior
<!-- A description of what you expected to happen.
     You could also paste the output of another compiler,
     I like `clang -x c - -Wall -Wextra -pedantic` -->
`#include<stddef.h>` should work. I was under the impression this should be part of libc, but glibc at least expects it to be part of the compiler: https://stackoverflow.com/questions/31600600/compilation-error-stddef-h-no-such-file-or-directory, https://releases.llvm.org/9.0.0/tools/clang/docs/LibTooling.html#builtin-includes

`stddef.h` at least looks really simple to write, the hard part will be distributing it properly.

### Code
<!-- The code that was not interpreted correctly goes here.
     This should also include the error message you got. -->

```c
#include<stddef.h>
<stdin>:1:2 error: invalid macro: file 'stddef.h' not found
#include<stddef.h>
 ^^^^^^^^^^^^^^^^^
```
```

<!-- If you know where to find it, include the relevant part of the C standard
    There's a copy at http://port70.net/~nsz/c/c11/n1570.html -->
http://port70.net/~nsz/c/c11/n1570.html#7.19
Missing stddef.h
issue
created
jyn514
username_0
This is going to be a nightmare to fix. Extracts from a conversation on Discord:

- There is no supported way to distribute files other than a binary with cargo. They might be present on the filesystem, but there is no guarantee that `$CARGO_HOME` will be set
- Even if there were files in `~/.cargo` whenever `$CARGO_HOME` is unset, there's no way to get to them other than hard-coding `$HOME/.cargo/registry/src/github.com-1ecc6299db9ec823/rcc-0.8.0` into the binary
- If we solve _that_ problem, we then have to worry about platform-specific includes. My idea here was to have intrinsic macros, but this sort of falls apart for `stdint.h` since there are so _many_.

I'm going to leave this alone for a while in hopes that someone else comes up with a bright idea.
comment
created
jyn514
username_0
Possible alternatives:

- no `stddef.h` lol (the current situation)
- hard code it in the binary with `include_str!`. Hope that the include was correct, because it can't be updated. It will have to take into account multiple platforms.
- Intrinsic macros, which will work but be an absolute pain
- Bundle the files with cargo anyway, hardcode `$HOME/.cargo/registry/src/github.com-1ecc6299db9ec823/rcc-0.8.0`, hope that cargo never changes its file paths
- Bundle the files with cargo, look for them files relative to the `rcc` binary. Breaks immediately since cargo does not put the files relative to the binary, but works if done more intentionally with a `.deb` or something. This is how all other compilers work.
- ... other ideas?
comment
created
jyn514
username_0
Oh and a further issue with intrinsic macros is that they have to keep track of whether the file's been included or not, because `NULL` should be an error unless you include `stddef.h`. This isn't hard, I just have to remember to do it.
comment
created
jyn514
username_0
@Kixiron suggested https://github.com/burtonageo/cargo-bundle
comment
closed
jyn514
username_0
issue
created
jyn514
username_0
I ended up implementing this with `include_str!`, which means it won't work when cross-compiling. I'm leaving that for a future issue.

It also currently only supports the x86_64 architecture, but that shouldn't be _too_ hard to fix: just add a new `headers/$target` subdirectory for each target.
comment