cargo 0.19.0

Cargo, a package manager for Rust.
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
#!/bin/sh

# /bin/sh on Solaris is not a POSIX compatible shell, but /usr/bin/bash is.
if [ `uname -s` = 'SunOS' -a "${POSIX_SHELL}" != "true" ]; then
    POSIX_SHELL="true"
    export POSIX_SHELL
    exec /usr/bin/env bash $0 "$@"
fi
unset POSIX_SHELL # clear it so if we invoke other scripts, they run as bash as well

msg() {
    echo "configure: $1"
}

step_msg() {
    msg
    msg "$1"
    msg
}

warn() {
    echo "configure: WARNING: $1"
}

err() {
    echo "configure: error: $1"
    exit 1
}

need_ok() {
    if [ $? -ne 0 ]
    then
        err "$1"
    fi
}

need_cmd() {
    if command -v $1 >/dev/null 2>&1
    then msg "found $1"
    else err "need $1"
    fi
}

make_dir() {
    if [ ! -d $1 ]
    then
        msg "mkdir -p $1"
        mkdir -p $1
    fi
}

copy_if_changed() {
    if cmp -s $1 $2
    then
        msg "leaving $2 unchanged"
    else
        msg "cp $1 $2"
        cp -f $1 $2
        chmod u-w $2 # make copied artifact read-only
    fi
}

move_if_changed() {
    if cmp -s $1 $2
    then
        msg "leaving $2 unchanged"
    else
        msg "mv $1 $2"
        mv -f $1 $2
        chmod u-w $2 # make moved artifact read-only
    fi
}

