4
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Dockerを使ったD言語のワンライナービルド

Last updated at Posted at 2017-12-06

はじめに

シェル芸はロマンです。
Dockerを使ってワンライナーで環境を汚さずにD言語のプロジェクトをビルドする方法を紹介します。

TL;DR

d-mansay で試します。

$ ls -1a
.
..
.dub
.git
.gitignore
README.md
dub.json
dub.selections.json
source
$ docker run --rm -v $PWD:/src -w /src dlanguage/dmd:latest dub -- ワンライナーだよ
Fetching east_asian_width 1.0.0 (getting selected version)...
Performing "debug" build using dmd for x86_64.
east_asian_width 1.0.0: building configuration "library"...
d-mansay ~master: building configuration "say"...
Linking...
Running ./d-mansay ワンライナーだよ
 __________________
< ワンライナーだよ >
 ------------------
    \    _   _
     \  (_) (_)
       /______ \
       \\(O(O \/
        | | | |
        | |_| |
       /______/
         <   >
        (_) (_)
$ ls -1a
.
..
.dub
.git
.gitignore
README.md
d-mansay
dub.json
dub.selections.json
source
$ ./d-mansay Ubuntuだよ
 ____________
< Ubuntuだよ >
 ------------
    \    _   _
     \  (_) (_)
       /______ \
       \\(O(O \/
        | | | |
        | |_| |
       /______/
         <   >
        (_) (_)

バイナリが出力されます。
ビルドに使ったコンテナと同じアーキテクチャであればそのまま実行できます。

注意点

  • 出力されるバイナリのパーミッションはコンテナのユーザーに依存します。
  • 依存関係がないプロジェクト前提です。dmanbotは以下のようにビルドできません。
$ docker run --rm -it -v `pwd`:/src -w /src dlanguage/dmd:latest dub build
Fetching dyaml 0.6.3 (getting selected version)...
Fetching tinyendian 0.1.2 (getting selected version)...
Fetching twitter4d 0.0.70 (getting selected version)...
Fetching mysql-d 0.3.3 (getting selected version)...
Fetching dunit 1.0.12 (getting selected version)...
Performing "debug" build using dmd for x86_64.
tinyendian 0.1.2: building configuration "library"...
dyaml 0.6.3: building configuration "library"...
mysql-d 0.3.3: building configuration "mysql-d"...
twitter4d 0.0.70: building configuration "library"...
dmanbot ~master: building configuration "application"...
Linking...
/usr/bin/ld: cannot find -lmysqlclient
/usr/bin/ld: cannot find -lcurl
collect2: error: ld returned 1 exit status
Error: linker exited with status 1
dmd failed with exit code 1.

おまけ

宗教上の理由等でGoをインストールしていない環境でも、go getを使ってバイナリを取得できます。

$ docker run --rm -v ~/bin:/go/bin golang:1.9.2-stretch go get github.com/adamryman/gophersay
$ gophersay
 ------------------------
Don't panic.
 ------------------------
   \
    \
     \   ,_---~~~~~----._
  _,,_,*^____      _____``*g*\"*,
 / __/ /'     ^.  /      \ ^@q   f
[  @f | @))    |  | @))   l  0 _/
 \`/   \~____ / __ \_____/    \
  |           _l__l_           I
  }          [______]           I
  ]            | | |            |
  ]             ~ ~             |
  |                            |
   |                           |

4
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?