@@ -284,7 +284,7 @@ pub const Builder = struct {
284
284
return & top_level_step .step ;
285
285
}
286
286
}
287
- %% io .stderr .printf ("Cannot run step '{}' because it does not exist. " , name );
287
+ %% io .stderr .printf ("Cannot run step '{}' because it does not exist\n " , name );
288
288
return error .InvalidStepName ;
289
289
}
290
290
@@ -529,6 +529,13 @@ pub const Builder = struct {
529
529
530
530
}
531
531
532
+ pub fn makePath (self : & Builder , path : []const u8 ) - > % void {
533
+ os .makePath (self .allocator , path ) %% | err | {
534
+ %% io .stderr .printf ("Unable to create path {}: {}\n " , path , @errorName (err ));
535
+ return err ;
536
+ };
537
+ }
538
+
532
539
pub fn installCLibrary (self : & Builder , lib : & CLibrary ) - > & InstallCLibraryStep {
533
540
const install_step = %% self .allocator .create (InstallCLibraryStep );
534
541
* install_step = InstallCLibraryStep .init (self , lib );
@@ -1090,11 +1097,13 @@ pub const CLibrary = struct {
1090
1097
%% cc_args .append ("-c" );
1091
1098
%% cc_args .append (source_file );
1092
1099
1093
- // TODO don't dump the .o file in the same place as the source file
1094
- const o_file = builder .fmt ("{}{}" , source_file , self .target .oFileExt ());
1095
- defer builder .allocator .free (o_file );
1100
+ const rel_src_path = %% os .path .relative (builder .allocator , builder .build_root , source_file );
1101
+ const cache_o_src = %% os .path .join (builder .allocator , builder .cache_root , rel_src_path );
1102
+ const cache_o_dir = os .path .dirname (cache_o_src );
1103
+ % return builder .makePath (cache_o_dir );
1104
+ const cache_o_file = builder .fmt ("{}{}" , cache_o_src , self .target .oFileExt ());
1096
1105
%% cc_args .append ("-o" );
1097
- %% cc_args .append (o_file );
1106
+ %% cc_args .append (cache_o_file );
1098
1107
1099
1108
for (self .cflags .toSliceConst ()) | cflag | {
1100
1109
%% cc_args .append (cflag );
@@ -1107,7 +1116,7 @@ pub const CLibrary = struct {
1107
1116
1108
1117
% return builder .spawnChild (cc , cc_args .toSliceConst ());
1109
1118
1110
- %% self .object_files .append (o_file );
1119
+ %% self .object_files .append (cache_o_file );
1111
1120
}
1112
1121
1113
1122
if (self .static ) {
@@ -1248,10 +1257,13 @@ pub const CExecutable = struct {
1248
1257
%% cc_args .append (builder .pathFromRoot (source_file ));
1249
1258
1250
1259
// TODO don't dump the .o file in the same place as the source file
1251
- const o_file = builder .fmt ("{}{}" , source_file , self .target .oFileExt ());
1252
- defer builder .allocator .free (o_file );
1260
+ const rel_src_path = %% os .path .relative (builder .allocator , builder .build_root , source_file );
1261
+ const cache_o_src = %% os .path .join (builder .allocator , builder .cache_root , rel_src_path );
1262
+ const cache_o_dir = os .path .dirname (cache_o_src );
1263
+ % return builder .makePath (cache_o_dir );
1264
+ const cache_o_file = builder .fmt ("{}{}" , cache_o_src , self .target .oFileExt ());
1253
1265
%% cc_args .append ("-o" );
1254
- %% cc_args .append (o_file );
1266
+ %% cc_args .append (cache_o_file );
1255
1267
1256
1268
for (self .cflags .toSliceConst ()) | cflag | {
1257
1269
%% cc_args .append (cflag );
@@ -1264,7 +1276,7 @@ pub const CExecutable = struct {
1264
1276
1265
1277
% return builder .spawnChild (cc , cc_args .toSliceConst ());
1266
1278
1267
- %% self .object_files .append (o_file );
1279
+ %% self .object_files .append (cache_o_file );
1268
1280
}
1269
1281
1270
1282
%% cc_args .resize (0 );
0 commit comments