Skip to content

Commit f8eb94c

Browse files
committed
Fix some platform stuff
1 parent fe93921 commit f8eb94c

File tree

1 file changed

+23
-5
lines changed

1 file changed

+23
-5
lines changed

src/cli/main.zig

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -579,6 +579,9 @@ fn rocRun(allocs: *Allocators, args: cli_args.RunArgs) !void {
579579
const trace = tracy.trace(@src());
580580
defer trace.end();
581581

582+
// Import needed modules
583+
const target_mod = @import("target.zig");
584+
582585
// Initialize cache - used to store our shim, and linked interpreter executables in cache
583586
const cache_config = CacheConfig{
584587
.enabled = !args.no_cache,
@@ -735,17 +738,32 @@ fn rocRun(allocs: *Allocators, args: cli_args.RunArgs) !void {
735738
return err;
736739
};
737740

738-
// Platforms provide their own CRT files and libraries in a targets/ directory
739-
const platform_files_pre: []const []const u8 = &.{};
740-
const platform_files_post: []const []const u8 = &.{};
741+
// Get platform directory and CRT files
742+
const platform_dir = std.fs.path.dirname(platform_paths.host_lib_path) orelse {
743+
std.log.err("Invalid platform host library path", .{});
744+
return error.InvalidPlatform;
745+
};
746+
747+
const crt_files = try target_mod.getVendoredCRTFiles(allocs.arena, shim_target, platform_dir);
748+
749+
// Setup platform files based on CRT files
750+
var platform_files_pre = try std.array_list.Managed([]const u8).initCapacity(allocs.arena, 16);
751+
var platform_files_post = try std.array_list.Managed([]const u8).initCapacity(allocs.arena, 16);
752+
753+
// Add CRT files in correct order
754+
if (crt_files.crt1_o) |crt1| try platform_files_pre.append(crt1);
755+
if (crt_files.crti_o) |crti| try platform_files_pre.append(crti);
756+
if (crt_files.crtn_o) |crtn| try platform_files_post.append(crtn);
757+
if (crt_files.libc_a) |libc| try platform_files_post.append(libc);
758+
741759
const target_abi: ?linker.TargetAbi = null;
742760

743761
const link_config = linker.LinkConfig{
744762
.target_abi = target_abi,
745763
.output_path = exe_path,
746764
.object_files = object_files.items,
747-
.platform_files_pre = platform_files_pre,
748-
.platform_files_post = platform_files_post,
765+
.platform_files_pre = platform_files_pre.items,
766+
.platform_files_post = platform_files_post.items,
749767
.extra_args = extra_args.items,
750768
.can_exit_early = false,
751769
.disable_output = false,

0 commit comments

Comments
 (0)