This commit is contained in:
Eric S. Londres 2021-03-22 16:20:45 -04:00
commit ec9c07169d
Signed by: slondr
GPG Key ID: A2D25B4D5CB970E4
13 changed files with 18546 additions and 0 deletions

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
/target

40
Cargo.lock generated Normal file
View File

@ -0,0 +1,40 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
[[package]]
name = "cc"
version = "1.0.67"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e3c69b077ad434294d3ce9f1f6143a2a4b89a8a2d54ef813d85003a4fd1137fd"
dependencies = [
"jobserver",
]
[[package]]
name = "guile-test"
version = "0.1.0"
dependencies = [
"cc",
"libc",
"pkg-config",
]
[[package]]
name = "jobserver"
version = "0.1.21"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5c71313ebb9439f74b00d9d2dcec36440beaf57a6aa0623068441dd7cd81a7f2"
dependencies = [
"libc",
]
[[package]]
name = "libc"
version = "0.2.90"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ba4aede83fc3617411dc6993bc8c70919750c1c257c6ca6a502aed6e0e2394ae"
[[package]]
name = "pkg-config"
version = "0.3.19"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3831453b3449ceb48b6d9c7ad7c96d5ea673e9b470a1dc578c2ce6521230884c"

13
Cargo.toml Normal file
View File

@ -0,0 +1,13 @@
[package]
name = "guile-test"
version = "0.1.0"
authors = ["Eric S. Londres <elondres@stevens.edu>"]
edition = "2018"
build = "build.rs"
[dependencies]
libc = "0.2"
[build-dependencies]
cc = { version = "1.0", features = ["parallel"] }
pkg-config = "0.3"

14
Makefile Normal file
View File

@ -0,0 +1,14 @@
CFLAGS= `guile-config compile`
LIBS= `guile-config link`
guile-test: guile-test.o main.c
gcc $? -o $@ $(LIBS)
guile-test.o: guile-test.c
gcc -c $< -o $@ $(CFLAGS)
clean:
rm -f guile-test.o
distclean: clean
rm -f guile-test

14
build.rs Normal file
View File

@ -0,0 +1,14 @@
fn main() {
println!("cargo:rustc-link-search=native=/usr/include/guile/2.2");
println!("cargo:rustc-link-search=/usr/lib");
println!("cargo:rustc-link-lib=guile-2.2");
pkg_config::probe_library("guile-2.2").unwrap();
cc::Build::new()
.include("/usr/include/guile/2.2")
.object("/usr/lib/libguile-2.2.so")
.flag("-lguile-2.2")
.flag("-pthread")
.flag("-lgc")
.file("guile-test.c")
.compile("guile-test");
}

13
guile-test.c Normal file
View File

@ -0,0 +1,13 @@
#include <libguile.h>
#include "guile-test.h"
static void * register_functions(void * data) {
return 0; // NULL
}
void run_scm(int argc, char ** argv) {
scm_with_guile(&register_functions, 0);
scm_shell(argc, argv);
}

7
guile-test.h Normal file
View File

@ -0,0 +1,7 @@
#pragma once
#include <libguile.h>
static void * register_functions(void * data);
void run_scm(int argc, char ** argv);

BIN
guile-test.o Normal file

Binary file not shown.

BIN
guile-test.so Executable file

Binary file not shown.

5
main.c Normal file
View File

@ -0,0 +1,5 @@
#include "guile-test.h"
int main(int argc, char ** argv) {
run_scm(argc, argv);
}

18402
src/bindings.rs Normal file

File diff suppressed because it is too large Load Diff

35
src/main.rs Normal file
View File

@ -0,0 +1,35 @@
#![allow(non_camel_case_types)]
#![allow(non_upper_case_globals)]
#![allow(non_snake_case)]
use std::{borrow::Borrow, ops::Deref, os};
use os::raw::{c_int, c_char, c_void};
use std::ffi::CStr;
include!("./bindings.rs");
#[no_mangle]
unsafe extern "C" fn hello_from_rust() -> SCM {
println!("Hello from Rust!");
scm_from_int8(0)
}
fn main() {
let mut args = std::env::args().map(|mut arg| arg.as_mut_ptr() as *mut c_char ).collect::<Vec<*mut c_char>>();
let argc = args.len() as c_int;
let c_args: *mut *mut c_char = args.as_mut_ptr();
unsafe {
let hello: *mut c_void = hello_from_rust as *mut c_void;
let fn_name_cstr: &CStr = CStr::from_bytes_with_nul(b"hello_from_rust\0").unwrap();
let fn_name: *const c_char = fn_name_cstr.as_ptr();
println!("name = {}", fn_name.);
scm_c_define_gsubr(fn_name, 0 as c_int, 0 as c_int, 0 as c_int, hello);
println!("Created SCM function");
run_scm(argc, c_args);
};
}

2
wrapper.h Normal file
View File

@ -0,0 +1,2 @@
#include <libguile.h>
#include "guile-test.h"