mirror of
https://github.com/roc-lang/roc.git
synced 2024-09-22 08:17:40 +03:00
Update hello-world host
This commit is contained in:
parent
ff8bb64bae
commit
9f0b3bba9f
18
examples/hello-world/platform/host/README.md
Normal file
18
examples/hello-world/platform/host/README.md
Normal file
@ -0,0 +1,18 @@
|
||||
# Rebuilding the host from source
|
||||
|
||||
Here are the current steps to rebuild this host.
|
||||
|
||||
> This is a C host, which is the simplest to build.
|
||||
> For an example of a Rust host, see the quicksort example.
|
||||
|
||||
First, `cd` into `host/src/` and rebuild `host.o` like so:
|
||||
|
||||
```
|
||||
$ clang -c host.c -o host.o
|
||||
```
|
||||
|
||||
Next, move `host.o` into the appropriate `platform/` subdirectory
|
||||
based on your architecture and operating system. For example,
|
||||
on macOS, you'd move `host.o` into the `platform/host/x86_64-unknown-darwin10/` directory.
|
||||
|
||||
Congratulations! You now have an updated host.
|
@ -1,23 +0,0 @@
|
||||
#![crate_type = "staticlib"]
|
||||
|
||||
use std::ffi::CStr;
|
||||
use std::os::raw::c_char;
|
||||
|
||||
extern "C" {
|
||||
#[link_name = "main_1"]
|
||||
fn str_from_roc() -> *const c_char;
|
||||
}
|
||||
|
||||
// This magical #[export_name] annotation seems to be the only way to convince
|
||||
// LLVM to emit this as the symbol "start" rather than "_start" on macOS.
|
||||
// The linker will not recognize "_start" as the program entrypoint.
|
||||
//
|
||||
// See https://github.com/rust-lang/rust/issues/35052#issuecomment-235420755
|
||||
#[export_name = "\x01start"]
|
||||
pub extern "C" fn main(_argc: isize, _argv: *const *const u8) -> isize {
|
||||
let c_str = unsafe { CStr::from_ptr(str_from_roc()) };
|
||||
|
||||
println!("Roc says: \"{}\"", c_str.to_str().unwrap());
|
||||
|
||||
0
|
||||
}
|
Loading…
Reference in New Issue
Block a user