aboutsummaryrefslogtreecommitdiff
path: root/src/codegen.cpp
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2019-05-27 21:51:34 -0400
committerGitHub <noreply@github.com>2019-05-27 21:51:34 -0400
commitf924fbddcfb615014aa7527686c1651c6e4d7846 (patch)
treeebd48dee465b3a301aeea64695023e89d0b1f7a6 /src/codegen.cpp
parent2c0280ba085893984007706fb40c7b291f43074d (diff)
parent99ee0608f74268248a2dc684cb9e6e9b03e3a9f5 (diff)
downloadzig-f924fbddcfb615014aa7527686c1651c6e4d7846.tar.gz
zig-f924fbddcfb615014aa7527686c1651c6e4d7846.zip
Merge pull request #2552 from Sahnvour/issue-2543
gen-h: do not output visibility macros when the build is static
Diffstat (limited to 'src/codegen.cpp')
-rw-r--r--src/codegen.cpp29
1 files changed, 18 insertions, 11 deletions
diff --git a/src/codegen.cpp b/src/codegen.cpp
index 2c3e30b3d8..6b6564ffba 100644
--- a/src/codegen.cpp
+++ b/src/codegen.cpp
@@ -9085,8 +9085,11 @@ static void gen_h_file(CodeGen *g) {
if (!out_h)
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_upcase(export_macro);
+ Buf *export_macro = nullptr;
+ 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_upcase(extern_c_macro);
@@ -9111,10 +9114,11 @@ static void gen_h_file(CodeGen *g) {
FnExport *fn_export = &fn_table_entry->export_list.items[0];
symbol_name = &fn_export->name;
}
+
buf_appendf(&h_buf, "%s %s %s(",
- buf_ptr(export_macro),
- buf_ptr(&return_type_c),
- buf_ptr(symbol_name));
+ buf_ptr(g->is_dynamic ? export_macro : extern_c_macro),
+ buf_ptr(&return_type_c),
+ buf_ptr(symbol_name));
Buf param_type_c = BUF_INIT;
if (fn_type_id->param_count > 0) {
@@ -9164,13 +9168,16 @@ static void gen_h_file(CodeGen *g) {
fprintf(out_h, "#define %s\n", buf_ptr(extern_c_macro));
fprintf(out_h, "#endif\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));
- fprintf(out_h, "#else\n");
- fprintf(out_h, "#define %s %s __attribute__((visibility (\"default\")))\n",
+
+ if (g->is_dynamic) {
+ 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));
+ fprintf(out_h, "#else\n");
+ fprintf(out_h, "#define %s %s __attribute__((visibility (\"default\")))\n",
buf_ptr(export_macro), buf_ptr(extern_c_macro));
- fprintf(out_h, "#endif\n");
- fprintf(out_h, "\n");
+ fprintf(out_h, "#endif\n");
+ fprintf(out_h, "\n");
+ }
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);