From ef2a8e929d5337755e9b1d1e1d4ad859dc694eee Mon Sep 17 00:00:00 2001 From: martijneken Date: Fri, 28 Jul 2023 17:08:04 -0400 Subject: [PATCH] wasm_cc_binary: Specify a default OS. Allow users to override platform. (#1262) * wasm_cc_binary: Specify a default OS. Allow users to override platform. Problem: https://github.com/proxy-wasm/proxy-wasm-cpp-sdk/pull/157#discussion_r1277763118 This is solving the problem in two different ways. Please let me know your thoughts about both approaches, as either will work. Signed-off-by: Martijn Stevenson * Rework platform selection to trigger os:wasi off standalone attr Signed-off-by: Martijn Stevenson --------- Signed-off-by: Martijn Stevenson --- bazel/BUILD | 8 ++++++++ bazel/emscripten_toolchain/wasm_cc_binary.bzl | 4 +++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/bazel/BUILD b/bazel/BUILD index bce4ade..e67311d 100644 --- a/bazel/BUILD +++ b/bazel/BUILD @@ -84,3 +84,11 @@ platform( "@platforms//cpu:wasm32", ], ) + +platform( + name = "platform_wasi", + constraint_values = [ + "@platforms//cpu:wasm32", + "@platforms//os:wasi", + ], +) diff --git a/bazel/emscripten_toolchain/wasm_cc_binary.bzl b/bazel/emscripten_toolchain/wasm_cc_binary.bzl index 416ccae..fe77e17 100644 --- a/bazel/emscripten_toolchain/wasm_cc_binary.bzl +++ b/bazel/emscripten_toolchain/wasm_cc_binary.bzl @@ -25,7 +25,9 @@ def _wasm_transition_impl(settings, attr): if attr.simd: features.append("wasm_simd") + platform = "@emsdk//:platform_wasm" if attr.standalone: + platform = "@emsdk//:platform_wasi" features.append("wasm_standalone") return { @@ -35,7 +37,7 @@ def _wasm_transition_impl(settings, attr): "//command_line_option:features": features, "//command_line_option:dynamic_mode": "off", "//command_line_option:linkopt": linkopts, - "//command_line_option:platforms": ["@emsdk//:platform_wasm"], + "//command_line_option:platforms": [platform], "//command_line_option:custom_malloc": "@emsdk//emscripten_toolchain:malloc", }