putvar() {
    local T
    eval T=\$$1
    eval TLEN=\${#$1}
    if [ $TLEN -gt 35 ]
    then
        printf "configure: %-20s := %.35s ...\n" $1 "$T"
    else
        printf "configure: %-20s := %s %s\n" $1 "$T" "$2"
    fi
    printf "%-20s := %s\n" $1 "$T" >>config.tmp
}

probe() {
    local V=$1
    shift
    local P
    local T
    for P
    do
        T=$(command -v $P 2>&1)
        if [ $? -eq 0 ]
        then
            VER0=$($P --version 2>/dev/null | head -1 \
                |  sed -e 's/[^0-9]*\([vV]\?[0-9.]\+[^ ]*\).*/\1/' )
            if [ $? -eq 0 -a "x${VER0}" != "x" ]
            then
              VER="($VER0)"
            else
              VER=""
            fi
            break
        else
            VER=""
            T=""
        fi
    done
    eval $V=\$T
    putvar $V "$VER"
}

probe_need() {
    local V=$1
    probe $*
    eval VV=\$$V
    if [ -z "$VV" ]
    then
        err "needed, but unable to find any of: $*"
    fi
}

validate_opt () {
    for arg in $CFG_CONFIGURE_ARGS
    do
        isArgValid=0
        for option in $BOOL_OPTIONS
        do
            if test --disable-$option = $arg
            then
                isArgValid=1
            fi
            if test --enable-$option = $arg
            then
                isArgValid=1
            fi
        done
        for option in $VAL_OPTIONS
        do
            if echo "$arg" | grep -q -- "--$option="
            then
                isArgValid=1
            fi
        done
        if [ "$arg" = "--help" ]
        then
            echo
            echo "No more help available for Configure options,"
            echo "check the Wiki or join our IRC channel"
            break
        else
            if test $isArgValid -eq 0
            then
                err "Option '$arg' is not recognized"
            fi
        fi
    done
}

valopt() {
    VAL_OPTIONS="$VAL_OPTIONS $1"

    local OP=$1
    local DEFAULT=$2
    shift
    shift
    local DOC="$*"
    if [ $HELP -eq 0 ]
    then
        local UOP=$(echo $OP | tr '[:lower:]' '[:upper:]' | tr '\-' '\_')
        local V="CFG_${UOP}"
        eval $V="$DEFAULT"
        for arg in $CFG_CONFIGURE_ARGS
        do
            if echo "$arg" | grep -q -- "--$OP="
            then
                val=$(echo "$arg" | cut -f2 -d=)
                eval $V=$val
            fi
        done
        putvar $V
    else
        if [ -z "$DEFAULT" ]
        then
            DEFAULT="<none>"
        fi
        OP="${OP}=[${DEFAULT}]"
        printf "    --%-30s %s\n" "$OP" "$DOC"
    fi
}

opt() {
    BOOL_OPTIONS="$BOOL_OPTIONS $1"

    local OP=$1
    local DEFAULT=$2
    shift
    shift
    local DOC="$*"
    local FLAG=""

    if [ $DEFAULT -eq 0 ]
    then
        FLAG="enable"
    else
        FLAG="disable"
        DOC="don't $DOC"
    fi

    if [ $HELP -eq 0 ]
    then
        for arg in $CFG_CONFIGURE_ARGS
        do
            if [ "$arg" = "--${FLAG}-${OP}" ]
            then
                OP=$(echo $OP | tr 'a-z-' 'A-Z_')
                FLAG=$(echo $FLAG | tr 'a-z' 'A-Z')
                local V="CFG_${FLAG}_${OP}"
                eval $V=1
                putvar $V
            fi
        done
    else
        if [ ! -z "$META" ]
        then
            OP="$OP=<$META>"
        fi
        printf "    --%-30s %s\n" "$FLAG-$OP" "$DOC"
     fi
}

envopt() {
    local NAME=$1
    local V="CFG_${NAME}"
    eval VV=\$$V

    # If configure didn't set a value already, then check environment.
    #
    # (It is recommended that the configure script always check the
    # environment before setting any values to envopt variables; see
    # e.g.  how CFG_CC is handled, where it first checks `-z "$CC"`,
    # and issues msg if it ends up employing that provided value.)
    if [ -z "$VV" ]
    then
        eval $V=\$$NAME
        eval VV=\$$V
    fi

    # If script or environment provided a value, save it.
    if [ ! -z "$VV" ]
    then
        putvar $V
    fi
}

msg "looking for configure programs"
need_cmd cmp
need_cmd mkdir
need_cmd printf
need_cmd cut
need_cmd head
need_cmd grep
need_cmd xargs
need_cmd cp
need_cmd find
need_cmd uname
need_cmd date
need_cmd tr
need_cmd sed
need_cmd cmake
need_cmd make

CFG_SRC_DIR="$(cd $(dirname $0) && pwd)/"
CFG_BUILD_DIR="$(pwd)/"
CFG_SELF="$0"
CFG_CONFIGURE_ARGS="$@"

OPTIONS=""
HELP=0
if [ "$1" = "--help" ]
then
    HELP=1
    shift
    echo
    echo "Usage: $CFG_SELF [options]"
    echo
    echo "Options:"
    echo
else
    msg "recreating config.tmp"
    echo '' >config.tmp

    step_msg "processing $CFG_SELF args"
fi

BOOL_OPTIONS=""
VAL_OPTIONS=""

opt debug 1 "build with extra debug fun"
opt optimize 1 "build with optimizations"
opt verify-install 1 "verify installed binaries work"
opt option-checking 1 "complain about unrecognized options in this configure script"
opt cross-tests 1 "run cross-compilation tests"
opt build-openssl 0 "compile OpenSSL at build time to link to"
valopt prefix "/usr/local" "set installation prefix"
valopt local-rust-root "" "set prefix for local rust binary"

if [ ! -z "${CFG_LOCAL_RUST_ROOT}" ]; then
    export LD_LIBRARY_PATH="${CFG_LOCAL_RUST_ROOT}/lib:$LD_LIBRARY_PATH"
    export DYLD_LIBRARY_PATH="${CFG_LOCAL_RUST_ROOT}/lib:$DYLD_LIBRARY_PATH"
    export PATH="${CFG_LOCAL_RUST_ROOT}/bin:$PATH"
fi

valopt cargo "cargo" "cargo to bootstrap from"
valopt rustc "rustc" "rustc to compile with"
valopt rustdoc "rustdoc" "rustdoc to document with"

if [ $HELP -eq 0 ]; then
    probe_need CFG_CARGO $CFG_CARGO
    probe_need CFG_RUSTC $CFG_RUSTC
    probe_need CFG_RUSTDOC $CFG_RUSTDOC
    DEFAULT_BUILD=$("${CFG_RUSTC}" -vV | grep 'host: ' | sed 's/host: //')
fi

valopt build "${DEFAULT_BUILD}" "GNUs ./configure syntax LLVM build triple"
valopt host "${CFG_BUILD}" "GNUs ./configure syntax LLVM host triples"
valopt target "${CFG_HOST}" "GNUs ./configure syntax LLVM target triples"

valopt localstatedir "/var/lib" "local state directory"
valopt sysconfdir "/etc" "install system configuration files"
valopt datadir "${CFG_PREFIX}/share" "install data"
valopt infodir "${CFG_PREFIX}/share/info" "install additional info"
valopt docdir "${CFG_PREFIX}/share/doc/cargo" "install extra docs"
valopt mandir "${CFG_PREFIX}/share/man" "install man pages in PATH"
valopt libdir "${CFG_PREFIX}/lib" "install libraries"

if [ -e ${CFG_SRC_DIR}.git ]
then
    valopt release-channel "dev" "the name of the release channel to build"
else
    msg "git: no git directory. Changing default release channel to stable"
    valopt release-channel "stable" "the name of the release channel to build"
fi

if [ $HELP -eq 1 ]
then
    echo
    exit 0
fi

# Validate Options
if [ -z "$CFG_DISABLE_OPTION_CHECKING" ]
then
   step_msg "validating $CFG_SELF args"
   validate_opt
fi

step_msg "looking for build programs"

probe_need CFG_CC          cc gcc clang
probe GIT git

# a little post-processing of various config values
CFG_PREFIX=${CFG_PREFIX%/}
CFG_DATADIR=${CFG_DATADIR%/}
CFG_INFODIR=${CFG_INFODIR%/}
CFG_DOCDIR=${CFG_DOCDIR%/}
CFG_MANDIR=${CFG_MANDIR%/}
CFG_LIBDIR=${CFG_LIBDIR%/}
CFG_HOST="$(echo $CFG_HOST | tr ',' ' ')"
CFG_TARGET="$(echo $CFG_TARGET | tr ',' ' ')"

# strip CFG_PREFIX from variables used for installation so that
# install.sh's --prefix value can be used instead
CFG_DATADIR=${CFG_DATADIR#${CFG_PREFIX}}
CFG_INFODIR=${CFG_INFODIR#${CFG_PREFIX}}
CFG_DOCDIR=${CFG_DOCDIR#${CFG_PREFIX}}
CFG_MANDIR=${CFG_MANDIR#${CFG_PREFIX}}
CFG_LIBDIR=${CFG_LIBDIR#${CFG_PREFIX}}

# copy host-triples to target-triples so that hosts are a subset of targets
V_TEMP=""
for i in $CFG_HOST $CFG_TARGET;
do
   echo "$V_TEMP" | grep -qF $i || V_TEMP="$V_TEMP${V_TEMP:+ }$i"
done
CFG_TARGET=$V_TEMP

if [ "$CFG_SRC_DIR" != "$CFG_BUILD_DIR" ]; then
    CFG_CUSTOM_BUILD_DIR=$CFG_BUILD_DIR/target
    putvar CFG_CUSTOM_BUILD_DIR
fi

step_msg "writing configuration"

putvar CFG_SRC_DIR
putvar CFG_BUILD_DIR
putvar CFG_CONFIGURE_ARGS
putvar CFG_PREFIX
putvar CFG_BUILD
putvar CFG_HOST
putvar CFG_TARGET
putvar CFG_DATADIR
putvar CFG_DOCDIR
putvar CFG_INFODIR
putvar CFG_MANDIR
putvar CFG_LIBDIR
putvar CFG_RUSTC
putvar CFG_RUSTDOC
putvar CFG_CARGO
putvar CFG_GIT

msg
copy_if_changed ${CFG_SRC_DIR}Makefile.in ./Makefile
move_if_changed config.tmp config.mk
rm -f config.tmp
touch config.stamp

step_msg "complete"
msg