Skip to content

Commit

Permalink
Merge pull request #56 from kroma-network/fix/fix-duplicated-linking-…
Browse files Browse the repository at this point in the history
…error

fix(node): fix an error caused by duplicated libraries
  • Loading branch information
chokobole authored Sep 21, 2023
2 parents d93c72c + e1c744d commit b417724
Show file tree
Hide file tree
Showing 9 changed files with 31 additions and 75 deletions.
24 changes: 2 additions & 22 deletions tachyon/node/base/test/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -24,32 +24,12 @@ tachyon_cc_library(
)

tachyon_node_library(
name = "class",
name = "test",
testonly = True,
srcs = ["class.cc"],
srcs = ["test.cc"],
deps = [
":color",
":point",
"//tachyon/node/base:node_base",
],
)

tachyon_node_library(
name = "enum",
testonly = True,
srcs = ["enum.cc"],
deps = [
":color",
"//tachyon/node/base:node_base",
],
)

tachyon_node_library(
name = "function",
testonly = True,
srcs = ["function.cc"],
deps = [
"//tachyon/base/binding/test:functions",
"//tachyon/node/base:node_base",
],
)
4 changes: 0 additions & 4 deletions tachyon/node/base/test/color.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,6 @@

void AddColor(tachyon::node::NodeModule& m) {
using namespace tachyon::base::test;
m.NewEnum<Color>("color")
.AddValue("red", Color::kRed)
.AddValue("green", Color::kGreen)
.AddValue("blue", Color::kBlue);
}

#endif // defined(TACHYON_NODE_BINDING)
13 changes: 0 additions & 13 deletions tachyon/node/base/test/enum.cc

This file was deleted.

17 changes: 0 additions & 17 deletions tachyon/node/base/test/function.cc

This file was deleted.

33 changes: 22 additions & 11 deletions tachyon/node/base/test/class.cc → tachyon/node/base/test/test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@

#include "tachyon/base/binding/test/adder.h"
#include "tachyon/base/binding/test/colored_point.h"
#include "tachyon/base/binding/test/functions.h"
#include "tachyon/base/binding/test/rect.h"
#include "tachyon/base/binding/test/variant.h"
#include "tachyon/node/base/node_module.h"
#include "tachyon/node/base/test/color.h"
#include "tachyon/node/base/test/point.h"

Expand All @@ -12,22 +14,31 @@ void AcceptColoredPoint(tachyon::base::test::ColoredPoint& cp) {}
Napi::Object Init(Napi::Env env, Napi::Object exports) {
using namespace tachyon::base::test;

tachyon::node::NodeModule module(env, exports);
AddColor(module);
tachyon::node::NodeModule m(env, exports);

m.AddFunction("hello", &Hello)
.AddFunction("sum", &Sum, 1, 2)
.AddFunction("do_nothing", &DoNothing);

m.NewEnum<Color>("color")
.AddValue("red", Color::kRed)
.AddValue("green", Color::kGreen)
.AddValue("blue", Color::kBlue);

// TODO(chokobole): I tried testing all these variation either in same addon
// or different addon. But it somehow corrupts this addon. So I need to figure
// out how to gracefully test! Uncomment either one of AddXXXPoint.
AddPoint(module);
AddPoint(m);
// This enable 'shared_ptr' test in 'class.spec.ts'.
// AddSharedPoint(module);
// AddSharedPoint(m);
// This enable 'unique_ptr' test in 'class.spec.ts'.
// AddUniquePoint(module);
// AddUniquePoint(m);

module.NewClass<ColoredPoint, Point>("ColoredPoint")
m.NewClass<ColoredPoint, Point>("ColoredPoint")
.AddConstructor<>()
.AddConstructor<int, int, Color>();

module.NewClass<Rect>("Rect")
m.NewClass<Rect>("Rect")
.AddConstructor<>()
.AddConstructor<const Point&, const Point&>()
.AddReadWrite("topLeft", &Rect::top_left)
Expand All @@ -37,12 +48,12 @@ Napi::Object Init(Napi::Env env, Napi::Object exports) {
.AddMethod("getBottomRight", &Rect::GetBottomRight)
.AddMethod("getConstBottomRight", &Rect::GetConstBottomRight);

module.NewClass<Adder>("Adder")
m.NewClass<Adder>("Adder")
.AddConstructor<>()
.AddMethod("add", &Adder::Add, 1, 2, 3, 4)
.AddStaticMethod("sAdd", &Adder::SAdd, 1, 2, 3, 4);

module.NewClass<Variant>("Variant")
m.NewClass<Variant>("Variant")
.AddConstructor<bool>()
.AddConstructor<int>()
.AddConstructor<int64_t>()
Expand All @@ -57,14 +68,14 @@ Napi::Object Init(Napi::Env env, Napi::Object exports) {
.AddReadWrite("ivec", &Variant::ivec)
.AddReadWrite("p", &Variant::p);

module.AddFunction("doubleWithValue", &DoubleWithValue)
m.AddFunction("doubleWithValue", &DoubleWithValue)
.AddFunction("doubleWithReference", &DoubleWithReference)
.AddFunction("doubleWithSharedPtr", &DoubleWithSharedPtr)
.AddFunction("doubleWithUniquePtr", &DoubleWithUniquePtr)
.AddFunction("acceptColoredPoint", &AcceptColoredPoint);
return exports;
}

NODE_API_MODULE(class, Init)
NODE_API_MODULE(test, Init)

#endif // defined(TACHYON_NODE_BINDING)
6 changes: 1 addition & 5 deletions tachyon/node/test/src/base/test/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,7 @@ tachyon_ts_project(
"enum.spec.ts",
"function.spec.ts",
],
data = [
"@kroma_network_tachyon//tachyon/node/base/test:class",
"@kroma_network_tachyon//tachyon/node/base/test:enum",
"@kroma_network_tachyon//tachyon/node/base/test:function",
],
data = ["@kroma_network_tachyon//tachyon/node/base/test"],
)

tachyon_jest_test(
Expand Down
3 changes: 2 additions & 1 deletion tachyon/node/test/src/base/test/class.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { describe, expect, test } from '@jest/globals';

const class_test = require('../../../external/kroma_network_tachyon/tachyon/node/base/test/class.node');
const class_test = require(
'../../../external/kroma_network_tachyon/tachyon/node/base/test/test.node');

const callNonConstMethod = TypeError('Call non-const method');
const noSuchConstructor = TypeError('No such constructor');
Expand Down
3 changes: 2 additions & 1 deletion tachyon/node/test/src/base/test/enum.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { describe, expect, test } from '@jest/globals';

const enum_test = require('../../../external/kroma_network_tachyon/tachyon/node/base/test/enum.node');
const enum_test = require(
'../../../external/kroma_network_tachyon/tachyon/node/base/test/test.node');

describe('enum', () => {
test('enum values', () => {
Expand Down
3 changes: 2 additions & 1 deletion tachyon/node/test/src/base/test/function.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { describe, expect, test } from '@jest/globals';

const functionTest = require('../../../external/kroma_network_tachyon/tachyon/node/base/test/function.node');
const functionTest = require(
'../../../external/kroma_network_tachyon/tachyon/node/base/test/test.node');

const wrongNumberOfArguments = TypeError('Wrong number of arguments');

Expand Down

0 comments on commit b417724

Please sign in to comment.