Repository navigation
Expand file tree
/
Copy pathmcpp_probes.sh
More file actions
executable file
·214 lines (188 loc) · 5.59 KB
/
Copy pathmcpp_probes.sh
File metadata and controls
executable file
·214 lines (188 loc) · 5.59 KB
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
#!/usr/bin/env bash
# TEMPORARY PROBE (do not merge): mcpp built from main, on the cases the design
# for #770 / #771 / #769 relies on. Prints; asserts nothing.
set -u
M="${MCPP_BUILT:?}"
W="$RUNNER_TEMP/mcpp-probes"; mkdir -p "$W"
run() { echo "\$ $*"; "$@" 2>&1; echo "rc=$?"; }
section() { echo; echo "### $1"; }
edges() { # the link edges of the generated build.ninja, with their link flags
local n; n=$(find target -name build.ninja | head -1)
[ -n "$n" ] || { echo "(no build.ninja)"; return; }
python - "$n" <<'PY'
import re, sys
glob, edges, cur = {}, {}, None
for line in open(sys.argv[1], encoding="utf-8", errors="replace"):
line = line.rstrip("\n")
if line.startswith("build "):
cur = line.split(" : ")[0][6:].strip()
rule = line.split(" : ", 1)[1].split()[0] if " : " in line else "?"
edges[cur] = {"_rule": rule}
continue
if line.startswith(" ") and cur:
k, _, v = line.strip().partition(" = "); edges[cur][k] = v; continue
cur = None
m = re.match(r"^(\w+)\s*=\s*(.*)$", line)
if m: glob[m.group(1)] = m.group(2)
for e, v in edges.items():
if v["_rule"] not in ("cxx_shared", "cxx_link"): continue
src = "group" if "ldflags" in v else "plan-global"
ld = v.get("ldflags", glob.get("ldflags", "")) + " | unit: " + v.get("unit_ldflags", "")
print(f"{e} [{v['_rule']}, {src}]\n {ld}")
PY
}
"$M" --version
MODE="${1:-all}"
if [ "$MODE" = msvc ] || [ "$MODE" = all ]; then
# ---------------------------------------------------------------- #771
section "771 workspace member's shared library and its build.mcpp link_lib (msvc@system)"
mkdir -p "$W/ws771/player/src" "$W/ws771/other/src"; cd "$W/ws771"
cat > mcpp.toml <<'EOF'
[workspace]
members = ["player", "other"]
[toolchain]
windows = "msvc@system"
EOF
cat > player/mcpp.toml <<'EOF'
[package]
name = "player"
version = "0.1.0"
[targets.player_dll]
kind = "shared"
[targets.player]
kind = "bin"
main = "src/main.cpp"
EOF
cat > player/build.mcpp <<'EOF'
import mcpp;
int main() { mcpp::link_lib("ws2_32"); return 0; }
EOF
cat > player/src/net.cpp <<'EOF'
#include <winsock2.h>
int player_err() { return WSAGetLastError(); }
EOF
cat > player/src/main.cpp <<'EOF'
int player_err();
int main() { return player_err() == 0 ? 0 : 0; }
EOF
cat > other/mcpp.toml <<'EOF'
[package]
name = "other"
version = "0.1.0"
[build]
ldflags = ["/IGNORE:4099"]
[targets.other]
kind = "bin"
main = "src/main.cpp"
EOF
printf 'int main() { return 0; }\n' > other/src/main.cpp
run "$M" build
edges
section "771 the same, selecting the member (-p player)"
rm -rf target; run "$M" build -p player
edges
# ---------------------------------------------------------------- #770 F6
section "770 F6 /GL in cxxflags + default windows_auto_export on a DLL (msvc@system)"
mkdir -p "$W/gl/src"; cd "$W/gl"
cat > mcpp.toml <<'EOF'
[package]
name = "glprobe"
version = "0.1.0"
[toolchain]
windows = "msvc@system"
[build]
cxxflags = ["/GL"]
ldflags = ["/LTCG"]
[targets.glprobe]
kind = "shared"
EOF
printf 'int gl_fn(int x) { return x + 1; }\n' > src/gl.cpp
run "$M" build
section "770 F6b /GL + windows_auto_export = false + __declspec(dllexport)"
mkdir -p "$W/gl2/src"; cd "$W/gl2"
cat > mcpp.toml <<'EOF'
[package]
name = "glprobe2"
version = "0.1.0"
[toolchain]
windows = "msvc@system"
[build]
cxxflags = ["/GL"]
ldflags = ["/LTCG"]
[targets.glprobe2]
kind = "shared"
windows_auto_export = false
EOF
printf '__declspec(dllexport) int gl_fn(int x) { return x + 1; }\n' > src/gl.cpp
run "$M" build
dll=$(find target -name 'glprobe2.dll' | head -1); [ -n "$dll" ] && MSYS2_ARG_CONV_EXCL='*' run dumpbin -nologo -exports "$dll"
section "770 lto = true on cl.exe today: what the build line says"
mkdir -p "$W/lto/src"; cd "$W/lto"
cat > mcpp.toml <<'EOF'
[package]
name = "ltoprobe"
version = "0.1.0"
[toolchain]
windows = "msvc@system"
[profile.release]
lto = true
[targets.ltoprobe]
kind = "bin"
main = "src/main.cpp"
EOF
printf 'int main() { return 0; }\n' > src/main.cpp
run "$M" build --release
n=$(find target -name build.ninja | head -1); grep -n "GL\|LTCG\|flto" "$n" | head -5; echo "(grep done)"
# ---------------------------------------------------------------- #769 / D2
fi
if [ "$MODE" = llvm ] || [ "$MODE" = all ]; then
section "D2 import std only: is std.compat compiled anyway? (std cache cleared first)"
echo "WindowsSdkDir=${WindowsSdkDir:-<unset>}"
rm -rf "${MCPP_HOME:-$HOME/.mcpp}/build-cache/v1/std"
rm -rf "$W/stdonly"; mkdir -p "$W/stdonly/src"; cd "$W/stdonly"
cat > mcpp.toml <<'EOF'
[package]
name = "std-only"
version = "0.1.0"
standard = "c++23"
[toolchain]
windows = "llvm@22.1.8"
[target.x86_64-windows-msvc]
sysroot = "msvc@system"
[targets.std-only]
kind = "bin"
main = "src/main.cpp"
EOF
printf 'import std;\nint main() { std::vector<int> v{1}; return v.size() == 1 ? 0 : 1; }\n' > src/main.cpp
run "$M" build
find "${MCPP_HOME:-$HOME/.mcpp}" -path '*std.compat*' \( -name '*.pcm' -o -name '*.o' -o -name '*.obj' \) 2>/dev/null | head -5
echo "(compat artefacts listed above, if any)"
section "769 llvm + MSVC STL: import std.compat"
rm -rf "$W/compat"; mkdir -p "$W/compat/src"; cd "$W/compat"
cat > mcpp.toml <<'EOF'
[package]
name = "std-compat-canary"
version = "0.1.0"
standard = "c++23"
[toolchain]
windows = "llvm@22.1.8"
[target.x86_64-windows-msvc]
sysroot = "msvc@system"
[targets.std-compat-canary]
kind = "bin"
main = "src/main.cpp"
EOF
cat > src/main.cpp <<'EOF'
import std.compat;
int main() {
auto* memory = ::malloc(32);
if (!memory) return 1;
::free(memory);
std::vector<int> values{1, 2, 3};
::printf("compat=%zu\n", values.size());
return values.size() == 3 ? 0 : 1;
}
EOF
run "$M" build
run "$M" run
fi