| ... | @@ -18,7 +18,9 @@ pub fn build(b: *Build) void { | ... | @@ -18,7 +18,9 @@ pub fn build(b: *Build) void { |
| 18 | }; | 18 | }; |
| 19 | | 19 | |
| 20 | // Exercise linker with self-hosted backend (no LLVM) | 20 | // Exercise linker with self-hosted backend (no LLVM) |
| 21 | // elf_step.dependOn(testLinkingZig(b, .{ .use_llvm = false })); | 21 | elf_step.dependOn(testLinkingZig(b, .{ .use_llvm = false })); |
| | 22 | elf_step.dependOn(testImportingDataDynamic(b, .{ .use_llvm = false, .target = glibc_target })); |
| | 23 | elf_step.dependOn(testImportingDataStatic(b, .{ .use_llvm = false, .target = musl_target })); |
| 22 | | 24 | |
| 23 | // Exercise linker with LLVM backend | 25 | // Exercise linker with LLVM backend |
| 24 | // musl tests | 26 | // musl tests |
| ... | @@ -1223,6 +1225,70 @@ fn testImageBase(b: *Build, opts: Options) *Step { | ... | @@ -1223,6 +1225,70 @@ fn testImageBase(b: *Build, opts: Options) *Step { |
| 1223 | return test_step; | 1225 | return test_step; |
| 1224 | } | 1226 | } |
| 1225 | | 1227 | |
| | 1228 | fn testImportingDataDynamic(b: *Build, opts: Options) *Step { |
| | 1229 | const test_step = addTestStep(b, "importing-data-dynamic", opts); |
| | 1230 | |
| | 1231 | const dso = addSharedLibrary(b, "a", .{ |
| | 1232 | .target = opts.target, |
| | 1233 | .optimize = opts.optimize, |
| | 1234 | .use_llvm = true, |
| | 1235 | }); |
| | 1236 | addCSourceBytes(dso, "int foo = 42;", &.{}); |
| | 1237 | |
| | 1238 | const main = addExecutable(b, "main", opts); |
| | 1239 | addZigSourceBytes(main, |
| | 1240 | \\extern var foo: i32; |
| | 1241 | \\pub fn main() void { |
| | 1242 | \\ @import("std").debug.print("{d}\n", .{foo}); |
| | 1243 | \\} |
| | 1244 | ); |
| | 1245 | main.pie = true; |
| | 1246 | main.strip = true; // TODO temp hack |
| | 1247 | main.linkLibrary(dso); |
| | 1248 | main.linkLibC(); |
| | 1249 | |
| | 1250 | const run = addRunArtifact(main); |
| | 1251 | run.expectStdErrEqual("42\n"); |
| | 1252 | test_step.dependOn(&run.step); |
| | 1253 | |
| | 1254 | return test_step; |
| | 1255 | } |
| | 1256 | |
| | 1257 | fn testImportingDataStatic(b: *Build, opts: Options) *Step { |
| | 1258 | const test_step = addTestStep(b, "importing-data-static", opts); |
| | 1259 | |
| | 1260 | const obj = addObject(b, "a", .{ |
| | 1261 | .target = opts.target, |
| | 1262 | .optimize = opts.optimize, |
| | 1263 | .use_llvm = true, |
| | 1264 | }); |
| | 1265 | addCSourceBytes(obj, "int foo = 42;", &.{}); |
| | 1266 | |
| | 1267 | const lib = addStaticLibrary(b, "a", .{ |
| | 1268 | .target = opts.target, |
| | 1269 | .optimize = opts.optimize, |
| | 1270 | .use_llvm = true, |
| | 1271 | }); |
| | 1272 | lib.addObject(obj); |
| | 1273 | |
| | 1274 | const main = addExecutable(b, "main", opts); |
| | 1275 | addZigSourceBytes(main, |
| | 1276 | \\extern var foo: i32; |
| | 1277 | \\pub fn main() void { |
| | 1278 | \\ @import("std").debug.print("{d}\n", .{foo}); |
| | 1279 | \\} |
| | 1280 | ); |
| | 1281 | main.strip = true; // TODO temp hack |
| | 1282 | main.linkLibrary(lib); |
| | 1283 | main.linkLibC(); |
| | 1284 | |
| | 1285 | const run = addRunArtifact(main); |
| | 1286 | run.expectStdErrEqual("42\n"); |
| | 1287 | test_step.dependOn(&run.step); |
| | 1288 | |
| | 1289 | return test_step; |
| | 1290 | } |
| | 1291 | |
| 1226 | fn testInitArrayOrder(b: *Build, opts: Options) *Step { | 1292 | fn testInitArrayOrder(b: *Build, opts: Options) *Step { |
| 1227 | const test_step = addTestStep(b, "init-array-order", opts); | 1293 | const test_step = addTestStep(b, "init-array-order", opts); |
| 1228 | | 1294 | |