You are visiting the site as a unregistered user. You can earn points and a new level by registering. Register free for ever!
logo Televistar Communities

Profile Picture
  • Name: One Person Email Verified
  • Public Username: Chess player
  • Bio: https://lichess.org/@/Quantium
  • Contact Me
Dlang + ARM

Time To Read: 3 minutes or less

I think you are very surprised by the name of this blog. Yes, you can write programms on Dlang and start them on ARM.
Let's see ARM structure:
.
├── arm-lib/
| ├── libcrypto.a
| ├── libssl.a
| └── libz.a
├── docker-ctx/
| ├── Dockerfile
| └── entry.sh
├── source
| └── app.d
├── .gitignore
├── build-docker
├── ddb
├── dub.sdl
├── ldc
└── makefile
File meanings
arm-lib - the most important ARM libs
docker-ctx - Docker-building container
entry.sh - Starts Docker Container
build-docker - To compile Docker
ddb - Docker D Builder ( script of starting container)
ldc - ldc parameters
makefile - compilation recipes
Compiling algorythm
1. ddb starts entry.sh
2. entry.sh pushes settings to Dub Compiler
3. entry.sh starts makefile
4. makefile starts Dub with settings from P.2
5. Dub starts ldc script
6. ldc returns files to dub.sdl
It's possible to programm to Paspberry Pi 3 (IMPORTANT)
Then, download Debian.
Code for Dockerfile:
FROM debian:stretch-slim
RUN apt-get update && apt-get install -y \
make cmake bash p7zip-full tar wget gpg xz-utils \
gcc-arm-linux-gnueabihf ca-certificates \
&& apt-get autoremove -y && apt-get clean

ARG ldcver=1.11.0

RUN wget -O /root/ldc.tar.xz https://github.com/ldc-developers/ldc/releases/download/v$ldcver/ldc2-$ldcver-linux-x86_64.tar.xz \
&& tar xf /root/ldc.tar.xz -C /root/ && rm /root/ldc.tar.xz
ENV PATH "/root/ldc2-$ldcver-linux-x86_64/bin:$PATH"
ADD entry.sh /entry.sh
RUN chmod +x /entry.sh
WORKDIR /workdir
ENTRYPOINT [ "/entry.sh" ]

Code for entry.sh (create .dpack folder)
#!/bin/bash

if [ ! -d ".dpack" ]; then
mkdir .dpack
fi

ln -s $(pwd)/.dpack /root/.dub

exec $@

Build Docker:
#!/bin/bash
docker build -t dcross docker-ctx

ddb:
#!/bin/bash
docker run -v `pwd`:/workdir -t --rm dcross $@

ldc:
#!/bin/bash
$LDC $LDC_FLAGS $@

dub.sdl:
name "FILE NAME"
description "DESCRIPTION"
license "LICENSE NAME"

targetType "executable"
targetPath "$TP"

dependency "vibe-d" version="~>0.8.4"
dependency "vibe-d:tls" version="~>0.8.4"
subConfiguration "vibe-d:tls" "openssl-1.1"

Makefile:

arch = arm

TP = build-$(arch)

LDC_DFLAGS = -mtriple=armv7l-linux-gnueabihf -disable-inlining -mcpu=cortex-a8

EMPTY :=
SPACE :=$(EMPTY) $(EMPTY)
LDC_BRT_DFLAGS = $(subst $(SPACE),;,$(LDC_DFLAGS))

ifeq ($(force), y)
FORCE = --force
else
FORCE =
endif

ifeq ($(release), y)
BUILD_TYPE = --build=release
else
BUILD_TYPE =
endif

DUB_FLAGS = build --parallel --compiler=./ldc $(FORCE) $(BUILD_TYPE)

$(info DUB_FLAGS: $(DUB_FLAGS))

LDC = ldc2
LDC_BRT = ldc-build-runtime

LDC_RT_DIR = .ldc-rt

GCC = arm-linux-gnueabihf-gcc

ifeq ($(arch), x86)
LDC_FLAGS =
else ifeq ($(arch), arm)
LDC_FLAGS = $(LDC_DFLAGS) -L-L./$(LDC_RT_DIR)/lib -L-L./arm-lib -gcc=$(GCC)
else
$(error unknown arch)
endif

DUB = TP=$(TP) LDC=$(LDC) LDC_FLAGS="$(LDC_FLAGS)" dub $(DUB_FLAGS)

.PHONY: all clean rtlibs stat

all: rtlibs
$(DUB)

DRT_LIBS=$(addprefix $(LDC_RT_DIR)/lib/, libdruntime-ldc.a libdruntime-ldc-debug.a libphobos2-ldc.a libphobos2-ldc-debug.a)

$(DRT_LIBS):
CC=$(GCC) $(LDC_BRT) -j8 --dFlags="$(LDC_BRT_DFLAGS)" --buildDir=$(LDC_RT_DIR) \
--targetSystem="Linux;UNIX" BUILD_SHARED_LIBS=OFF

rtlibs: $(DRT_LIBS)

stat:
find source -name '*.d' | xargs wc -l

clean:
rm -rf $(TP)
rm -rf .dub
$(LDC_BRT) --buildDir=$(LDC_RT_DIR) --resetOnly

AND EXAMPLE CODE App.d created in Vibed:
import vibe.core.core : runApplication;
import vibe.http.server;

void handleRequest(scope HTTPServerRequest req, scope HTTPServerResponse res)
{
if (req.path == "/")
res.writeBody("Hello, World!", "text/plain");
}

void main()
{
auto settings = new HTTPServerSettings;
settings.port = 8080;
settings.bindAddresses = ["::1", "0.0.0.0"];

auto l = listenHTTP(settings, &handleRequest);
scope (exit) l.stopListening();

runApplication();
}


Blog Comments
avatar
Chess player added comment 2 days, 22 hours ago
And yes, Televistar cutted "space" from this code. So go to Sources and all code is there.
avatar
pawnbeat added comment 2 days, 16 hours ago
We might need to improve the text editor. Adding WYSIWYG capabilities. You agree?
avatar
Chess player added comment 2 days, 14 hours ago
Yes, I think there should be more improved text editor . Maybe add "Delete space" setting? So some people could disable it and text editor wouldn't delete spaces
Sources

Source cited

https://habr.com/ru/post/428982/

Blog Images