Skip to content

Commit

Permalink
added app skeleton
Browse files Browse the repository at this point in the history
  • Loading branch information
Elzor committed Oct 15, 2018
0 parents commit 4a9620c
Show file tree
Hide file tree
Showing 23 changed files with 682 additions and 0 deletions.
10 changes: 10 additions & 0 deletions .gitignore
@@ -0,0 +1,10 @@
.eunit
*.o
*.beam
*.plt
erl_crash.dump
ebin/*.beam
.concrete/DEV_MODE
.rebar
_build
.idea
49 changes: 49 additions & 0 deletions Makefile
@@ -0,0 +1,49 @@
DOCKER = $(shell which docker)
ifeq ($(DOCKER),)
$(error "Docker not available on this system")
endif

DOCKER_COMPOSE = $(shell which docker-compose)
ifeq ($(DOCKER_COMPOSE),)
$(error "DockerCompose not available on this system")
endif

# use to override vars for your platform
ifeq (env.mk,$(wildcard env.mk))
include env.mk
endif

all: build_imgs up tests rel

build_imgs:
@echo "Update docker images..."
@${DOCKER_COMPOSE} build

up:
@${DOCKER_COMPOSE} up -d

down:
@${DOCKER_COMPOSE} down

tests:
@echo "Testing..."
@${DOCKER_COMPOSE} exec test bash -c "cd /project && make -f sandbox.mk tests"

rel:
@echo "Build release..."
@${DOCKER_COMPOSE} exec test bash -c "cd /project && make -f sandbox.mk prod"

lint:
@echo "Lint..."
@${DOCKER_COMPOSE} exec test bash -c "cd /project && make -f sandbox.mk lint"

xref:
@echo "Xref analysis..."
@${DOCKER_COMPOSE} exec test bash -c "cd /project && make -f sandbox.mk xref"

dialyzer:
@echo "Dialyzer..."
@${DOCKER_COMPOSE} exec test bash -c "cd /project && make -f sandbox.mk dialyzer"

upgrade_rebar:
@${DOCKER_COMPOSE} exec test bash -c "cd /project && make -f sandbox.mk upgrade_rebar"
14 changes: 14 additions & 0 deletions README.md
@@ -0,0 +1,14 @@
# eapa
Erlang Arbitrary Precision Arithmetics

**release:**
`rebar3 as prod release`

**test:**
`rebar3 as test ct`

In Docker enviroment:
* `make tests` - run tests
* `make lint` - linter
* `make xref` - xref analysis
* `make prod` - generate release for target
1 change: 1 addition & 0 deletions config/sys.config
@@ -0,0 +1 @@
[].
15 changes: 15 additions & 0 deletions config/vm.args
@@ -0,0 +1,15 @@
## Name of the node
-name eapa@127.0.0.1

## Cookie for distributed erlang
-setcookie dev

## Enable kernel poll and a few async threads
##+K true
##+A 5

## Increase number of concurrent ports/sockets
##-env ERL_MAX_PORTS 4096

## Tweak GC to run more often
##-env ERL_FULLSWEEP_AFTER 10
2 changes: 2 additions & 0 deletions crates/eapa/.gitignore
@@ -0,0 +1,2 @@
target/*
.idea/*
84 changes: 84 additions & 0 deletions crates/eapa/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions crates/eapa/Cargo.toml
@@ -0,0 +1,15 @@
[package]
name = "eapa"
version = "0.1.0"
authors = ["Maxim Molchanov <m.molchanov@vonmo.com>"]
license = "MIT/GPL"

[lib]
name = "eapa"
crate-type = ["dylib"]

[dependencies]
erlang_nif-sys = "=0.6.4"
lazy_static = "=1.1.*"
rustler = "=0.18.0"
rug = "=1.2.1"
31 changes: 31 additions & 0 deletions crates/eapa/src/lib.rs
@@ -0,0 +1,31 @@
#[macro_use]
extern crate lazy_static;
#[macro_use]
extern crate rustler;

use rustler::{Encoder, Env, NifResult, Term};
use rustler::resource::ResourceArc;
use std::sync::RwLock;

mod atoms {
rustler_atoms! {
atom ok;
atom vn1;
}
}

rustler_export_nifs!(
"eapa",
[
("lxcode", 0, lxcode), // library version code
],
Some(on_load)
);

fn on_load<'a>(env: Env<'a>, _load_info: Term<'a>) -> bool {
true
}

fn lxcode<'a>(env: Env<'a>, _args: &[Term<'a>]) -> NifResult<Term<'a>> {
Ok((atoms::ok(), atoms::vn1()).encode(env))
}
15 changes: 15 additions & 0 deletions docker-compose.yml
@@ -0,0 +1,15 @@
version: '3.2'
services:

base:
build: imgs/base

test:
image: eapa_base:latest
depends_on:
- base
volumes:
- "./:/project:Z"
tmpfs:
- /run
- /tmp
38 changes: 38 additions & 0 deletions imgs/base/Dockerfile
@@ -0,0 +1,38 @@
FROM elzor/erlang:20.3 AS erlang
FROM rust:1.28 AS rust

FROM debian:9.4

COPY --from=erlang /erl /erl
ENV PATH=/erl/bin:$PATH

COPY --from=rust /usr/local/rustup /usr/local/rustup
COPY --from=rust /usr/local/cargo /usr/local/cargo

ENV RUSTUP_HOME=/usr/local/rustup \
CARGO_HOME=/usr/local/cargo \
PATH=/usr/local/cargo/bin:$PATH

RUN apt-get update \
&& apt-get install --no-install-recommends -y \
apt-transport-https \
wget \
curl \
build-essential \
git \
openssl \
libssl-dev \
libncurses5 \
libncurses5-dev \
xsltproc \
automake \
autoconf \
clang \
libclang-dev \
procps \
ca-certificates \
&& apt-get clean

ADD ./docker-entry.sh /docker-entry.sh

CMD ["/docker-entry.sh"]
7 changes: 7 additions & 0 deletions imgs/base/docker-entry.sh
@@ -0,0 +1,7 @@
#!/bin/sh
set -e

a=0
until [ ! $a -lt 10 ]; do
sleep 1
done
1 change: 1 addition & 0 deletions priv/.gitignore
@@ -0,0 +1 @@
*.so

0 comments on commit 4a9620c

Please sign in to comment.