Skip to content

Commit

Permalink
fix(windows): explicitly export symbols
Browse files Browse the repository at this point in the history
This also fixes some ifdefs.
  • Loading branch information
ObserverOfTime committed Apr 13, 2024
1 parent 7711ad1 commit 8cdf154
Show file tree
Hide file tree
Showing 7 changed files with 175 additions and 173 deletions.
10 changes: 5 additions & 5 deletions cli/src/generate/render.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1326,20 +1326,20 @@ impl Generator {
}

add_line!(self, "#ifdef TREE_SITTER_HIDE_SYMBOLS");
add_line!(self, "#define TS_PUBLIC");
add_line!(self, "#elif defined(_WIN32)");
add_line!(self, "#define TS_PUBLIC __declspec(dllexport)");
add_line!(self, "#define TS_EXPORT");
add_line!(self, "#elif defined(_MSC_VER)");
add_line!(self, "#define TS_EXPORT __declspec(dllexport)");
add_line!(self, "#else");
add_line!(
self,
"#define TS_PUBLIC __attribute__((visibility(\"default\")))"
"#define TS_EXPORT __attribute__((visibility(\"default\")))"
);
add_line!(self, "#endif");
add_line!(self, "");

add_line!(
self,
"TS_PUBLIC const TSLanguage *{language_function_name}(void) {{",
"TS_EXPORT const TSLanguage *{language_function_name}(void) {{",
);
indent!(self);
add_line!(self, "static const TSLanguage language = {{");
Expand Down
6 changes: 3 additions & 3 deletions cli/src/generate/templates/alloc.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ extern "C" {
#include <stdio.h>
#include <stdlib.h>

// Allow clients to override allocation functions
#ifdef TREE_SITTER_REUSE_ALLOCATOR

extern void *(*ts_current_malloc)(size_t);
extern void *(*ts_current_calloc)(size_t, size_t);
extern void *(*ts_current_realloc)(void *, size_t);
extern void (*ts_current_free)(void *);

// Allow clients to override allocation functions
#ifdef TREE_SITTER_REUSE_ALLOCATOR

#ifndef ts_malloc
#define ts_malloc ts_current_malloc
#endif
Expand Down
8 changes: 4 additions & 4 deletions cli/src/tests/detect_language.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,12 +97,12 @@ fn tree_sitter_dir(package_json: &str, name: &str) -> tempfile::TempDir {
format!(
r##"
#include "tree_sitter/parser.h"
#ifdef _WIN32
#define TS_PUBLIC __declspec(dllexport)
#ifdef _MSC_VER
#define TS_EXPORT __declspec(dllexport)
#else
#define TS_PUBLIC __attribute__((visibility("default")))
#define TS_EXPORT __attribute__((visibility("default")))
#endif
TS_PUBLIC const TSLanguage *tree_sitter_{name}() {{}}
TS_EXPORT const TSLanguage *tree_sitter_{name}() {{}}
"##
),
)
Expand Down

0 comments on commit 8cdf154

Please sign in to comment.