implement support for multiarch
This commit is contained in:
parent
d88a1c9490
commit
1d332880ff
|
@ -1,4 +1,5 @@
|
|||
*.o
|
||||
*.zo
|
||||
/crossfire-agent
|
||||
/vendor/
|
||||
/cache/
|
||||
/arch_*
|
||||
|
|
|
@ -22,20 +22,26 @@ RKT_NAME=$(APP_NAME).rkt
|
|||
|
||||
MONOCYPHER_VERSION=3.1.1
|
||||
|
||||
TARGET_ARCH=$(shell $(CC) -dumpmachine)
|
||||
|
||||
####################################################################################################
|
||||
|
||||
LIBS=-ldl -lm
|
||||
# for musl
|
||||
#LIBS=-lffi -lucontext
|
||||
|
||||
VENDOR_DIR=vendor
|
||||
ARCH_DIR=arch_$(TARGET_ARCH)
|
||||
CACHE_DIR=cache
|
||||
VENDOR_DIR=$(ARCH_DIR)/vendor
|
||||
MONOCYPHER_DIR=$(VENDOR_DIR)/monocypher-$(MONOCYPHER_VERSION)
|
||||
MONOCYPHER_URL=https://monocypher.org/download/monocypher-$(MONOCYPHER_VERSION).tar.gz
|
||||
MONOCYPHER_FILE=$(CACHE_DIR)/monocypher.tar.gz
|
||||
|
||||
all: $(APP_NAME)
|
||||
all: $(ARCH_DIR)/$(APP_NAME)
|
||||
|
||||
# main build
|
||||
$(APP_NAME): main_bc.c app.o $(MONOCYPHER_DIR)/lib/libmonocypher.a
|
||||
$(ARCH_DIR)/$(APP_NAME): main_bc.c app.o $(MONOCYPHER_DIR)/lib/libmonocypher.a
|
||||
[ -d $(ARCH_DIR) ] || mkdir -p $(ARCH_DIR)
|
||||
$(CC) -o $@ -pipe -fPIC -O3 -DAPP_NAME='"$(APP_NAME)"' -I$(MONOCYPHER_DIR)/src -static $^ \
|
||||
-L$(MONOCYPHER_DIR)/lib \
|
||||
-lracket3m -lrktio -lmonocypher $(LIBS)
|
||||
|
@ -43,14 +49,16 @@ $(APP_NAME): main_bc.c app.o $(MONOCYPHER_DIR)/lib/libmonocypher.a
|
|||
$(MONOCYPHER_DIR)/lib/libmonocypher.a: $(MONOCYPHER_DIR)/.extracted
|
||||
cd $(MONOCYPHER_DIR) && $(MAKE) USE_ED22519=true static-library
|
||||
|
||||
$(MONOCYPHER_DIR)/.extracted: $(MONOCYPHER_DIR).tar.gz
|
||||
$(MONOCYPHER_DIR)/.extracted: $(MONOCYPHER_FILE)
|
||||
[ -d $(MONOCYPHER_DIR) ] || mkdir -p $(MONOCYPHER_DIR)
|
||||
tar xf $< -C $(VENDOR_DIR) && touch $@
|
||||
|
||||
$(MONOCYPHER_DIR).tar.gz:
|
||||
$(MONOCYPHER_FILE):
|
||||
[ -d $(CACHE_DIR) ] || mkdir -p $(CACHE_DIR)
|
||||
wget -O $@ $(MONOCYPHER_URL) || curl -o $@ $(MONOCYPHER_URL)
|
||||
|
||||
# this is faster than --c-mods by a lot
|
||||
# it's less portable but like, we're containerized already so it'll work
|
||||
# it's potentially less portable but works on GNU ld and probably lld too
|
||||
app.o: app.zo
|
||||
$(LD) -r -b binary $< -o $@
|
||||
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
-- @revision: e50ab485d8590ead53c2518396c04f81
|
||||
-- @description: Creates some initial core tables for crossfire.
|
||||
-- @up {
|
||||
create table node(id integer primary key, name text not null,
|
||||
create table node(id integer primary key, name text not null, arch text not null,
|
||||
type text check(type in ("client", "agent")) not null,
|
||||
secret blob(32) not null)
|
||||
-- }
|
||||
|
|
|
@ -58,10 +58,10 @@
|
|||
(define-syntax-rule (define-stmt name what)
|
||||
(define name (virtual-statement what)))
|
||||
|
||||
(define-stmt q-new-node "insert into node (name, type, secret) values (?, ?, ?)")
|
||||
(define-stmt q-new-node "insert into node (name, arch, type, secret) values (?, ?, ?, ?)")
|
||||
(define-stmt q-add-node-res "insert or ignore into node_resource (nodeid, resource) values (?, ?)")
|
||||
(define-stmt q-del-node-res "delete from node_resource where nodeid=? and resource=?")
|
||||
(define-stmt q-get-nodes "select id, name from node where type=?")
|
||||
(define-stmt q-get-nodes "select id, name, arch from node where type=?")
|
||||
(define-stmt q-get-all-resources
|
||||
"select nodeid, resource from node_resource inner join node on node.id = node_resource.nodeid
|
||||
where node.type = ?")
|
||||
|
@ -73,21 +73,22 @@
|
|||
|
||||
(define-rpc-type server)
|
||||
|
||||
(struct node-info [id name resources online?] #:transparent)
|
||||
(struct node-info [id name arch type resources online?] #:transparent)
|
||||
|
||||
(define (get-nodes type)
|
||||
(define type-str (symbol->string type))
|
||||
(define resources (rows->dict #:key "nodeid" #:value "resource" #:value-mode '(list)
|
||||
(query (current-db) q-get-all-resources type-str)))
|
||||
(for/list ([(id name) (in-query (current-db) q-get-nodes type-str)])
|
||||
(for/list ([(id name arch) (in-query (current-db) q-get-nodes type-str)])
|
||||
(define online? (and (current-comms) (comms-channel-available? (current-comms) id)))
|
||||
(node-info id name (hash-ref resources id) online?)))
|
||||
(node-info id name arch type (hash-ref resources id) online?)))
|
||||
|
||||
(define (make-agent name resources)
|
||||
(define (make-node name arch type resources)
|
||||
(call-with-transaction (current-db) (lambda ()
|
||||
(define secret (crypto-sign-make-key))
|
||||
(define public (crypto-sign-public-key secret))
|
||||
(define info (simple-result-info (query (current-db) q-new-node name "agent" secret)))
|
||||
(define info
|
||||
(simple-result-info (query (current-db) q-new-node name arch (symbol->string type) secret)))
|
||||
(define id (cdr (assoc 'insert-id info)))
|
||||
(for ([res (in-list resources)])
|
||||
(query-exec (current-db) q-add-node-res id res))
|
||||
|
@ -109,9 +110,9 @@
|
|||
(enforce-subject 'client)
|
||||
(get-nodes 'agent))
|
||||
|
||||
(define-rpc server (new-agent name resources)
|
||||
(define-rpc server (new-agent name arch resources)
|
||||
(enforce-subject 'client)
|
||||
(define-values [id public] (make-agent name resources))
|
||||
(define-values [id public] (make-node name arch 'agent resources))
|
||||
(define comms-node (node id name 'agent public #f #f #f))
|
||||
(comms-set-node-info (current-comms) comms-node)
|
||||
id)
|
||||
|
@ -146,7 +147,7 @@
|
|||
(require racket/cmdline)
|
||||
(current-db (open-server-db 'create))
|
||||
(migrate-server-db)
|
||||
;;(make-agent "agent0" '("gpu" "hifive"))
|
||||
(make-node "agent0" "x86_64" 'agent '("gpu" "hifive"))
|
||||
(parameterize ([current-from-node (node 100 "meow" 'client #f #f #f #f)])
|
||||
((rpc-impl server edit-agent) 1 "meow0" '("cpu" "hifive")))
|
||||
(get-nodes 'agent)
|
||||
|
|
Loading…
Reference in New Issue