on master help sign in
Build RTS as shared library

The C RTS is now built as a shared library, so that the functions in the Idris standard library that use parts of it will work in :x and in type providers.

commitf8fcd921221d09946e20879c1c6a92645670e666 authorDavid Christiansen <david@davidchristiansen.dk> dateMon 1 Apr 2013, 18:47 (14 years ago) parent9af2d93
4 files changed+25−4
.gitignore+4 config.mk+3 rts/Makefile+8−4 src/Idris/REPL.hs+10
.gitignore+4
@@ -3,6 +3,9 @@ cabal-dev/
33*.ibc
44*.o
55*.a
6+*.so
7+*.dll
8+*.dylib
69*.swp
710*~
811custom.mk
@@ -11,3 +14,4 @@ test/test???/output
1114test/reg???/output
1215test/test???/*.exe
1316test/reg???/*.exe
17+
config.mk+3
@@ -1,5 +1,8 @@
11GMP_INCLUDE_DIR :=
22CC :=gcc
3+SHLIB_SUFFIX :=.so
4+# Mac OS X: SHLIB_SUFFIX :=.dylib
5+# Windows: SHLIB_SUFFIX :=.DLL
36CABAL :=cabal
47CABALFLAGS :=
58## Enable Java RTS:
rts/Makefile+8−4
@@ -2,26 +2,30 @@ include ../config.mk
22
33OBJS = idris_rts.o idris_heap.o idris_gc.o idris_gmp.o idris_stdfgn.o idris_bitstring.o idris_opts.o idris_stats.o
44HDRS = idris_rts.h idris_heap.h idris_gc.h idris_gmp.h idris_stdfgn.h idris_bitstring.h idris_opts.h idris_stats.h
5−CFLAGS = -O2 -Wall
5+CFLAGS = -O2 -Wall -fPIC
66
77ifneq ($(GMP_INCLUDE_DIR),)
88 CFLAGS += -isystem $(GMP_INCLUDE_DIR)
99endif
1010
1111LIBTARGET = libidris_rts.a
12+DYLIBTARGET = libidris_rts$(SHLIB_SUFFIX)
1213
13−check : $(LIBTARGET)
14+check : $(LIBTARGET) $(DYLIBTARGET)
1415
1516$(LIBTARGET) : $(OBJS)
1617 ar r $(LIBTARGET) $(OBJS)
1718 ranlib $(LIBTARGET)
1819
20+$(DYLIBTARGET) : $(OBJS)
21+ $(CC) $(CFLAGS) -shared -o $(DYLIBTARGET) $(OBJS)
22+
1923install : .PHONY
2024 mkdir -p $(TARGET)
21− install $(LIBTARGET) $(HDRS) $(TARGET)
25+ install $(LIBTARGET) $(DYLIBTARGET) $(HDRS) $(TARGET)
2226
2327clean : .PHONY
24− rm -f $(OBJS) $(LIBTARGET)
28+ rm -f $(OBJS) $(LIBTARGET) $(DYLIBTARGET)
2529
2630idris_rts.o: idris_rts.h
2731
src/Idris/REPL.hs+10
@@ -552,6 +552,16 @@ idrisMain opts =
552552 [] -> setIBCSubDir ""
553553 (d:_) -> setIBCSubDir d
554554 setImportDirs importdirs
555+ -- attempt to load the RTS as a shared lib in the interpreter
556+ idrisCatch (do rtslib <- lift (getDataFileName $ "rts" </> "libidris_rts")
557+ handle <- lift (tryLoadLib rtslib)
558+ case handle of
559+ Nothing -> return ()
560+ Just x -> do i <- getIState
561+ let libs = idris_dynamic_libs i
562+ putIState $ i { idris_dynamic_libs = x:libs })
563+ (\e -> iputStrLn (show e))
564+
555565 addPkgDir "base"
556566 mapM_ addPkgDir pkgdirs
557567 elabPrims