mirror of
https://github.com/ziglang/zig.git
synced 2024-11-15 08:33:06 +00:00
gen-h: do not output visibility macros when the build is static
This commit is contained in:
parent
c89b522233
commit
99ee0608f7
@ -9075,8 +9075,11 @@ static void gen_h_file(CodeGen *g) {
|
|||||||
if (!out_h)
|
if (!out_h)
|
||||||
zig_panic("unable to open %s: %s\n", buf_ptr(out_h_path), strerror(errno));
|
zig_panic("unable to open %s: %s\n", buf_ptr(out_h_path), strerror(errno));
|
||||||
|
|
||||||
Buf *export_macro = preprocessor_mangle(buf_sprintf("%s_EXPORT", buf_ptr(g->root_out_name)));
|
Buf *export_macro = nullptr;
|
||||||
buf_upcase(export_macro);
|
if (g->is_dynamic) {
|
||||||
|
export_macro = preprocessor_mangle(buf_sprintf("%s_EXPORT", buf_ptr(g->root_out_name)));
|
||||||
|
buf_upcase(export_macro);
|
||||||
|
}
|
||||||
|
|
||||||
Buf *extern_c_macro = preprocessor_mangle(buf_sprintf("%s_EXTERN_C", buf_ptr(g->root_out_name)));
|
Buf *extern_c_macro = preprocessor_mangle(buf_sprintf("%s_EXTERN_C", buf_ptr(g->root_out_name)));
|
||||||
buf_upcase(extern_c_macro);
|
buf_upcase(extern_c_macro);
|
||||||
@ -9101,10 +9104,11 @@ static void gen_h_file(CodeGen *g) {
|
|||||||
FnExport *fn_export = &fn_table_entry->export_list.items[0];
|
FnExport *fn_export = &fn_table_entry->export_list.items[0];
|
||||||
symbol_name = &fn_export->name;
|
symbol_name = &fn_export->name;
|
||||||
}
|
}
|
||||||
|
|
||||||
buf_appendf(&h_buf, "%s %s %s(",
|
buf_appendf(&h_buf, "%s %s %s(",
|
||||||
buf_ptr(export_macro),
|
buf_ptr(g->is_dynamic ? export_macro : extern_c_macro),
|
||||||
buf_ptr(&return_type_c),
|
buf_ptr(&return_type_c),
|
||||||
buf_ptr(symbol_name));
|
buf_ptr(symbol_name));
|
||||||
|
|
||||||
Buf param_type_c = BUF_INIT;
|
Buf param_type_c = BUF_INIT;
|
||||||
if (fn_type_id->param_count > 0) {
|
if (fn_type_id->param_count > 0) {
|
||||||
@ -9154,13 +9158,16 @@ static void gen_h_file(CodeGen *g) {
|
|||||||
fprintf(out_h, "#define %s\n", buf_ptr(extern_c_macro));
|
fprintf(out_h, "#define %s\n", buf_ptr(extern_c_macro));
|
||||||
fprintf(out_h, "#endif\n");
|
fprintf(out_h, "#endif\n");
|
||||||
fprintf(out_h, "\n");
|
fprintf(out_h, "\n");
|
||||||
fprintf(out_h, "#if defined(_WIN32)\n");
|
|
||||||
fprintf(out_h, "#define %s %s __declspec(dllimport)\n", buf_ptr(export_macro), buf_ptr(extern_c_macro));
|
if (g->is_dynamic) {
|
||||||
fprintf(out_h, "#else\n");
|
fprintf(out_h, "#if defined(_WIN32)\n");
|
||||||
fprintf(out_h, "#define %s %s __attribute__((visibility (\"default\")))\n",
|
fprintf(out_h, "#define %s %s __declspec(dllimport)\n", buf_ptr(export_macro), buf_ptr(extern_c_macro));
|
||||||
|
fprintf(out_h, "#else\n");
|
||||||
|
fprintf(out_h, "#define %s %s __attribute__((visibility (\"default\")))\n",
|
||||||
buf_ptr(export_macro), buf_ptr(extern_c_macro));
|
buf_ptr(export_macro), buf_ptr(extern_c_macro));
|
||||||
fprintf(out_h, "#endif\n");
|
fprintf(out_h, "#endif\n");
|
||||||
fprintf(out_h, "\n");
|
fprintf(out_h, "\n");
|
||||||
|
}
|
||||||
|
|
||||||
for (size_t type_i = 0; type_i < gen_h->types_to_declare.length; type_i += 1) {
|
for (size_t type_i = 0; type_i < gen_h->types_to_declare.length; type_i += 1) {
|
||||||
ZigType *type_entry = gen_h->types_to_declare.at(type_i);
|
ZigType *type_entry = gen_h->types_to_declare.at(type_i);
|
||||||
|
@ -11,7 +11,7 @@ pub fn addCases(cases: *tests.GenHContext) void {
|
|||||||
\\ C = 2
|
\\ C = 2
|
||||||
\\};
|
\\};
|
||||||
\\
|
\\
|
||||||
\\TEST_EXPORT void entry(enum Foo foo);
|
\\TEST_EXTERN_C void entry(enum Foo foo);
|
||||||
\\
|
\\
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -35,7 +35,7 @@ pub fn addCases(cases: *tests.GenHContext) void {
|
|||||||
\\ uint64_t F;
|
\\ uint64_t F;
|
||||||
\\};
|
\\};
|
||||||
\\
|
\\
|
||||||
\\TEST_EXPORT void entry(struct Foo foo);
|
\\TEST_EXTERN_C void entry(struct Foo foo);
|
||||||
\\
|
\\
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -70,7 +70,7 @@ pub fn addCases(cases: *tests.GenHContext) void {
|
|||||||
\\ struct Big D;
|
\\ struct Big D;
|
||||||
\\};
|
\\};
|
||||||
\\
|
\\
|
||||||
\\TEST_EXPORT void entry(union Foo foo);
|
\\TEST_EXTERN_C void entry(union Foo foo);
|
||||||
\\
|
\\
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -81,7 +81,7 @@ pub fn addCases(cases: *tests.GenHContext) void {
|
|||||||
,
|
,
|
||||||
\\struct Foo;
|
\\struct Foo;
|
||||||
\\
|
\\
|
||||||
\\TEST_EXPORT void entry(struct Foo * foo);
|
\\TEST_EXTERN_C void entry(struct Foo * foo);
|
||||||
);
|
);
|
||||||
|
|
||||||
cases.add("array field-type",
|
cases.add("array field-type",
|
||||||
@ -96,7 +96,7 @@ pub fn addCases(cases: *tests.GenHContext) void {
|
|||||||
\\ uint32_t * B[4];
|
\\ uint32_t * B[4];
|
||||||
\\};
|
\\};
|
||||||
\\
|
\\
|
||||||
\\TEST_EXPORT void entry(struct Foo foo, uint8_t bar[]);
|
\\TEST_EXTERN_C void entry(struct Foo foo, uint8_t bar[]);
|
||||||
\\
|
\\
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -110,7 +110,7 @@ pub fn addCases(cases: *tests.GenHContext) void {
|
|||||||
\\}
|
\\}
|
||||||
,
|
,
|
||||||
\\struct S;
|
\\struct S;
|
||||||
\\TEST_EXPORT uint8_t a(struct S * s);
|
\\TEST_EXTERN_C uint8_t a(struct S * s);
|
||||||
\\
|
\\
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -125,7 +125,7 @@ pub fn addCases(cases: *tests.GenHContext) void {
|
|||||||
\\}
|
\\}
|
||||||
,
|
,
|
||||||
\\union U;
|
\\union U;
|
||||||
\\TEST_EXPORT uint8_t a(union U * s);
|
\\TEST_EXTERN_C uint8_t a(union U * s);
|
||||||
\\
|
\\
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -140,7 +140,7 @@ pub fn addCases(cases: *tests.GenHContext) void {
|
|||||||
\\}
|
\\}
|
||||||
,
|
,
|
||||||
\\enum E;
|
\\enum E;
|
||||||
\\TEST_EXPORT uint8_t a(enum E * s);
|
\\TEST_EXTERN_C uint8_t a(enum E * s);
|
||||||
\\
|
\\
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user