Skip to content

Commit 56d8185

Browse files
committed
expose glibc version in builtin
1 parent 3e36cad commit 56d8185

File tree

3 files changed

+39
-3
lines changed

3 files changed

+39
-3
lines changed

src/codegen.cpp

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7918,6 +7918,14 @@ Buf *codegen_generate_builtin_source(CodeGen *g) {
79187918
//assert(EndianBig == 0);
79197919
//assert(EndianLittle == 1);
79207920
}
7921+
{
7922+
buf_appendf(contents,
7923+
"pub const Version = struct {\n"
7924+
" major: u32,\n"
7925+
" minor: u32,\n"
7926+
" patch: u32,\n"
7927+
"};\n\n");
7928+
}
79217929
{
79227930
buf_appendf(contents,
79237931
"pub const SubSystem = enum {\n"
@@ -7949,6 +7957,15 @@ Buf *codegen_generate_builtin_source(CodeGen *g) {
79497957
buf_appendf(contents, "pub const os = Os.%s;\n", cur_os);
79507958
buf_appendf(contents, "pub const arch = %s;\n", cur_arch);
79517959
buf_appendf(contents, "pub const abi = Abi.%s;\n", cur_abi);
7960+
if (g->libc_link_lib != nullptr && g->zig_target->glibc_version != nullptr) {
7961+
buf_appendf(contents,
7962+
"pub const glibc_version: ?Version = Version{.major = %d, .minor = %d, .patch = %d};\n",
7963+
g->zig_target->glibc_version->major,
7964+
g->zig_target->glibc_version->minor,
7965+
g->zig_target->glibc_version->patch);
7966+
} else {
7967+
buf_appendf(contents, "pub const glibc_version: ?Version = null;\n");
7968+
}
79527969
buf_appendf(contents, "pub const object_format = ObjectFormat.%s;\n", cur_obj_fmt);
79537970
buf_appendf(contents, "pub const mode = %s;\n", build_mode_to_str(g->build_mode));
79547971
buf_appendf(contents, "pub const link_libc = %s;\n", bool_to_str(g->libc_link_lib != nullptr));
@@ -8005,6 +8022,11 @@ static Error define_builtin_compile_vars(CodeGen *g) {
80058022
cache_int(&cache_hash, g->zig_target->vendor);
80068023
cache_int(&cache_hash, g->zig_target->os);
80078024
cache_int(&cache_hash, g->zig_target->abi);
8025+
if (g->zig_target->glibc_version != nullptr) {
8026+
cache_int(&cache_hash, g->zig_target->glibc_version->major);
8027+
cache_int(&cache_hash, g->zig_target->glibc_version->minor);
8028+
cache_int(&cache_hash, g->zig_target->glibc_version->patch);
8029+
}
80088030
cache_bool(&cache_hash, g->have_err_ret_tracing);
80098031
cache_bool(&cache_hash, g->libc_link_lib != nullptr);
80108032
cache_bool(&cache_hash, g->valgrind_support);
@@ -9465,6 +9487,11 @@ static Error check_cache(CodeGen *g, Buf *manifest_dir, Buf *digest) {
94659487
cache_int(ch, g->zig_target->vendor);
94669488
cache_int(ch, g->zig_target->os);
94679489
cache_int(ch, g->zig_target->abi);
9490+
if (g->zig_target->glibc_version != nullptr) {
9491+
cache_int(ch, g->zig_target->glibc_version->major);
9492+
cache_int(ch, g->zig_target->glibc_version->minor);
9493+
cache_int(ch, g->zig_target->glibc_version->patch);
9494+
}
94689495
cache_int(ch, detect_subsystem(g));
94699496
cache_bool(ch, g->strip_debug_symbols);
94709497
cache_bool(ch, g->is_test_build);

src/main.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1015,6 +1015,10 @@ int main(int argc, char **argv) {
10151015
CodeGen *g = codegen_create(main_pkg_path, nullptr, &target,
10161016
out_type, build_mode, override_lib_dir, override_std_dir, nullptr, nullptr);
10171017
codegen_set_strip(g, strip);
1018+
for (size_t i = 0; i < link_libs.length; i += 1) {
1019+
LinkLib *link_lib = codegen_add_link_lib(g, buf_create_from_str(link_libs.at(i)));
1020+
link_lib->provided_explicitly = true;
1021+
}
10181022
g->subsystem = subsystem;
10191023
g->valgrind_support = valgrind_support;
10201024
g->want_pic = want_pic;

std/build.zig

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1011,7 +1011,8 @@ pub const LibExeObjStep = struct {
10111011
builder: *Builder,
10121012
name: []const u8,
10131013
target: Target,
1014-
linker_script: ?[]const u8,
1014+
linker_script: ?[]const u8 = null,
1015+
version_script: ?[]const u8 = null,
10151016
out_filename: []const u8,
10161017
is_dynamic: bool,
10171018
version: Version,
@@ -1118,7 +1119,6 @@ pub const LibExeObjStep = struct {
11181119
.root_src = root_src,
11191120
.name = name,
11201121
.target = Target.Native,
1121-
.linker_script = null,
11221122
.frameworks = BufSet.init(builder.allocator),
11231123
.step = Step.init(name, builder.allocator, make),
11241124
.version = ver,
@@ -1596,7 +1596,12 @@ pub const LibExeObjStep = struct {
15961596

15971597
if (self.linker_script) |linker_script| {
15981598
zig_args.append("--linker-script") catch unreachable;
1599-
zig_args.append(linker_script) catch unreachable;
1599+
zig_args.append(builder.pathFromRoot(linker_script)) catch unreachable;
1600+
}
1601+
1602+
if (self.version_script) |version_script| {
1603+
try zig_args.append("--version-script");
1604+
try zig_args.append(builder.pathFromRoot(version_script));
16001605
}
16011606

16021607
if (self.exec_cmd_args) |exec_cmd_args| {

0 commit comments

Comments
 (0)