Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/sunfishcode/eyra-c
Support for compiling C programs with Eyra
https://github.com/sunfishcode/eyra-c
rust
Last synced: 5 days ago
JSON representation
Support for compiling C programs with Eyra
- Host: GitHub
- URL: https://github.com/sunfishcode/eyra-c
- Owner: sunfishcode
- Created: 2023-12-12T19:48:15.000Z (11 months ago)
- Default Branch: main
- Last Pushed: 2024-10-13T17:03:02.000Z (about 1 month ago)
- Last Synced: 2024-11-01T12:52:20.295Z (12 days ago)
- Topics: rust
- Language: Rust
- Homepage:
- Size: 11.7 KB
- Stars: 13
- Watchers: 3
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# eyra-c
Support for compiling C programs with Eyra.
Specifically, this repo compiles [Eyra] into a [staticlib] to make a libc.a:
```sh
$ cargo build
Compiling eyra-c v0.0.0 (/home/eyra/ecosystem/eyra-c)
Finished dev [unoptimized + debuginfo] target(s) in 0.00s
$ ls target/debug/libc.a
target/debug/libc.a
$
```This libc.a can be used by C compilers, with -nostdlib to disable the
system libraries:```sh
$ cat c-tests/src/hello.c
#includeint main(void) {
printf("Hello, world!\n");
return 0;
}
$ cc c-tests/src/hello.c -nostdlib target/debug/libc.a
$ ./a.out
Hello, world!
$
```💃
Amusingly, even though this libc.a is built entirely from Rust, it cannot be
used by Rust programs, because a staticlib library is meant to be linked into
a C program, so it includes the Rust standard library. If linked into a Rust
program, it would conflict with the Rust standard library.To use Eyra in a Rust program, [use Eyra as a dependency].
[Eyra]: https://github.com/sunfishcode/eyra
[staticlib]: https://doc.rust-lang.org/reference/linkage.html#linkage
[use Eyra as a dependency]: https://github.com/sunfishcode/eyra#quick-start