Skip to content

Commit e26ca9b

Browse files
committed
Support jsonnet >= v0.19.0
1 parent e8c4469 commit e26ca9b

2 files changed

Lines changed: 38 additions & 3 deletions

File tree

ext/jsonnet/callbacks.c

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,9 +104,15 @@ rubyjsonnet_jump_tag(const char *exc_mesg)
104104
return 0;
105105
}
106106

107+
#ifdef HAVE_JSONNET_IMPORT_CALLBACK_0_19
108+
static int
109+
import_callback_entrypoint(void *ctx, const char *base, const char *rel, char **found_here,
110+
char **buf, size_t *buflen)
111+
#else
107112
static char *
108113
import_callback_entrypoint(void *ctx, const char *base, const char *rel, char **found_here,
109114
int *success)
115+
#endif
110116
{
111117
struct jsonnet_vm_wrap *const vm = (struct jsonnet_vm_wrap *)ctx;
112118
int state;
@@ -123,14 +129,26 @@ import_callback_entrypoint(void *ctx, const char *base, const char *rel, char **
123129

124130
if (state) {
125131
VALUE msg = rescue_callback(state, "cannot import %s from %s", rel, base);
132+
#ifdef HAVE_JSONNET_IMPORT_CALLBACK_0_19
133+
*buf = rubyjsonnet_str_to_cstr(vm->vm, msg);
134+
*buflen = RSTRING_LEN(msg);
135+
return 1;
136+
#else
126137
*success = 0;
127138
return rubyjsonnet_str_to_cstr(vm->vm, msg);
139+
#endif
128140
}
129141

130142
result = rb_Array(result);
131-
*success = 1;
132143
*found_here = rubyjsonnet_str_to_cstr(vm->vm, rb_ary_entry(result, 1));
144+
#ifdef HAVE_JSONNET_IMPORT_CALLBACK_0_19
145+
*buf = rubyjsonnet_str_to_cstr(vm->vm, rb_ary_entry(result, 0));
146+
*buflen = RSTRING_LEN(rb_ary_entry(result, 0));
147+
return 0;
148+
#else
149+
*success = 1;
133150
return rubyjsonnet_str_to_cstr(vm->vm, rb_ary_entry(result, 0));
151+
#endif
134152
}
135153

136154
/*

ext/jsonnet/extconf.rb

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ def using_system_libraries?
1313
require 'mini_portile2'
1414
message "Using mini_portile version #{MiniPortile::VERSION}\n"
1515

16-
recipe = MiniPortile.new('jsonnet', 'v0.18.0')
17-
recipe.files = ['https://github.com/google/jsonnet/archive/v0.18.0.tar.gz']
16+
recipe = MiniPortile.new('jsonnet', 'v0.20.0')
17+
recipe.files = ['https://github.com/google/jsonnet/archive/v0.20.0.tar.gz']
1818
class << recipe
1919
CORE_OBJS = %w[
2020
desugarer.o formatter.o lexer.o libjsonnet.o parser.o pass.o static_analysis.o string_utils.o vm.o
@@ -89,4 +89,21 @@ def target_object_files
8989
abort 'libjsonnet.h not found' unless have_header('libjsonnet.h')
9090
abort 'libjsonnet not found' unless have_library('jsonnet')
9191
have_header('libjsonnet_fmt.h')
92+
93+
import_callback_0_19 = checking_for checking_message('JsonnetImportCallback >= v0.19.0') do
94+
try_compile(<<SRC, '-Werror=incompatible-pointer-types')
95+
#include <libjsonnet.h>
96+
97+
int f(void *ctx, const char *base, const char *rel, char **found_here, char **buf, size_t *buflen);
98+
99+
int main() {
100+
jsonnet_import_callback(NULL, f, NULL);
101+
return 0;
102+
}
103+
SRC
104+
end
105+
if import_callback_0_19
106+
$defs.push('-DHAVE_JSONNET_IMPORT_CALLBACK_0_19')
107+
end
108+
92109
create_makefile('jsonnet/jsonnet_wrap')

0 commit comments

Comments
 (0)