╭ export_builtin.zig ───────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭ find file ─ ─ ─ ─ ─ ─ ─ ─ ─ ─╮ ╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │ │ │http│ ssh │ │ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─╯ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
.. conflicting_externs/ hasdecl/ import/ namespace_depends_on_compile_var/ pub_enum/ x86_64/ zon/ abs.zig addrspace_and_linksection.zig align.zig alignof.zig array.zig asm.zig atomics.zig backing_int.zig basic.zig bit_shifting.zig bitcast.zig bitreverse.zig bool.zig builtin_functions_returning_void_ byteswap.zig byval_arg_var.zig call.zig cast.zig cast_int.zig comptime_memory.zig const_slice_child.zig decl_literals.zig decltest.zig defer.zig destructure.zig duplicated_test_names.zig enum.zig error.zig eval.zig ╭─────────────────────────────────╮ │export_builtin.zig │ ╰─────────────────────────────────╯ export_c_keywords.zig export_keyword.zig export_self_referential_type_info extern.zig extern_struct_zero_size_fields.zi field_parent_ptr.zig file_to_embed.txt floatop.zig fn.zig fn_delegation.zig fn_in_struct_in_comptime.zig for.zig generics.zig globals.zig hasdecl.zig hasfield.zig if.zig import.zig import_c_keywords.zig incomplete_struct_param_tld.zig inline_switch.zig int128.zig int_comparison_elision.zig ir_block_deps.zig lower_strlit_to_vector.zig math.zig maximum_minimum.zig member_func.zig memcpy.zig memmove.zig memset.zig merge_error_sets.zig muladd.zig multiple_externs_with_conflicting namespace_depends_on_compile_var. nan.zig null.zig optional.zig overlapping_assign.zig packed-struct.zig packed-union.zig packed_struct_explicit_backing_in pointers.zig popcount.zig prefetch.zig ptrcast.zig ptrfromint.zig pub_enum.zig ref_var_in_if_after_if_2nd_switch reflection.zig return_address.zig saturating_arithmetic.zig select.zig shuffle.zig sizeof_and_typeof.zig slice.zig slice_sentinel_comptime.zig spirv.zig splat.zig src.zig string_literals.zig struct.zig struct_contains_null_ptr_itself.z struct_contains_slice_of_itself.z switch.zig switch_loop.zig switch_on_captured_error.zig switch_prong_err_enum.zig switch_prong_implicit_cast.zig this.zig threadlocal.zig truncate.zig try.zig tuple.zig tuple_declarations.zig type.zig type_info.zig typename.zig undefined.zig underscore.zig union.zig var_args.zig vector.zig void.zig wasm.zig while.zig widening.zig wrapping_arithmetic.zig x86_64.zig zero.bin zon.zig
1 const builtin = @import("builtin"); 2 const std = @import("std"); 3 const expect = std.testing.expect; 4 5 test "exporting enum value" { 6 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; 7 if (builtin.zig_backend == .stage2_spirv) return error.SkipZigTest; 8 9 const S = struct { 10 const E = enum(c_int) { one, two }; 11 const e: E = .two; 12 comptime { 13 @export(&e, .{ .name = "e" }); 14 } 15 }; 16 try expect(S.e == .two); 17 } 18 19 test "exporting with internal linkage" { 20 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; 21 22 const S = struct { 23 fn foo() callconv(.c) void {} 24 comptime { 25 @export(&foo, .{ .name = "exporting_with_internal_linkage_foo", .linkage = .internal }); 26 } 27 }; 28 S.foo(); 29 } 30 31 test "exporting using namespace access" { 32 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; 33 if (builtin.zig_backend == .stage2_spirv) return error.SkipZigTest; 34 35 const S = struct { 36 const Inner = struct { 37 const x: u32 = 5; 38 }; 39 comptime { 40 @export(&Inner.x, .{ .name = "foo", .linkage = .internal }); 41 } 42 }; 43 44 _ = S.Inner.x; 45 } 46 47 test "exporting comptime-known value" { 48 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; 49 if (builtin.zig_backend == .stage2_c) return error.SkipZigTest; 50 if (builtin.zig_backend == .stage2_spirv) return error.SkipZigTest; 51 52 const x: u32 = 10; 53 @export(&x, .{ .name = "exporting_comptime_known_value_foo" }); 54 const S = struct { 55 extern const exporting_comptime_known_value_foo: u32; 56 }; 57 try expect(S.exporting_comptime_known_value_foo == 10); 58 } 59