Commits

ariovistus committed 2ddc0f2

hellooo dmd 2.063

can it truly be? shared libs with unittests and module constructors?
goodbye dmd 2.062-. You made my life miserable. I won't miss you. Until
I start dealing with these deprecation messages.

Comments (0)

Files changed (7)

build_manifest.py

             return True
         if pathsubs == ['infrastructure','d','python_dll_def.def_template']:
             return True
+        if pathsubs == ['infrastructure','d','so_ctor.c']:
+            return True
         if pathsubs == ['infrastructure','python','python.d']:
             return False
         if ext.lower() == '.d':
     def _initialize(self):
         self.winonly = True
         # _compileOpts
-        self._exeCompileOpts = self._compileOpts = ['-c']
+        self._exeCompileOpts = ['-c']
+        self._compileOpts = ['-c']
+        if not _isPlatWin: self._compileOpts.append('-fPIC')
         # _outputOpts
         self._outputOpts = ['-of%s']
         # _linkOpts
             self._exeLinkOpts.append(posix_static_python_lib())
         else:
             self._exeLinkOpts = []
-        self._linkOpts = []
+        if _isPlatWin:
+            self._linkOpts = []
+        else:
+            self._linkOpts = ['-shared','-defaultlib=phobos2so']
         # _includeOpts
         self._includeOpts = ['-I%s']
         # _versionOpt
             return self.library_filename(lib)
         else:
             return '-L-l' + lib
+    def compile(self, *args, **kwargs):
+        if not _isPlatWin:
+            output_dir = kwargs.get('output_dir', '')
+            if not os.path.exists(output_dir):
+                os.makedirs(os.path.join(output_dir,'infra'))
+            src = os.path.join(_infraDir, 'd', 'so_ctor.c')
+            dsto = os.path.join(output_dir, 'infra', 'so_ctor.o')
+            spawn0(self,['gcc','-c', src, '-fPIC','-o',dsto])
+            self._dmd_so_ctor = dsto
+        return DCompiler.compile(self, *args, **kwargs)
+    def link (self, *args, **kwargs):
+        if not _isPlatWin: 
+            args[1].append(self._dmd_so_ctor)
+        return DCompiler.link(self, *args, **kwargs)
 
 class GDCDCompiler(DCompiler):
     compiler_type = 'gdc'

examples/misc/cffi/test1.py

 mystr = (doh.str_test(DString("world peace"),DString("world peace")))
 print mystr.length
 print mystr.ptr
+import pdb
+pdb.set_trace()
 
 

examples/misc/dmd_sharedlibs/makefile

 	rm -f *.so
 	rm -f *.x
 
-lib%.so: %.d boilerplate.d so_ctor.o 
-	$(DMD) -unittest -fPIC -defaultlib=phobos2so -shared $^ -of$@
+lib%.so: %.d boilerplate.d so_ctor.o
+	#$(DMD) -unittest -fPIC -defaultlib=phobos2so -shared $^ -of$@
+	$(DMD) -c -unittest -fPIC $< boilerplate.d -oftemp.o
+	$(DMD) -shared -defaultlib=phobos2so temp.o so_ctor.o -of$@
 so_ctor.o: so_ctor.c
 	$(GCC) -c -fPIC so_ctor.c -o so_ctor.o
 

examples/misc/dmd_sharedlibs/so_ctor.c

+#include <stdio.h>
 void my_init();
 void my_fini();
 
 __attribute__((__constructor__)) void actual_init() {
+    printf("initing\n");
     my_init();
 }
+__attribute__((__destructor__)) void actual_fini() {
+    printf("dniting\n");
+    my_fini();
+}
 

examples/misc/dmd_sharedlibs/test1.d

 static this() {
     writeln("yawn. stretch.");
 }
+static ~this() {
+    writeln("yawn. zzzzz");
+}
 
 unittest {
     writeln("lets test this donut.");

infrastructure/d/python_so_linux_boilerplate.d

     void rt_init();
     void rt_term();
 
-    void _init() {
+    void hacky_init() {
         rt_init();
     }
 
-    void _fini() {
+    void hacky_fini() {
         if(!_d_isHalting){
             rt_term();
         }