Skip to content

Instantly share code, notes, and snippets.

@bvssvni
Last active August 29, 2015 13:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save bvssvni/10934894 to your computer and use it in GitHub Desktop.
Save bvssvni/10934894 to your computer and use it in GitHub Desktop.
Rust & Idris
$ rustc src/lib.rs -o idris/idrisfs.ll --crate-type=lib --emit=ir
$ cd idris
$ llc idrisfs.ll -o idrisfs.o
ld: warning: ignoring file ./idrisfs.o, file was built for unsupported file format ( 0x09 0x2E 0x73 0x65 0x63 0x74 0x69 0x6F 0x6E 0x09 0x5F 0x5F 0x54 0x45 0x58 0x54 ) which is not the architecture being linked (x86_64): ./idrisfs.o
Undefined symbols for architecture x86_64:
"_sizeof_int", referenced from:
__idris__123_APPLY0_125_ in idris5179-da576e.o
__idris_Main_46__123_getSizeInt0_125_ in idris5179-da576e.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
FAILURE: gcc -O2 -fwrapv -fno-strict-overflow -I. ./idrisfs.o -x c /var/folders/_t/g72k9vzd30b5svvyd1nxpwp40000gn/T/idris5179 -L/Users/sven/Library/Haskell/ghc-7.6.3/lib/idris-0.9.12/share/rts -lidris_rts -lgmp -lpthread -I/Users/sven/Library/Haskell/ghc-7.6.3/lib/idris-0.9.12/share/rts -I. -I/Users/sven/Library/Haskell/ghc-7.6.3/lib/idris-0.9.12/share/prelude -I/Users/sven/Library/Haskell/ghc-7.6.3/lib/idris-0.9.12/share/base -o /var/folders/_t/g72k9vzd30b5svvyd1nxpwp40000gn/T/idris5176
/bin/sh: /var/folders/_t/g72k9vzd30b5svvyd1nxpwp40000gn/T/idris5176: No such file or directory
#ifndef IDRISFS
#define IDRISFS
int sizeof_int(void);
#endif
#![crate_id = "idrisfs"]
#![deny(missing_doc)]
//! Documentation goes here.
/// Returns the number of bytes in an int.
#[no_mangle]
pub extern "C" fn sizeof_int() -> int {
std::mem::size_of::<int>() as int
}
module Main
-- %dynamic "./../target/x86_64-apple-darwin/lib/libidrisfs-ba8d5852-0.0.dylib"
%include C "idrisfs.h"
%link C "idrisfs.o"
getSizeInt : IO Int
getSizeInt = mkForeign (FFun "sizeof_int" [] FInt)
main : IO ()
main = do
x <- getSizeInt
putStrLn (show x)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment