|
| 1 | +load("@rules_cc//cc:defs.bzl", "cc_library") |
| 2 | + |
| 3 | +package(default_visibility = ["//visibility:public"]) |
| 4 | + |
| 5 | +licenses(["notice"]) # Apache 2.0 with LLVM exception |
| 6 | + |
| 7 | +cc_library( |
| 8 | + name = "iwasm", |
| 9 | + srcs = [ |
| 10 | + # Memory allocator sources (EMS only - tlsf has been removed from upstream) |
| 11 | + "core/shared/mem-alloc/ems/ems_alloc.c", |
| 12 | + "core/shared/mem-alloc/ems/ems_gc.c", |
| 13 | + "core/shared/mem-alloc/ems/ems_hmu.c", |
| 14 | + "core/shared/mem-alloc/ems/ems_kfc.c", |
| 15 | + "core/shared/mem-alloc/mem_alloc.c", |
| 16 | + # Shared utils |
| 17 | + "core/shared/utils/bh_assert.c", |
| 18 | + "core/shared/utils/bh_bitmap.c", |
| 19 | + "core/shared/utils/bh_common.c", |
| 20 | + "core/shared/utils/bh_hashmap.c", |
| 21 | + "core/shared/utils/bh_leb128.c", |
| 22 | + "core/shared/utils/bh_list.c", |
| 23 | + "core/shared/utils/bh_log.c", |
| 24 | + "core/shared/utils/bh_queue.c", |
| 25 | + "core/shared/utils/bh_vector.c", |
| 26 | + "core/shared/utils/runtime_timer.c", |
| 27 | + # IWASM common sources |
| 28 | + "core/iwasm/common/wasm_blocking_op.c", |
| 29 | + "core/iwasm/common/wasm_c_api.c", |
| 30 | + "core/iwasm/common/wasm_exec_env.c", |
| 31 | + "core/iwasm/common/wasm_loader_common.c", |
| 32 | + "core/iwasm/common/wasm_memory.c", |
| 33 | + "core/iwasm/common/wasm_native.c", |
| 34 | + "core/iwasm/common/wasm_runtime_common.c", |
| 35 | + "core/iwasm/common/wasm_shared_memory.c", |
| 36 | + # Interpreter sources |
| 37 | + "core/iwasm/interpreter/wasm_loader.c", |
| 38 | + "core/iwasm/interpreter/wasm_runtime.c", |
| 39 | + ] + select({ |
| 40 | + # Fast vs classic interpreter |
| 41 | + "//bazel:fast_interp_enabled": ["core/iwasm/interpreter/wasm_interp_fast.c"], |
| 42 | + "//conditions:default": ["core/iwasm/interpreter/wasm_interp_classic.c"], |
| 43 | + }) + select({ |
| 44 | + # Platform-specific sources |
| 45 | + "@platforms//os:linux": [ |
| 46 | + "core/shared/platform/linux/platform_init.c", |
| 47 | + "core/shared/platform/common/posix/posix_malloc.c", |
| 48 | + "core/shared/platform/common/posix/posix_memmap.c", |
| 49 | + "core/shared/platform/common/posix/posix_thread.c", |
| 50 | + "core/shared/platform/common/posix/posix_time.c", |
| 51 | + "core/shared/platform/common/posix/posix_sleep.c", |
| 52 | + "core/shared/platform/common/posix/posix_blocking_op.c", |
| 53 | + ], |
| 54 | + "@platforms//os:macos": [ |
| 55 | + "core/shared/platform/darwin/platform_init.c", |
| 56 | + "core/shared/platform/common/posix/posix_malloc.c", |
| 57 | + "core/shared/platform/common/posix/posix_memmap.c", |
| 58 | + "core/shared/platform/common/posix/posix_thread.c", |
| 59 | + "core/shared/platform/common/posix/posix_time.c", |
| 60 | + "core/shared/platform/common/posix/posix_sleep.c", |
| 61 | + "core/shared/platform/common/posix/posix_blocking_op.c", |
| 62 | + # macOS doesn't have mremap, use fallback |
| 63 | + "core/shared/platform/common/memory/mremap.c", |
| 64 | + ], |
| 65 | + }) + select({ |
| 66 | + # Architecture-specific native invoke sources |
| 67 | + "//bazel:x86_64_simd": ["core/iwasm/common/arch/invokeNative_em64_simd.s"], |
| 68 | + "//bazel:x86_64_no_simd": ["core/iwasm/common/arch/invokeNative_em64.s"], |
| 69 | + "//bazel:aarch64_simd": ["core/iwasm/common/arch/invokeNative_aarch64_simd.s"], |
| 70 | + "//bazel:aarch64_no_simd": ["core/iwasm/common/arch/invokeNative_aarch64.s"], |
| 71 | + # Fallback to general C implementation for other architectures |
| 72 | + "//conditions:default": ["core/iwasm/common/arch/invokeNative_general.c"], |
| 73 | + }), |
| 74 | + hdrs = glob([ |
| 75 | + "core/*.h", # For version.h and config.h |
| 76 | + "core/iwasm/include/*.h", |
| 77 | + "core/shared/platform/include/*.h", |
| 78 | + "core/shared/platform/linux/*.h", |
| 79 | + "core/shared/platform/darwin/*.h", |
| 80 | + "core/shared/platform/common/posix/*.h", |
| 81 | + "core/shared/mem-alloc/*.h", |
| 82 | + "core/shared/mem-alloc/ems/*.h", |
| 83 | + "core/shared/utils/*.h", |
| 84 | + "core/iwasm/common/*.h", |
| 85 | + "core/iwasm/interpreter/*.h", |
| 86 | + "core/iwasm/aot/*.h", |
| 87 | + "core/iwasm/compilation/*.h", |
| 88 | + ]), |
| 89 | + copts = select({ |
| 90 | + "@platforms//os:windows": [], |
| 91 | + "//conditions:default": [ |
| 92 | + "-std=gnu99", |
| 93 | + "-Wno-unused-parameter", |
| 94 | + "-Wno-pedantic", |
| 95 | + "-Wno-unused-command-line-argument", |
| 96 | + ], |
| 97 | + }), |
| 98 | + includes = [ |
| 99 | + ".", # Root for all relative paths |
| 100 | + "core", |
| 101 | + "core/iwasm", # For relative paths like ../aot/ from common/ |
| 102 | + "core/iwasm/include", |
| 103 | + "core/shared/platform/include", |
| 104 | + "core/shared/mem-alloc", |
| 105 | + "core/shared/mem-alloc/ems", |
| 106 | + "core/shared/utils", |
| 107 | + "core/iwasm/common", |
| 108 | + "core/iwasm/interpreter", |
| 109 | + "core/iwasm/aot", |
| 110 | + "core/iwasm/compilation", |
| 111 | + ] + select({ |
| 112 | + "@platforms//os:linux": ["core/shared/platform/linux"], |
| 113 | + "@platforms//os:macos": ["core/shared/platform/darwin"], |
| 114 | + "//conditions:default": [], |
| 115 | + }), |
| 116 | + linkopts = select({ |
| 117 | + "@platforms//os:linux": ["-lpthread", "-lm"], |
| 118 | + "@platforms//os:macos": ["-lpthread"], |
| 119 | + "//conditions:default": [], |
| 120 | + }), |
| 121 | + local_defines = [ |
| 122 | + # Core defines |
| 123 | + "WASM_ENABLE_INTERP=1", |
| 124 | + "BH_MALLOC=wasm_runtime_malloc", |
| 125 | + "BH_FREE=wasm_runtime_free", |
| 126 | + # Use EMS allocator (tlsf has been removed from upstream WAMR) |
| 127 | + "MEM_ALLOCATOR_EMS=0", |
| 128 | + "MEM_ALLOCATOR_TLSF=1", |
| 129 | + "DEFAULT_MEM_ALLOCATOR=MEM_ALLOCATOR_EMS", |
| 130 | + # Disable features we don't need |
| 131 | + "WASM_ENABLE_LIBC_WASI=0", |
| 132 | + "WASM_ENABLE_LIBC_BUILTIN=0", |
| 133 | + "WASM_ENABLE_MULTI_MODULE=0", |
| 134 | + "WASM_ENABLE_AOT=0", |
| 135 | + "WASM_ENABLE_JIT=0", |
| 136 | + ] + select({ |
| 137 | + "@platforms//os:linux": [ |
| 138 | + "BH_PLATFORM_LINUX", |
| 139 | + "_GNU_SOURCE", # Required for mremap and MREMAP_MAYMOVE |
| 140 | + "WASM_HAVE_MREMAP=1", # Linux has native mremap syscall |
| 141 | + ], |
| 142 | + "@platforms//os:macos": ["BH_PLATFORM_DARWIN"], |
| 143 | + "//conditions:default": [], |
| 144 | + }) + select({ |
| 145 | + "//bazel:fast_interp_enabled": ["WASM_ENABLE_FAST_INTERP=1"], |
| 146 | + "//conditions:default": ["WASM_ENABLE_FAST_INTERP=0"], |
| 147 | + }) + select({ |
| 148 | + "//bazel:dump_call_stack_enabled": ["WASM_ENABLE_DUMP_CALL_STACK=1"], |
| 149 | + "//conditions:default": ["WASM_ENABLE_DUMP_CALL_STACK=0"], |
| 150 | + }) + select({ |
| 151 | + "//bazel:custom_name_section_enabled": ["WASM_ENABLE_CUSTOM_NAME_SECTION=1"], |
| 152 | + "//conditions:default": ["WASM_ENABLE_CUSTOM_NAME_SECTION=0"], |
| 153 | + }) + select({ |
| 154 | + "//bazel:load_custom_section_enabled": ["WASM_ENABLE_LOAD_CUSTOM_SECTION=1"], |
| 155 | + "//conditions:default": ["WASM_ENABLE_LOAD_CUSTOM_SECTION=0"], |
| 156 | + }) + select({ |
| 157 | + "//bazel:bulk_memory_enabled": ["WASM_ENABLE_BULK_MEMORY=1"], |
| 158 | + "//conditions:default": ["WASM_ENABLE_BULK_MEMORY=0"], |
| 159 | + }) + select({ |
| 160 | + "//bazel:ref_types_enabled": ["WASM_ENABLE_REF_TYPES=1"], |
| 161 | + "//conditions:default": ["WASM_ENABLE_REF_TYPES=0"], |
| 162 | + }) + select({ |
| 163 | + "//bazel:tail_call_enabled": ["WASM_ENABLE_TAIL_CALL=1"], |
| 164 | + "//conditions:default": ["WASM_ENABLE_TAIL_CALL=0"], |
| 165 | + }) + select({ |
| 166 | + "//bazel:simd_enabled": ["WASM_ENABLE_SIMD=1"], |
| 167 | + "//conditions:default": ["WASM_ENABLE_SIMD=0"], |
| 168 | + }), |
| 169 | +) |
| 170 | + |
| 171 | +# Alias for compatibility |
| 172 | +alias( |
| 173 | + name = "wamr_lib", |
| 174 | + actual = ":iwasm", |
| 175 | +) |
0 commit comments