Skip to content

Commit 99f8354

Browse files
authored
chore: Simpler separation between component and core wasm builds (#450)
Only link the world in if we're building a component, and otherwise only link the adapter if we're targeting core wasm.
1 parent 8abb9d6 commit 99f8354

18 files changed

+187
-723
lines changed

c-dependencies/js-compute-runtime/Makefile

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ regenerate-world:
248248
endif
249249

250250

251-
# Compute runtime build ########################################################
251+
# Compute runtime shared build #################################################
252252

253253
FSM_CPP := $(wildcard $(FSM_SRC)/*.cpp)
254254
FSM_CPP += $(wildcard $(FSM_SRC)/builtins/*.cpp)
@@ -259,34 +259,43 @@ FSM_OBJ := $(patsubst $(FSM_SRC)/%.cpp,$(OBJ_DIR)/%.o,$(FSM_CPP))
259259

260260
# Build all the above object files
261261
$(foreach source,$(FSM_CPP),$(eval $(call compile_cxx,$(source))))
262-
$(eval $(call compile_cxx,$(FSM_SRC)/c-at-e-world/c_at_e_world_adapter.cpp))
263-
$(eval $(call compile_c,$(FSM_SRC)/c-at-e-world/c_at_e_world.c))
264262

265-
# Special build of c_at_e_world_adapter.cpp for the component model.
266-
$(OBJ_DIR)/c-at-e-world/c_at_e_world_adapter_component.o: $(FSM_SRC)/c-at-e-world/c_at_e_world_adapter.cpp
267-
$(OBJ_DIR)/c-at-e-world/c_at_e_world_adapter_component.o: DEFINES += -DCOMPONENT
268-
$(OBJ_DIR)/c-at-e-world/c_at_e_world_adapter_component.o: | $(OBJ_DIR)/c-at-e-world
269-
$(call cmd,wasi_cxx,$@)
263+
# Compute runtime build ########################################################
270264

265+
$(eval $(call compile_cxx,$(FSM_SRC)/c-at-e-world/c_at_e_world_adapter.cpp))
266+
267+
# This version of the runtime uses the world adapter in place of the world
268+
# generated by wit-bindgen, adapting to the currently available host calls on
269+
# c@e.
270+
#
271271
# NOTE: we shadow wasm-opt by adding $(FSM_SRC)/scripts to the path, which
272272
# includes a script called wasm-opt that immediately exits successfully. See
273273
# that script for more information about why we do this.
274-
275274
$(OBJ_DIR)/js-compute-runtime.wasm: $(FSM_OBJ) $(SM_OBJ) $(RUST_URL_LIB)
276-
$(OBJ_DIR)/js-compute-runtime.wasm: $(OBJ_DIR)/c-at-e-world/c_at_e_world.o
277275
$(OBJ_DIR)/js-compute-runtime.wasm: $(OBJ_DIR)/c-at-e-world/c_at_e_world_adapter.o
278276
$(call cmd_format,WASI_LD,$@) PATH="$(FSM_SRC)/scripts:$$PATH" \
279277
$(WASI_CXX) $(LD_FLAGS) $(OPENSSL_LIBS) -o $@ $^
280278
$(call cmd_format,WASM_STRIP,$@) $(call WASM_STRIP,$@)
281279

280+
281+
# Compute runtime component build ##############################################
282+
283+
$(eval $(call compile_c,$(FSM_SRC)/c-at-e-world/c_at_e_world.c))
284+
285+
# This version of the runtime uses the code generated by wit-bindgen, to
286+
# ultimately be run as a component on c@e.
287+
#
288+
# NOTE: we shadow wasm-opt by adding $(FSM_SRC)/scripts to the path, which
289+
# includes a script called wasm-opt that immediately exits successfully. See
290+
# that script for more information about why we do this.
282291
$(OBJ_DIR)/js-compute-runtime-component.wasm: $(FSM_OBJ) $(SM_OBJ) $(RUST_URL_LIB)
283292
$(OBJ_DIR)/js-compute-runtime-component.wasm: $(OBJ_DIR)/c-at-e-world/c_at_e_world.o
284-
$(OBJ_DIR)/js-compute-runtime-component.wasm: $(OBJ_DIR)/c-at-e-world/c_at_e_world_adapter_component.o
285293
$(call cmd_format,WASI_LD,$@) PATH="$(FSM_SRC)/scripts:$$PATH" \
286294
$(WASI_CXX) $(LD_FLAGS) $(OPENSSL_LIBS) -o $@ $^
287295
$(call cmd_format,WASM_STRIP,$@) $(call WASM_STRIP,$@)
288296

289-
# Shared builtins build
297+
298+
# Shared builtins build ########################################################
290299

291300
shared-builtins: shared/builtins.a shared/librust_url.a
292301

c-dependencies/js-compute-runtime/builtins/backend.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -813,8 +813,7 @@ JS::Result<mozilla::Ok> Backend::register_dynamic_backend(JSContext *cx, JS::Han
813813
}
814814

815815
fastly_error_t err;
816-
if (!c_at_e_fastly_http_req_register_dynamic_backend(&name_str, &target_str, &backend_config,
817-
&err)) {
816+
if (!fastly_http_req_register_dynamic_backend(&name_str, &target_str, &backend_config, &err)) {
818817
HANDLE_ERROR(cx, err);
819818
return JS::Result<mozilla::Ok>(JS::Error());
820819
}

c-dependencies/js-compute-runtime/builtins/client-info.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#include "builtins/client-info.h"
2-
#include "c-at-e-world/c_at_e_world_adapter.h"
32
#include "core/geo_ip.h"
3+
#include "host_interface/host_call.h"
44

55
#include "js/JSON.h"
66
#include <arpa/inet.h>
@@ -24,7 +24,7 @@ static JSString *retrieve_address(JSContext *cx, JS::HandleObject self) {
2424

2525
fastly_list_u8_t octets;
2626
fastly_error_t err;
27-
if (!c_at_e_fastly_http_req_downstream_client_ip_addr(&octets, &err)) {
27+
if (!fastly_http_req_downstream_client_ip_addr(&octets, &err)) {
2828
HANDLE_ERROR(cx, err);
2929
return nullptr;
3030
}

c-dependencies/js-compute-runtime/builtins/config-store.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ bool ConfigStore::get(JSContext *cx, unsigned argc, JS::Value *vp) {
3030
fastly_option_string_t ret;
3131
fastly_error_t err;
3232
// Ensure that we throw an exception for all unexpected host errors.
33-
if (!c_at_e_fastly_dictionary_get(ConfigStore::config_store_handle(self), &key_str, &ret, &err)) {
33+
if (!fastly_dictionary_get(ConfigStore::config_store_handle(self), &key_str, &ret, &err)) {
3434
HANDLE_ERROR(cx, err);
3535
return false;
3636
}
@@ -99,7 +99,7 @@ bool ConfigStore::constructor(JSContext *cx, unsigned argc, JS::Value *vp) {
9999
JS::RootedObject config_store(cx, JS_NewObjectForConstructor(cx, &class_, args));
100100
fastly_dictionary_handle_t dict_handle = INVALID_HANDLE;
101101
fastly_error_t err;
102-
if (!c_at_e_fastly_dictionary_open(&name_str, &dict_handle, &err)) {
102+
if (!fastly_dictionary_open(&name_str, &dict_handle, &err)) {
103103
if (err == FASTLY_ERROR_BAD_HANDLE) {
104104
JS_ReportErrorNumberASCII(cx, GetErrorMessage, nullptr, JSMSG_CONFIG_STORE_DOES_NOT_EXIST,
105105
name.data());

c-dependencies/js-compute-runtime/builtins/dictionary.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ bool Dictionary::get(JSContext *cx, unsigned argc, JS::Value *vp) {
3737
fastly_error_t err;
3838

3939
// Ensure that we throw an exception for all unexpected host errors.
40-
if (!c_at_e_fastly_dictionary_get(Dictionary::dictionary_handle(self), &name_str, &ret, &err)) {
40+
if (!fastly_dictionary_get(Dictionary::dictionary_handle(self), &name_str, &ret, &err)) {
4141
HANDLE_ERROR(cx, err);
4242
return false;
4343
}
@@ -113,7 +113,7 @@ bool Dictionary::constructor(JSContext *cx, unsigned argc, JS::Value *vp) {
113113

114114
fastly_dictionary_handle_t dict_handle = INVALID_HANDLE;
115115
fastly_error_t err;
116-
if (!c_at_e_fastly_dictionary_open(&name_str, &dict_handle, &err)) {
116+
if (!fastly_dictionary_open(&name_str, &dict_handle, &err)) {
117117
if (err == FASTLY_ERROR_BAD_HANDLE) {
118118
JS_ReportErrorNumberASCII(cx, GetErrorMessage, nullptr, JSMSG_DICTIONARY_DOES_NOT_EXIST,
119119
name_str.ptr);

c-dependencies/js-compute-runtime/builtins/fetch-event.cpp

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
#include "builtins/request-response.h"
55
#include "builtins/shared/url.h"
66
#include "builtins/worker-location.h"
7-
#include "c-at-e-world/c_at_e_world_adapter.h"
87
#include "host_interface/host_api.h"
98

109
namespace builtins {
@@ -83,7 +82,7 @@ bool FetchEvent::init_downstream_request(JSContext *cx, JS::HandleObject request
8382

8483
fastly_request_t req;
8584
fastly_error_t err;
86-
if (!c_at_e_fastly_http_req_body_downstream_get(&req, &err)) {
85+
if (!fastly_http_req_body_downstream_get(&req, &err)) {
8786
HANDLE_ERROR(cx, err);
8887
return false;
8988
}
@@ -98,7 +97,7 @@ bool FetchEvent::init_downstream_request(JSContext *cx, JS::HandleObject request
9897

9998
// Set the method.
10099
c_at_e_world_string_t method_str;
101-
if (!c_at_e_fastly_http_req_method_get(request_handle, &method_str, &err)) {
100+
if (!fastly_http_req_method_get(request_handle, &method_str, &err)) {
102101
HANDLE_ERROR(cx, err);
103102
return false;
104103
}
@@ -126,7 +125,7 @@ bool FetchEvent::init_downstream_request(JSContext *cx, JS::HandleObject request
126125
}
127126

128127
c_at_e_world_string_t uri_str;
129-
if (!c_at_e_fastly_http_req_uri_get(request_handle, &uri_str, &err)) {
128+
if (!fastly_http_req_uri_get(request_handle, &uri_str, &err)) {
130129
HANDLE_ERROR(cx, err);
131130
return false;
132131
}
@@ -185,7 +184,7 @@ bool start_response(JSContext *cx, JS::HandleObject response_obj, bool streaming
185184
fastly_body_handle_t body = RequestOrResponse::body_handle(response_obj);
186185

187186
fastly_error_t err;
188-
if (!c_at_e_fastly_http_resp_send_downstream(response, body, streaming, &err)) {
187+
if (!fastly_http_resp_send_downstream(response, body, streaming, &err)) {
189188
HANDLE_ERROR(cx, err);
190189
return false;
191190
}
@@ -308,7 +307,7 @@ bool FetchEvent::respondWithError(JSContext *cx, JS::HandleObject self) {
308307
fastly_response_handle_t response = INVALID_HANDLE;
309308
fastly_error_t err;
310309

311-
if (!c_at_e_fastly_http_resp_new(&response, &err)) {
310+
if (!fastly_http_resp_new(&response, &err)) {
312311
HANDLE_ERROR(cx, err);
313312
return false;
314313
}
@@ -320,8 +319,8 @@ bool FetchEvent::respondWithError(JSContext *cx, JS::HandleObject self) {
320319
}
321320

322321
auto body = make_res.unwrap();
323-
if (!c_at_e_fastly_http_resp_status_set(response, 500, &err) ||
324-
!c_at_e_fastly_http_resp_send_downstream(response, body.handle, false, &err)) {
322+
if (!fastly_http_resp_status_set(response, 500, &err) ||
323+
!fastly_http_resp_send_downstream(response, body.handle, false, &err)) {
325324
HANDLE_ERROR(cx, err);
326325
return false;
327326
}

c-dependencies/js-compute-runtime/builtins/headers.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -251,9 +251,9 @@ bool get_header_names_from_handle(JSContext *cx, uint32_t handle, Headers::Mode
251251
fastly_list_string_t ret;
252252
fastly_error_t err;
253253
if (mode == Headers::Mode::ProxyToRequest) {
254-
ok = c_at_e_fastly_http_req_header_names_get(handle, &ret, &err);
254+
ok = fastly_http_req_header_names_get(handle, &ret, &err);
255255
} else {
256-
ok = c_at_e_fastly_http_resp_header_names_get(handle, &ret, &err);
256+
ok = fastly_http_resp_header_names_get(handle, &ret, &err);
257257
}
258258

259259
if (!ok) {
@@ -294,9 +294,9 @@ bool retrieve_value_for_header_from_handle(JSContext *cx, JS::HandleObject self,
294294
bool ok;
295295
fastly_error_t err;
296296
if (mode == Headers::Mode::ProxyToRequest) {
297-
ok = c_at_e_fastly_http_req_header_values_get(handle, &str, &ret, &err);
297+
ok = fastly_http_req_header_values_get(handle, &str, &ret, &err);
298298
} else {
299-
ok = c_at_e_fastly_http_resp_header_values_get(handle, &str, &ret, &err);
299+
ok = fastly_http_resp_header_values_get(handle, &str, &ret, &err);
300300
}
301301

302302
if (!ok) {
@@ -467,8 +467,8 @@ bool Headers::append_header_value(JSContext *cx, JS::HandleObject self, JS::Hand
467467

468468
auto mode = get_mode(self);
469469
if (mode != Headers::Mode::Standalone) {
470-
auto *op = mode == Headers::Mode::ProxyToRequest ? c_at_e_fastly_http_req_header_append
471-
: c_at_e_fastly_http_resp_header_append;
470+
auto *op = mode == Headers::Mode::ProxyToRequest ? fastly_http_req_header_append
471+
: fastly_http_resp_header_append;
472472
std::string_view name(name_chars.get(), name_len);
473473
if (name == "set-cookie") {
474474
std::string_view value(value_chars.get(), value_len);
@@ -591,8 +591,8 @@ bool Headers::set(JSContext *cx, unsigned argc, JS::Value *vp) {
591591

592592
auto mode = get_mode(self);
593593
if (mode != Mode::Standalone) {
594-
auto *op = mode == Mode::ProxyToRequest ? c_at_e_fastly_http_req_header_insert
595-
: c_at_e_fastly_http_resp_header_insert;
594+
auto *op = mode == Mode::ProxyToRequest ? fastly_http_req_header_insert
595+
: fastly_http_resp_header_insert;
596596
c_at_e_world_string_t name = {name_chars.get(), name_len};
597597
c_at_e_world_string_t val = {value_chars.get(), value_len};
598598
fastly_error_t err;
@@ -681,8 +681,8 @@ bool Headers::delete_(JSContext *cx, unsigned argc, JS::Value *vp) {
681681

682682
auto mode = get_mode(self);
683683
if (mode != Headers::Mode::Standalone) {
684-
auto *op = mode == Mode::ProxyToRequest ? c_at_e_fastly_http_req_header_remove
685-
: c_at_e_fastly_http_resp_header_remove;
684+
auto *op = mode == Mode::ProxyToRequest ? fastly_http_req_header_remove
685+
: fastly_http_resp_header_remove;
686686
c_at_e_world_string_t name = {name_chars.get(), name_len};
687687
fastly_error_t err;
688688
if (!op(get_handle(self), &name, &err)) {

c-dependencies/js-compute-runtime/builtins/logger.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ bool Logger::log(JSContext *cx, unsigned argc, JS::Value *vp) {
1616

1717
fastly_error_t err;
1818
c_at_e_world_string_t msg_str = {msg.get(), msg_len};
19-
if (!c_at_e_fastly_log_write(endpoint, &msg_str, &err)) {
19+
if (!fastly_log_write(endpoint, &msg_str, &err)) {
2020
HANDLE_ERROR(cx, err);
2121
return false;
2222
}
@@ -37,7 +37,7 @@ JSObject *Logger::create(JSContext *cx, const char *name) {
3737
fastly_log_endpoint_handle_t handle;
3838
c_at_e_world_string_t name_str = {const_cast<char *>(name), strlen(name)};
3939
fastly_error_t err;
40-
if (!c_at_e_fastly_log_endpoint_get(&name_str, &handle, &err)) {
40+
if (!fastly_log_endpoint_get(&name_str, &handle, &err)) {
4141
HANDLE_ERROR(cx, err);
4242
return nullptr;
4343
}
@@ -58,7 +58,7 @@ bool Logger::constructor(JSContext *cx, unsigned argc, JS::Value *vp) {
5858
fastly_log_endpoint_handle_t handle = INVALID_HANDLE;
5959
fastly_error_t err;
6060

61-
if (!c_at_e_fastly_log_endpoint_get(&name_str, &handle, &err)) {
61+
if (!fastly_log_endpoint_get(&name_str, &handle, &err)) {
6262
HANDLE_ERROR(cx, err);
6363
return false;
6464
}

c-dependencies/js-compute-runtime/builtins/object-store.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ bool ObjectStore::get(JSContext *cx, unsigned argc, JS::Value *vp) {
197197

198198
fastly_option_body_handle_t ret;
199199
fastly_error_t err;
200-
if (!c_at_e_fastly_object_store_lookup(object_store_handle(self), &key_str, &ret, &err)) {
200+
if (!fastly_object_store_lookup(object_store_handle(self), &key_str, &ret, &err)) {
201201
HANDLE_ERROR(cx, err);
202202
return false;
203203
}
@@ -271,7 +271,7 @@ bool ObjectStore::put(JSContext *cx, unsigned argc, JS::Value *vp) {
271271
fastly_body_handle_t body = RequestOrResponse::body_handle(source_owner);
272272

273273
fastly_error_t err;
274-
if (!c_at_e_fastly_object_store_insert(object_store_handle(self), &key_str, body, &err)) {
274+
if (!fastly_object_store_insert(object_store_handle(self), &key_str, body, &err)) {
275275
HANDLE_ERROR(cx, err);
276276
return ReturnPromiseRejectedWithPendingError(cx, args);
277277
}
@@ -350,8 +350,7 @@ bool ObjectStore::put(JSContext *cx, unsigned argc, JS::Value *vp) {
350350
}
351351

352352
fastly_error_t err;
353-
if (!c_at_e_fastly_object_store_insert(object_store_handle(self), &key_str, body.handle,
354-
&err)) {
353+
if (!fastly_object_store_insert(object_store_handle(self), &key_str, body.handle, &err)) {
355354
// Ensure that we throw an exception for all unexpected host errors.
356355
HANDLE_ERROR(cx, err);
357356
return RejectPromiseWithPendingError(cx, result_promise);
@@ -418,7 +417,7 @@ bool ObjectStore::constructor(JSContext *cx, unsigned argc, JS::Value *vp) {
418417

419418
fastly_object_store_handle_t object_store_handle = INVALID_HANDLE;
420419
fastly_error_t err;
421-
if (!c_at_e_fastly_object_store_open(&name_str, &object_store_handle, &err)) {
420+
if (!fastly_object_store_open(&name_str, &object_store_handle, &err)) {
422421
if (err == FASTLY_ERROR_INVALID_ARGUMENT) {
423422
JS_ReportErrorNumberASCII(cx, GetErrorMessage, nullptr, JSMSG_OBJECT_STORE_DOES_NOT_EXIST,
424423
name_str.ptr);

0 commit comments

Comments
 (0)