Skip to content
3 changes: 2 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -569,6 +569,7 @@ set(ZIG_STAGE2_SOURCES
"${CMAKE_SOURCE_DIR}/src/clang_options_data.zig"
"${CMAKE_SOURCE_DIR}/src/codegen.zig"
"${CMAKE_SOURCE_DIR}/src/codegen/c.zig"
"${CMAKE_SOURCE_DIR}/src/codegen/c/type.zig"
"${CMAKE_SOURCE_DIR}/src/codegen/llvm.zig"
"${CMAKE_SOURCE_DIR}/src/codegen/llvm/bindings.zig"
"${CMAKE_SOURCE_DIR}/src/glibc.zig"
Expand Down Expand Up @@ -782,7 +783,7 @@ set_target_properties(zig2 PROPERTIES
COMPILE_FLAGS ${ZIG2_COMPILE_FLAGS}
LINK_FLAGS ${ZIG2_LINK_FLAGS}
)
target_include_directories(zig2 PUBLIC "${CMAKE_SOURCE_DIR}/lib")
target_include_directories(zig2 PUBLIC "${CMAKE_SOURCE_DIR}/stage1")
target_link_libraries(zig2 LINK_PUBLIC zigcpp)

if(MSVC)
Expand Down
31 changes: 31 additions & 0 deletions build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -506,8 +506,39 @@ fn addWasiUpdateStep(b: *std.Build, version: [:0]const u8) !void {
run_opt.addArg("-o");
run_opt.addFileSourceArg(.{ .path = "stage1/zig1.wasm" });

const CopyFileStep = struct {
const Step = std.Build.Step;
const FileSource = std.Build.FileSource;
const CopyFileStep = @This();

step: Step,
builder: *std.Build,
source: FileSource,
dest_rel_path: []const u8,

pub fn init(builder: *std.Build, source: FileSource, dest_rel_path: []const u8) CopyFileStep {
return CopyFileStep{
.builder = builder,
.step = Step.init(.custom, builder.fmt("install {s} to {s}", .{ source.getDisplayName(), dest_rel_path }), builder.allocator, make),
.source = source.dupe(builder),
.dest_rel_path = builder.dupePath(dest_rel_path),
};
}

fn make(step: *Step) !void {
const self = @fieldParentPtr(CopyFileStep, "step", step);
const full_src_path = self.source.getPath(self.builder);
const full_dest_path = self.builder.pathFromRoot(self.dest_rel_path);
try self.builder.updateFile(full_src_path, full_dest_path);
}
};

const copy_zig_h = try b.allocator.create(CopyFileStep);
copy_zig_h.* = CopyFileStep.init(b, .{ .path = "lib/zig.h" }, "stage1/zig.h");

const update_zig1_step = b.step("update-zig1", "Update stage1/zig1.wasm");
update_zig1_step.dependOn(&run_opt.step);
update_zig1_step.dependOn(&copy_zig_h.step);
}

fn addCompilerStep(
Expand Down
4 changes: 2 additions & 2 deletions lib/std/hash_map.zig
Original file line number Diff line number Diff line change
Expand Up @@ -508,7 +508,7 @@ pub fn HashMap(
/// If a new entry needs to be stored, this function asserts there
/// is enough capacity to store it.
pub fn getOrPutAssumeCapacityAdapted(self: *Self, key: anytype, ctx: anytype) GetOrPutResult {
return self.unmanaged.getOrPutAssumeCapacityAdapted(self.allocator, key, ctx);
return self.unmanaged.getOrPutAssumeCapacityAdapted(key, ctx);
}

pub fn getOrPutValue(self: *Self, key: K, value: V) Allocator.Error!Entry {
Expand Down Expand Up @@ -2130,7 +2130,7 @@ test "std.hash_map getOrPutAdapted" {
try testing.expectEqual(map.count(), keys.len);

inline for (keys, 0..) |key_str, i| {
const result = try map.getOrPutAdapted(key_str, AdaptedContext{});
const result = map.getOrPutAssumeCapacityAdapted(key_str, AdaptedContext{});
try testing.expect(result.found_existing);
try testing.expectEqual(real_keys[i], result.key_ptr.*);
try testing.expectEqual(@as(u64, i) * 2, result.value_ptr.*);
Expand Down
12 changes: 3 additions & 9 deletions lib/std/multi_array_list.zig
Original file line number Diff line number Diff line change
Expand Up @@ -433,15 +433,9 @@ pub fn MultiArrayList(comptime S: type) type {
}

fn capacityInBytes(capacity: usize) usize {
if (builtin.zig_backend == .stage2_c) {
var bytes: usize = 0;
for (sizes.bytes) |size| bytes += size * capacity;
return bytes;
} else {
const sizes_vector: @Vector(sizes.bytes.len, usize) = sizes.bytes;
const capacity_vector = @splat(sizes.bytes.len, capacity);
return @reduce(.Add, capacity_vector * sizes_vector);
}
comptime var elem_bytes: usize = 0;
inline for (sizes.bytes) |size| elem_bytes += size;
return elem_bytes * capacity;
}

fn allocatedBytes(self: Self) []align(@alignOf(S)) u8 {
Expand Down
Loading