new build system

This commit is contained in:
MatthieuCoder 2023-01-16 15:43:10 +04:00
parent 277f38bbe8
commit 0f90d0f3d3
14 changed files with 72 additions and 1010 deletions

2
Cargo.lock generated
View file

@ -38,7 +38,7 @@ dependencies = [
]
[[package]]
name = "all-in-one"
name = "all_in_one"
version = "0.1.0"
dependencies = [
"anyhow",

View file

@ -5,8 +5,9 @@ members = [
"exes/rest/",
"exes/webhook/",
"exes/ratelimit/",
"exes/all-in-one/",
"libs/all_in_one/",
"libs/proto/",
"libs/shared/",
"libs/leash/"
@ -27,7 +28,7 @@ anyhow = "1"
tracing = "0.1"
tracing-futures = "0.2"
tracing-opentelemetry = "0.18"
opentelemetry = "0.18"
opentelemetry = { version = "0.18", features = ["rt-tokio"] }
opentelemetry-http = "0.7"
tikv-jemallocator = "0.5"

View file

@ -1,37 +1,43 @@
# Build nova all-in-one bin
all:
# Creates bin folder for artifacts
@mkdir -p build/bin
@mkdir -p build/lib
@echo "Using cc, go, rust and ld versions"
cc -v
go version
rustc --version
ld -v
EXTENSION :=
ifeq ($(OS),Windows_NT)
EXTENSION += .exe
endif
dir_guard=@mkdir -p $(@D)
PROJECTS = $(shell find exes/ -mindepth 1 -maxdepth 1 -type d -printf '%f\n')
BINS=$(PROJECTS:%=build/bin/%$(EXTENSION))
# Builds rust
@echo "Building rust project"
cargo build --release
@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/
# Static libraries
target/release/lib%.a:
cargo build --release -p $*
# 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
docker-images:
docker-compose build
all: $(BINS) build/bin/nova$(EXTENSION)
docker-push:
docker-compose push
clean:
rm -rf build
rm -rf $(PROJECTS:%=target/release/%$(EXTENSION))
rm -rf target/release/liball_in_one.a
rust-test:
test:
cargo test
go test
test: rust-test
.PHONY: all docker-images docker-push test rust-test
.PHONY: clean all test

View file

@ -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
View file

@ -4,30 +4,9 @@ go 1.16
require (
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/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-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
golang.org/x/text v0.3.7 // indirect
google.golang.org/genproto v0.0.0-20211016002631-37fc39342514 // indirect
google.golang.org/grpc v1.41.0
golang.org/x/crypto v0.0.0-20221010152910-d6f0a8c073c2 // indirect
golang.org/x/sys v0.0.0-20221010170243-090e33056c14 // indirect
)

927
go.sum

File diff suppressed because it is too large Load diff

View 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);

View file

@ -1,5 +1,5 @@
[package]
name = "all-in-one"
name = "all_in_one"
version = "0.1.0"
edition = "2021"
@ -10,11 +10,11 @@ libc = "0.2.139"
leash = { path = "../../libs/leash" }
shared = { path = "../../libs/shared" }
cache = { path = "../cache" }
gateway = { path = "../gateway" }
ratelimit = { path = "../ratelimit" }
rest = { path = "../rest" }
webhook = { path = "../webhook" }
cache = { path = "../../exes/cache" }
gateway = { path = "../../exes/gateway" }
ratelimit = { path = "../../exes/ratelimit" }
rest = { path = "../../exes/rest" }
webhook = { path = "../../exes/webhook" }
ctrlc = "3.2.4"
tokio = { version = "1.23.1", features = ["rt"] }

View file

@ -9,7 +9,6 @@ use tracing::trace_span;
use twilight_model::gateway::event::{DispatchEvent, DispatchEventWithTypeDeserializer};
#[derive(Debug, Clone, PartialEq)]
#[repr(transparent)]
pub struct DispatchEventTagged(pub DispatchEvent);
impl Deref for DispatchEventTagged {
@ -76,12 +75,11 @@ mod tests {
#[test]
fn serialize_event_tagged() {
let dispatch_event = DispatchEvent::GiftCodeUpdate;
let dispatch_event = DispatchEventTagged(DispatchEvent::GiftCodeUpdate);
let value = serde_json::to_value(&dispatch_event);
assert!(value.is_ok());
let value = value.unwrap();
let kind = value.get("t").and_then(serde_json::Value::as_str);
assert_eq!(kind, Some("GIFT_CODE_UPDATE"));
}