Skip to content

Commit 3b97363

Browse files
authored
chore: Add fmtlib (#659)
1 parent 76a647c commit 3b97363

File tree

5 files changed

+23
-14
lines changed

5 files changed

+23
-14
lines changed

.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,6 @@
55
[submodule "runtime/spidermonkey/gecko-dev"]
66
path = runtime/spidermonkey/gecko-dev
77
url = https://github.com/bytecodealliance/gecko-dev.git
8+
[submodule "runtime/js-compute-runtime/third_party/fmt"]
9+
path = runtime/js-compute-runtime/third_party/fmt
10+
url = https://github.com/fmtlib/fmt

runtime/js-compute-runtime/Makefile

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ CFLAGS += --sysroot=$(WASI_SDK)/share/wasi-sysroot
107107

108108
# Includes for compiling c++
109109
INCLUDES := -I$(FSM_SRC)
110+
INCLUDES += -I$(FSM_SRC)/third_party/fmt/include
110111
INCLUDES += -I$(SM_SRC)/include
111112
INCLUDES += -I$(BUILD)/openssl/include
112113

@@ -169,6 +170,9 @@ $(OBJ_DIR)/host_interface:
169170
$(OBJ_DIR)/host_interface/component:
170171
$(call cmd,mkdir,$@)
171172

173+
$(OBJ_DIR)/third_party/fmt/src:
174+
$(call cmd,mkdir,$@)
175+
172176
shared:
173177
$(call cmd,mkdir,$@)
174178

@@ -291,7 +295,9 @@ FSM_CPP += $(wildcard $(FSM_SRC)/builtins/*.cpp)
291295
FSM_CPP += $(wildcard $(FSM_SRC)/builtins/shared/*.cpp)
292296
FSM_CPP += $(wildcard $(FSM_SRC)/core/*.cpp)
293297
FSM_CPP += $(wildcard $(FSM_SRC)/host_interface/*.cpp)
294-
FSM_OBJ := $(patsubst $(FSM_SRC)/%.cpp,$(OBJ_DIR)/%.o,$(FSM_CPP))
298+
FSM_CPP += $(FSM_SRC)/third_party/fmt/src/format.cc
299+
FSM_OBJ := $(call build_dest,$(call change_cxx_extension,$(FSM_CPP),o))
300+
295301

296302
# Build all the above object files
297303
$(foreach source,$(FSM_CPP),$(eval $(call compile_cxx,$(source))))

runtime/js-compute-runtime/builtins/crypto-algorithm.cpp

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#include "openssl/rsa.h"
22
#include "openssl/sha.h"
3+
#include <fmt/format.h>
34
#include <iostream>
45
#include <optional>
56
#include <span>
@@ -1325,29 +1326,23 @@ JSObject *CryptoAlgorithmECDSA_Import::importKey(JSContext *cx, CryptoKeyFormat
13251326
switch (this->namedCurve) {
13261327
case NamedCurve::P256: {
13271328
if (d.length() != 32) {
1328-
std::string message = "The JWK's \"d\" member defines an octet string of length ";
1329-
message += std::to_string(d.length());
1330-
message += " bytes but should be 32";
1329+
auto message = fmt::format("The JWK's \"d\" member defines an octet string of length {} bytes but should be 32", d.length());
13311330
DOMException::raise(cx, message, "SyntaxError");
13321331
return nullptr;
13331332
}
13341333
break;
13351334
}
13361335
case NamedCurve::P384: {
13371336
if (d.length() != 48) {
1338-
std::string message = "The JWK's \"d\" member defines an octet string of length ";
1339-
message += std::to_string(d.length());
1340-
message += " bytes but should be 48";
1337+
auto message = fmt::format("The JWK's \"d\" member defines an octet string of length {} bytes but should be 48", d.length());
13411338
DOMException::raise(cx, message, "SyntaxError");
13421339
return nullptr;
13431340
}
13441341
break;
13451342
}
13461343
case NamedCurve::P521: {
13471344
if (d.length() != 66) {
1348-
std::string message = "The JWK's \"d\" member defines an octet string of length ";
1349-
message += std::to_string(d.length());
1350-
message += " bytes but should be 66";
1345+
auto message = fmt::format("The JWK's \"d\" member defines an octet string of length {} bytes but should be 66", d.length());
13511346
DOMException::raise(cx, message, "SyntaxError");
13521347
return nullptr;
13531348
}

runtime/js-compute-runtime/mk/commands.mk

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,30 +44,34 @@ cmd_wasi_ar = $(WASI_AR) rcs $@ $1
4444
cmd_wasi_cxx_name := WASI_CXX
4545
cmd_wasi_cxx = $(WASI_CXX) $(CXX_FLAGS) $(OPT_FLAGS) $(INCLUDES) $(DEFINES) -MMD -MP -c -o $1 $<
4646

47+
change_cxx_extension = $(patsubst %.cc,%.$2,$(1:.cpp=.$2))
48+
49+
build_dest = $(patsubst $(FSM_SRC)/%,$(OBJ_DIR)/%,$1)
50+
4751
# Compile a single c++ source and lazily include the dependency file.
48-
compile_cxx = $(call compile_cxx_impl,$1,$(patsubst $(FSM_SRC)/%.cpp,$(OBJ_DIR)/%.o,$1))
52+
compile_cxx = $(call compile_cxx_impl,$1,$(call build_dest,$(patsubst %.cc,%.o,$(1:.cpp=.o))))
4953

5054
define compile_cxx_impl
5155

5256
# We use shell to get the dirname of the target here, as the builtin `dir` rule
5357
$2: $1 $(BUILD)/openssl/token | $(shell dirname "$2")
5458
$$(call cmd,wasi_cxx,$$@)
5559

56-
-include $(patsubst $(FSM_SRC)/%.cpp,$(OBJ_DIR)/%.d,$1)
60+
-include $(2:.o=.d)
5761

5862
endef
5963

6064
cmd_wasi_cc_name := WASI_CC
6165
cmd_wasi_cc = $(WASI_CC) $(CFLAGS) $(OPT_FLAGS) $(DEFINES) -MMD -MP -c -o $1 $<
6266

6367
# Compile a single c source and lazily include the dependency file.
64-
compile_c = $(call compile_c_impl,$1,$(patsubst $(FSM_SRC)/%.c,$(OBJ_DIR)/%.o,$1))
68+
compile_c = $(call compile_c_impl,$1,$(call build_dest,$(1:.c=.o)))
6569

6670
define compile_c_impl
6771

6872
$2: $1 | $(shell dirname "$2")
6973
$$(call cmd,wasi_cc,$$@)
7074

71-
-include $(patsubst $(FSM_SRC)/%.c,$(OBJ_DIR)/%.d,$1)
75+
-include $(2:.o=.d)
7276

7377
endef
Submodule fmt added at f5e5435

0 commit comments

Comments
 (0)