Debian Codegraph @

test/blackbox-tests/test-cases/foreign-stubs/fs-mode-dependent/fsmd-mixed-errors.t/run.t

raw
1 $ cat >stubs_exe.ml <<EOF
2 > external stub_byte_or_native : unit -> int = "caml_b_or_n"
3 > let () =
4 > Printf.printf "Byte (0) or native (1) ? %i\n" (stub_byte_or_native ())
5 > EOF
6
7
8 We can have one stub that is mode-dependent:
9 $ cat >dune <<EOF
10 > (executable
11 > (modes native byte_complete)
12 > (modules stubs_exe)
13 > (name stubs_exe)
14 > (foreign_stubs
15 > (mode native)
16 > (language c)
17 > (flags :standard -DNATIVE_CODE)
18 > (names c_stubs))
19 > (foreign_stubs
20 > (mode byte)
21 > (language c)
22 > (flags :standard)
23 > (names c_stubs)))
24 > EOF
25
26 $ dune exec ./stubs_exe.exe
27 Byte (0) or native (1) ? 1
28
29 $ dune exec ./stubs_exe.bc.exe
30 Byte (0) or native (1) ? 0
31
32 If one of the two is not specified, it will be used for both byte and native mode
33 and then a duplicated symbol error will happen
34 $ cat >dune <<EOF
35 > (executable
36 > (modes native byte_complete)
37 > (modules stubs_exe)
38 > (name stubs_exe)
39 > (foreign_stubs
40 > (language c)
41 > (flags :standard -DNATIVE_CODE)
42 > (names c_stubs))
43 > (foreign_stubs
44 > (mode byte)
45 > (language c)
46 > (flags :standard)
47 > (names c_stubs)))
48 > EOF
49
50 $ dune exec ./stubs_exe.exe
51 Byte (0) or native (1) ? 1
52
53 FIXME: we could detect this earlier and display a better error message
54 $ dune exec ./stubs_exe.bc.exe 2>&1 | grep -q 'duplicate symbol\|multiple definition'
55 [1]
56
57 But two foreign stubs for the same file and mode is an error:
58 $ cat >dune <<EOF
59 > (executable
60 > (modes native byte_complete)
61 > (modules stubs_exe)
62 > (name stubs_exe)
63 > (foreign_stubs
64 > (mode byte)
65 > (language c)
66 > (flags :standard -DNATIVE_CODE)
67 > (names c_stubs))
68 > (foreign_stubs
69 > (mode byte)
70 > (language c)
71 > (flags :standard)
72 > (names c_stubs)))
73 > EOF
74
75 $ dune exec ./stubs_exe.exe
76 File "dune", line 9, characters 9-16:
77 9 | (names c_stubs))
78 ^^^^^^^
79 Error: Multiple sources map to the same object name "c_stubs" for mode byte:
80 - c_stubs.c
81 - c_stubs.c
82 This is not allowed; please rename them or remove "c_stubs" from object
83 names.
84 Hint: You may be missing a mode field that would restrict this stub to some
85 specific mode.
86 Hint: You can also avoid the name clash by placing the objects into different
87 foreign archives and building them in different directories. Foreign archives
88 can be defined using the (foreign_library ...) stanza.
89 [1]
90
91 $ dune exec ./stubs_exe.bc.exe
92 File "dune", line 9, characters 9-16:
93 9 | (names c_stubs))
94 ^^^^^^^
95 Error: Multiple sources map to the same object name "c_stubs" for mode byte:
96 - c_stubs.c
97 - c_stubs.c
98 This is not allowed; please rename them or remove "c_stubs" from object
99 names.
100 Hint: You may be missing a mode field that would restrict this stub to some
101 specific mode.
102 Hint: You can also avoid the name clash by placing the objects into different
103 foreign archives and building them in different directories. Foreign archives
104 can be defined using the (foreign_library ...) stanza.
105 [1]
106
107 We can have some mode-dependent stubs and some non-dependent other stubs
108 $ cat >dune <<EOF
109 > (executable
110 > (modes native byte_complete)
111 > (modules stubs_exe)
112 > (name stubs_exe)
113 > (foreign_stubs
114 > (language c)
115 > (flags :standard -DNATIVE_CODE)
116 > (names c_stubs2))
117 > (foreign_stubs
118 > (mode native)
119 > (language c)
120 > (flags :standard -DNATIVE_CODE)
121 > (names c_stubs))
122 > (foreign_stubs
123 > (mode byte)
124 > (language c)
125 > (flags :standard)
126 > (names c_stubs)))
127 > EOF
128
129 $ cat >>stubs_exe.ml <<EOF
130 > external stub_byte_or_native2 : unit -> int = "caml_b_or_n2"
131 > let () =
132 > Printf.printf "Byte (0) or native (1) 2 ? %i\n" (stub_byte_or_native2 ())
133 > EOF
134
135 $ dune exec ./stubs_exe.exe
136 Byte (0) or native (1) ? 1
137 Byte (0) or native (1) 2 ? 42
138
139 $ dune exec ./stubs_exe.bc.exe
140 Byte (0) or native (1) ? 0
141 Byte (0) or native (1) 2 ? 42