new build system
This commit is contained in:
parent
277f38bbe8
commit
0f90d0f3d3
2
Cargo.lock
generated
2
Cargo.lock
generated
|
@ -38,7 +38,7 @@ dependencies = [
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "all-in-one"
|
name = "all_in_one"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"anyhow",
|
"anyhow",
|
||||||
|
|
|
@ -5,8 +5,9 @@ members = [
|
||||||
"exes/rest/",
|
"exes/rest/",
|
||||||
"exes/webhook/",
|
"exes/webhook/",
|
||||||
"exes/ratelimit/",
|
"exes/ratelimit/",
|
||||||
"exes/all-in-one/",
|
|
||||||
|
|
||||||
|
|
||||||
|
"libs/all_in_one/",
|
||||||
"libs/proto/",
|
"libs/proto/",
|
||||||
"libs/shared/",
|
"libs/shared/",
|
||||||
"libs/leash/"
|
"libs/leash/"
|
||||||
|
@ -27,7 +28,7 @@ anyhow = "1"
|
||||||
tracing = "0.1"
|
tracing = "0.1"
|
||||||
tracing-futures = "0.2"
|
tracing-futures = "0.2"
|
||||||
tracing-opentelemetry = "0.18"
|
tracing-opentelemetry = "0.18"
|
||||||
opentelemetry = "0.18"
|
opentelemetry = { version = "0.18", features = ["rt-tokio"] }
|
||||||
opentelemetry-http = "0.7"
|
opentelemetry-http = "0.7"
|
||||||
tikv-jemallocator = "0.5"
|
tikv-jemallocator = "0.5"
|
||||||
|
|
||||||
|
|
64
Makefile
64
Makefile
|
@ -1,37 +1,43 @@
|
||||||
# Build nova all-in-one bin
|
EXTENSION :=
|
||||||
all:
|
ifeq ($(OS),Windows_NT)
|
||||||
# Creates bin folder for artifacts
|
EXTENSION += .exe
|
||||||
@mkdir -p build/bin
|
endif
|
||||||
@mkdir -p build/lib
|
dir_guard=@mkdir -p $(@D)
|
||||||
|
PROJECTS = $(shell find exes/ -mindepth 1 -maxdepth 1 -type d -printf '%f\n')
|
||||||
@echo "Using cc, go, rust and ld versions"
|
BINS=$(PROJECTS:%=build/bin/%$(EXTENSION))
|
||||||
cc -v
|
|
||||||
go version
|
|
||||||
rustc --version
|
|
||||||
ld -v
|
|
||||||
|
|
||||||
# Builds rust
|
# Static libraries
|
||||||
@echo "Building rust project"
|
target/release/lib%.a:
|
||||||
cargo build --release
|
cargo build --release -p $*
|
||||||
@cp target/release/liball_in_one.a build/lib/
|
|
||||||
@cp target/release/cache build/bin/
|
|
||||||
@cp target/release/gateway build/bin/
|
|
||||||
@cp target/release/ratelimit build/bin/
|
|
||||||
@cp target/release/rest build/bin/
|
|
||||||
@cp target/release/webhook build/bin/
|
|
||||||
|
|
||||||
# Builds go
|
# Executables
|
||||||
|
target/release/%$(EXTENSION):
|
||||||
|
cargo build --release -p $*
|
||||||
|
|
||||||
|
# Copy static libraries
|
||||||
|
build/lib/%: target/release/%
|
||||||
|
$(dir_guard)
|
||||||
|
cp target/release/$* build/lib
|
||||||
|
|
||||||
|
# Copy executables
|
||||||
|
build/bin/%$(EXTENSION): target/release/%$(EXTENSION)
|
||||||
|
$(dir_guard)
|
||||||
|
cp target/release/$*$(EXTENSION) build/lib/
|
||||||
|
|
||||||
|
# All in one binary
|
||||||
|
build/bin/nova$(EXTENSION): build/lib/liball_in_one.a
|
||||||
|
$(dir_guard)
|
||||||
go build -a -ldflags '-s' -o build/bin/nova cmd/nova/nova.go
|
go build -a -ldflags '-s' -o build/bin/nova cmd/nova/nova.go
|
||||||
|
|
||||||
docker-images:
|
all: $(BINS) build/bin/nova$(EXTENSION)
|
||||||
docker-compose build
|
|
||||||
|
|
||||||
docker-push:
|
clean:
|
||||||
docker-compose push
|
rm -rf build
|
||||||
|
rm -rf $(PROJECTS:%=target/release/%$(EXTENSION))
|
||||||
|
rm -rf target/release/liball_in_one.a
|
||||||
|
|
||||||
rust-test:
|
test:
|
||||||
cargo test
|
cargo test
|
||||||
|
go test
|
||||||
|
|
||||||
test: rust-test
|
.PHONY: clean all test
|
||||||
|
|
||||||
.PHONY: all docker-images docker-push test rust-test
|
|
||||||
|
|
|
@ -1,19 +0,0 @@
|
||||||
use all_in_one::ffi::{create_instance, load_config, stop_instance};
|
|
||||||
use std::sync::mpsc::channel;
|
|
||||||
|
|
||||||
fn main() {
|
|
||||||
let c = load_config();
|
|
||||||
let comp = unsafe { create_instance(c) };
|
|
||||||
|
|
||||||
// wait for signal
|
|
||||||
let (tx, rx) = channel();
|
|
||||||
|
|
||||||
ctrlc::set_handler(move || tx.send(()).expect("Could not send signal on channel."))
|
|
||||||
.expect("Error setting Ctrl-C handler");
|
|
||||||
|
|
||||||
rx.recv().unwrap();
|
|
||||||
|
|
||||||
println!("Exiting.");
|
|
||||||
|
|
||||||
unsafe { stop_instance(comp) };
|
|
||||||
}
|
|
25
go.mod
25
go.mod
|
@ -4,30 +4,9 @@ go 1.16
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/Jeffail/gabs v1.4.0
|
github.com/Jeffail/gabs v1.4.0
|
||||||
github.com/Microsoft/go-winio v0.5.1 // indirect
|
|
||||||
github.com/ProtonMail/go-crypto v0.0.0-20210920160938-87db9fbc61c7 // indirect
|
|
||||||
github.com/alicebob/gopher-json v0.0.0-20200520072559-a9ecdc9d1d3a // indirect
|
|
||||||
github.com/alicebob/miniredis v2.5.0+incompatible
|
|
||||||
github.com/alicebob/miniredis/v2 v2.23.1
|
github.com/alicebob/miniredis/v2 v2.23.1
|
||||||
github.com/cespare/xxhash/v2 v2.1.2 // indirect
|
|
||||||
github.com/go-git/go-git/v5 v5.4.2
|
|
||||||
github.com/gomodule/redigo v1.8.9 // indirect
|
|
||||||
github.com/kevinburke/ssh_config v1.1.0 // indirect
|
|
||||||
github.com/mattn/go-runewidth v0.0.13 // indirect
|
|
||||||
github.com/nats-io/gnatsd v1.4.1 // indirect
|
|
||||||
github.com/nats-io/nats-server v1.4.1
|
|
||||||
github.com/nats-io/nats-server/v2 v2.9.10
|
github.com/nats-io/nats-server/v2 v2.9.10
|
||||||
github.com/nats-io/nats-streaming-server v0.25.2
|
|
||||||
github.com/nats-io/nuid v1.0.1 // indirect
|
|
||||||
github.com/olekukonko/tablewriter v0.0.5
|
|
||||||
github.com/prometheus/client_golang v1.11.0
|
|
||||||
github.com/prometheus/common v0.31.1 // indirect
|
|
||||||
github.com/rs/zerolog v1.25.0
|
|
||||||
github.com/sergi/go-diff v1.2.0 // indirect
|
|
||||||
github.com/spf13/cobra v1.2.1
|
|
||||||
github.com/xanzy/ssh-agent v0.3.1 // indirect
|
|
||||||
github.com/yuin/gopher-lua v1.0.0 // indirect
|
github.com/yuin/gopher-lua v1.0.0 // indirect
|
||||||
golang.org/x/text v0.3.7 // indirect
|
golang.org/x/crypto v0.0.0-20221010152910-d6f0a8c073c2 // indirect
|
||||||
google.golang.org/genproto v0.0.0-20211016002631-37fc39342514 // indirect
|
golang.org/x/sys v0.0.0-20221010170243-090e33056c14 // indirect
|
||||||
google.golang.org/grpc v1.41.0
|
|
||||||
)
|
)
|
||||||
|
|
24
internal/pkg/all-in-one/all_in_one.h
Normal file
24
internal/pkg/all-in-one/all_in_one.h
Normal file
|
@ -0,0 +1,24 @@
|
||||||
|
#include <stdarg.h>
|
||||||
|
#include <stdbool.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Represents a all in one instance
|
||||||
|
*/
|
||||||
|
typedef struct AllInOneInstance AllInOneInstance;
|
||||||
|
|
||||||
|
void set_error_handler(void (*func)(int, char*));
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Loads the config json using the nova shared config loader
|
||||||
|
*/
|
||||||
|
char *load_config(void);
|
||||||
|
|
||||||
|
void stop_instance(struct AllInOneInstance *instance);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* # Panics
|
||||||
|
* Panics if an incorrect `RUST_LOG` variables is specified.
|
||||||
|
*/
|
||||||
|
struct AllInOneInstance *create_instance(char *config);
|
|
@ -1,5 +1,5 @@
|
||||||
[package]
|
[package]
|
||||||
name = "all-in-one"
|
name = "all_in_one"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
|
||||||
|
@ -10,11 +10,11 @@ libc = "0.2.139"
|
||||||
leash = { path = "../../libs/leash" }
|
leash = { path = "../../libs/leash" }
|
||||||
shared = { path = "../../libs/shared" }
|
shared = { path = "../../libs/shared" }
|
||||||
|
|
||||||
cache = { path = "../cache" }
|
cache = { path = "../../exes/cache" }
|
||||||
gateway = { path = "../gateway" }
|
gateway = { path = "../../exes/gateway" }
|
||||||
ratelimit = { path = "../ratelimit" }
|
ratelimit = { path = "../../exes/ratelimit" }
|
||||||
rest = { path = "../rest" }
|
rest = { path = "../../exes/rest" }
|
||||||
webhook = { path = "../webhook" }
|
webhook = { path = "../../exes/webhook" }
|
||||||
ctrlc = "3.2.4"
|
ctrlc = "3.2.4"
|
||||||
|
|
||||||
tokio = { version = "1.23.1", features = ["rt"] }
|
tokio = { version = "1.23.1", features = ["rt"] }
|
|
@ -9,7 +9,6 @@ use tracing::trace_span;
|
||||||
use twilight_model::gateway::event::{DispatchEvent, DispatchEventWithTypeDeserializer};
|
use twilight_model::gateway::event::{DispatchEvent, DispatchEventWithTypeDeserializer};
|
||||||
|
|
||||||
#[derive(Debug, Clone, PartialEq)]
|
#[derive(Debug, Clone, PartialEq)]
|
||||||
#[repr(transparent)]
|
|
||||||
pub struct DispatchEventTagged(pub DispatchEvent);
|
pub struct DispatchEventTagged(pub DispatchEvent);
|
||||||
|
|
||||||
impl Deref for DispatchEventTagged {
|
impl Deref for DispatchEventTagged {
|
||||||
|
@ -76,12 +75,11 @@ mod tests {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn serialize_event_tagged() {
|
fn serialize_event_tagged() {
|
||||||
let dispatch_event = DispatchEvent::GiftCodeUpdate;
|
let dispatch_event = DispatchEventTagged(DispatchEvent::GiftCodeUpdate);
|
||||||
|
|
||||||
let value = serde_json::to_value(&dispatch_event);
|
let value = serde_json::to_value(&dispatch_event);
|
||||||
assert!(value.is_ok());
|
assert!(value.is_ok());
|
||||||
let value = value.unwrap();
|
let value = value.unwrap();
|
||||||
|
|
||||||
let kind = value.get("t").and_then(serde_json::Value::as_str);
|
let kind = value.get("t").and_then(serde_json::Value::as_str);
|
||||||
assert_eq!(kind, Some("GIFT_CODE_UPDATE"));
|
assert_eq!(kind, Some("GIFT_CODE_UPDATE"));
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue