Skip to content

SDK: Expose C bindings#126

Open
inge4pres wants to merge 5 commits intomainfrom
c-interop
Open

SDK: Expose C bindings#126
inge4pres wants to merge 5 commits intomainfrom
c-interop

Conversation

@inge4pres
Copy link
Collaborator

Reason for this PR

Create C exports, statically linked library and relevant header file to allow C programs to consume the Zig implementation of the SDK.

Closes #56.

Details

Exposing Zig code to C was not as easy as I thought 😅
There are several limitations that I encountered and I had not foreseen simply due to my lack of experience on the matter (Dunning-Krueger?).

Nevertheless, the PR:

  • Mirrors the SDK Zig types to export new types in c.zig
  • Re-defines enums where needed
  • Forces the use f std.heap.c_allocator on the C exported code
  • Adds examples, compiling and running as part of a new step, and using them as validation tests (zig buildexample-c)

Additional context

We should be more explicit that the C API is not going to be stable even when we stabilize the SDK.
The reason is: depending on the type of modifications we apply to the Zig SDK code, we might not reflect them immediately to the C code (it might require additional changes in the C part).
We cannot require contributors that changes to the Zig code are updated on the C part in the same PR, hence we are not going to flag the C API as stable.

Signed-off-by: inge4pres <fgualazzi@gmail.com>
Signed-off-by: inge4pres <fgualazzi@gmail.com>
Signed-off-by: inge4pres <fgualazzi@gmail.com>
Signed-off-by: inge4pres <fgualazzi@gmail.com>
Signed-off-by: inge4pres <fgualazzi@gmail.com>
@inge4pres
Copy link
Collaborator Author

Proud to have accomplished this

☁  opentelemetry-sdk [c-interop] nm -g zig-out/lib/libopentelemetry-sdk.a 2>&1 | grep otel_
00000000000081d0 T otel_counter_add_u64
000000000000ca00 T otel_gauge_record_f64
000000000000b1e0 T otel_histogram_record_f64
000000000029ce10 T otel_logger_emit
000000000029d4f0 T otel_logger_is_enabled
000000000029bc90 T otel_logger_provider_add_log_record_processor
000000000029a3d0 T otel_logger_provider_create
000000000029c450 T otel_logger_provider_force_flush
000000000029b520 T otel_logger_provider_get_logger
000000000029a9b0 T otel_logger_provider_shutdown
000000000029d880 T otel_log_record_exporter_stdout_create
0000000000006ef0 T otel_meter_create_counter_u64
000000000000bed0 T otel_meter_create_gauge_f64
000000000000a6b0 T otel_meter_create_histogram_f64
0000000000008eb0 T otel_meter_create_updown_counter_i64
0000000000004c10 T otel_meter_provider_add_reader
0000000000003be0 T otel_meter_provider_create
0000000000004490 T otel_meter_provider_get_meter
0000000000003d00 T otel_meter_provider_init
0000000000003e50 T otel_meter_provider_shutdown
000000000000e310 T otel_metric_exporter_inmemory_create
000000000000da40 T otel_metric_exporter_stdout_create
000000000004b8c0 T otel_metric_reader_collect
000000000000ee20 T otel_metric_reader_create
000000000004bb00 T otel_metric_reader_shutdown
000000000029db50 T otel_simple_log_record_processor_create
0000000000251dc0 T otel_simple_span_processor_create
000000000024ee80 T otel_span_add_event
000000000024f5b0 T otel_span_add_event_with_timestamp
000000000024d380 T otel_span_end
000000000024d500 T otel_span_end_with_timestamp
0000000000251910 T otel_span_exporter_stdout_create
0000000000251650 T otel_span_get_span_id_hex
0000000000251340 T otel_span_get_trace_id_hex
00000000002511c0 T otel_span_is_recording
0000000000250dd0 T otel_span_record_exception
000000000024e300 T otel_span_set_attribute_bool
000000000024dfa0 T otel_span_set_attribute_double
000000000024dc50 T otel_span_set_attribute_int
000000000024d930 T otel_span_set_attribute_string
000000000024fd50 T otel_span_set_status
0000000000250080 T otel_span_update_name
000000000024d260 T otel_tracer_is_enabled
000000000024af90 T otel_tracer_provider_add_span_processor
00000000002499e0 T otel_tracer_provider_create
000000000024b730 T otel_tracer_provider_force_flush
000000000024a830 T otel_tracer_provider_get_tracer
0000000000249f80 T otel_tracer_provider_shutdown
000000000024c270 T otel_tracer_start_span
00000000000099d0 T otel_updown_counter_add_i64

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

build: compilation is wrong, library output of zig build has no symbols.

1 participant