summaryrefslogtreecommitdiff
path: root/testsuite/tests/lib-dynlink-csharp/main.ml
blob: d6ac12b91e6762bf276db6458dac12b131964f11 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
(* TEST
 include dynlink;
 readonly_files = "entry.c main.cs plugin.ml";
 csharp-compiler;
 set csharp_cmd = "${csc} ${csc_flags} /out:main.exe main.cs";
 shared-libraries;
 {
   setup-ocamlc.byte-build-env;
   module = "plugin.ml";
   ocamlc.byte;
   module = "";
   flags = "-output-obj";
   program = "main.dll";
   all_modules = "dynlink.cma main.ml entry.c";
   ocamlc.byte;
   script = "${csharp_cmd}";
   script;
   program = "./main.exe";
   run;
   reference = "${test_source_directory}/main.bytecode.reference";
   check-program-output;
 }{
   compiler_directory_suffix = "-dll";
   setup-ocamlc.byte-build-env;
   module = "plugin.ml";
   ocamlc.byte;
   module = "";
   flags = "-output-obj";
   program = "main_obj.${objext}";
   all_modules = "dynlink.cma entry.c main.ml";
   ocamlc.byte;
   script = "${mkdll} -maindll -o main.dll main_obj.${objext} entry.${objext} \
     ${ocamlsrcdir}/runtime/libcamlrun.${libext} ${bytecc_libs}";
   script;
   script = "${csharp_cmd}";
   script;
   program = "./main.exe";
   run;
   reference = "${test_source_directory}/main.bytecode.reference";
   check-program-output;
 }{
   setup-ocamlopt.byte-build-env;
   program = "plugin.cmxs";
   flags = "-shared";
   all_modules = "plugin.ml";
   ocamlopt.byte;
   flags = "-output-obj";
   program = "main.dll";
   all_modules = "dynlink.cmxa entry.c main.ml";
   ocamlopt.byte;
   script = "${csharp_cmd}";
   script;
   program = "./main.exe";
   run;
   reference = "${test_source_directory}/main.native.reference";
   check-program-output;
 }{
   compiler_directory_suffix = "-dll";
   setup-ocamlopt.byte-build-env;
   program = "plugin.cmxs";
   flags = "-shared";
   all_modules = "plugin.ml";
   ocamlopt.byte;
   flags = "-output-obj";
   program = "main_obj.${objext}";
   all_modules = "dynlink.cmxa entry.c main.ml";
   ocamlopt.byte;
   script = "${mkdll} -maindll -o main.dll main_obj.${objext} entry.${objext} \
     ${ocamlsrcdir}/runtime/libasmrun.${libext} ${nativecc_libs}";
   script;
   script = "${csharp_cmd}";
   script;
   program = "./main.exe";
   run;
   reference = "${test_source_directory}/main.native.reference";
   check-program-output;
 }
*)

let load s =
  Printf.printf "Loading %s\n%!" s;
  try
    Dynlink.loadfile s
  with Dynlink.Error e ->
    print_endline (Dynlink.error_message e)

(* Callback must be linked to load Unix dynamically *)
let _ = Callback.register
let _ = Stdlib.Bigarray.float32

let () =
  ignore (Hashtbl.hash 42.0);
  print_endline "Main is running.";
  Dynlink.allow_unsafe_modules true;
  let plugin_name = Dynlink.adapt_filename "plugin.cmo" in
  load plugin_name;
  print_endline "OK."