# along with this program. If not, see <http://www.gnu.org/licenses/>.
# example usages:
-# ../nailing-cargo/nailing-caretwgo make
+# ../nailing-cargo/nailing-cargo make
# ../nailing-cargo/nailing-cargo cargo build
-# CARGO='../nailing-cargo/nailing-cargo cargo' make
# Why do we need this ?
#
# https://stackoverflow.com/questions/33025887/how-to-use-a-local-unpublished-crate
# https://github.com/rust-lang/cargo/issues/1481
-# Needs libtoml-perl
-
-#: Cargo.nail:
+# Options:
+# -v Increase verbosity. Default is 1.
+# -q Set verbosity ot 0.
+# -D Increase amount of debugging dump.
+#
+# -n "No action": stop after writing Cargo.toml.nailing~
+# everywhere, and do not run any build command.
+#
+# -T<arch> --target=<arch>
+# Specify target architecture. If <arch> starts with a
+# capital ascii letter, is an alias for some other arch
+# looked up in Cargo.nail and then in the builtin list:
+# RPI arm-unknown-linux-gnueabihf
+# Translates to a --target= option to the ultimate command,
+# unless that is a cargo subcommand which would reject it.
+#
+# -u | --cargo-lock-update
+# -U | --no-cargo-lock-update
+# Arranges to do a dance to allow Cargo.lock (or
+# alternative) to be updated in the source directory.
+#
+# The Cargo.lock and Cargo.toml are copied to the build
+# directory along with a skeleton just big enough to fool
+# cargo. After cargo has run, the resulting Cargo.lock is
+# copied back to the source tree.
+#
+# Makes no sense with in-tree builds.
+#
+# Default is no update unless the ultimate command is a
+# cargo subcommand which we know needs it.
#
+# -m | --cargo-manifest-args
+# -M | --no-cargo-manifest-args
+# Controls whether we add cargo command line options
+# relating to finding Cargo.toml, to the command to
+# run.
+#
+# Default is true if we are doing an out-of- tree build,
+# unless we are updating the Cargo.lock (in which case the
+# only relevant files are to be found in the build directory).
+#
+# The arguments are
+# --manifest-path=<path/to/Cargo.toml>
+# --locked
+# --target-dir=target
+#
+# -T | --no-cargo-target-arg
+# -t | --cargo-target-arg
+# Suppress --target (or un-suppress it).
+# Only useful with -m.
+#
+# Cargo.nail:
+#
+# # Adds each <subdir> to the list of directories whose
+# # Cargo.toml is to be nailed, and also arranges to use
+# # the package found there for other directories if
+# # no other source of that package is evident in Cargo.nail.
+# subdirs = [
+# "<subdir>"
+# ...
+# ]
+# or:
+# subdirs = """
+# "<subdir>"
+# ...
+# """
+#
+# # Adds <subdir> to the list of directories whose Cargo.toml
+# # is to be nailed, and overrides any other nailing for <package>
# [packages]
-# package = subdir
-# package = { subdir = ... }
+# <package> = <subdir>
+# <package> = { <subdir> = ... }
+#
+# To control use of alternative Cargo.lock filename:
+# [alt_cargolock]
#
-# [subdirs]
-# subdir
+# file = true # equivalent to "Cargo.lock.example"
+# file = false # disables this feature
+# file = "<some leafname>"
+#
+# force = false # default, uses alt file only if it already exists
+# force = true # always uses alt file; creation would make Cargo.lock
+#
+# (you can also specify just alt_cargo_lock instead of alt_cargo_lock.file)
+#
+# To enable out of tree builds:
+# [oot]
+# dir = "<build-directory>" # default is Build, if use is specified
+# and then
+# use = "really"
+# user = "<someuser>"
+# or
+# use = "ssh"
+# user = "<user>@host" # NB must still share a filesystem!
+# or
+# use = "command_args"
+# command = ["<command>", "<which works like>", "nice"]
+# or
+# use = "command_sh"
+# command = ["<command>", "<which work like>", "sh -c"]
+# or
+# use = "null"
+#
+# Limitations:
+#
+# Always dirties everyone's Cargo.toml, but tries to put them
+# back (if not, running it again should fix it). Cannnot be
+# fixed without changes to cargo.
+#
+# Out of tree builds require a unified filesystem view: eg,
+# different users on the same host, NFS, or something. This
+# could be improved.
+#
+# Alternative Cargo.lock file must currently be a leafname.
+# I think this just involves review to check other values work.
+#
+# Alternative Cargo.lock file must be on smae filesystem.
+# This is not so easy; we would want the existing algorithm but
+# a fallback for this case.
+#
+# Cargo.nail unconditionally looked for in ..
+# Ideally should be configurable, and also perhaps be able
+# to combine multiple Cargo.nail files ?
+#
+# Env vars we pass to the command:
+# NAILINGCARGO_WORKSPHERE absolute path of invocation ..
+# NAILINGCARGO_MANIFEST_DIR absolute path of invocation .
+# NAILINGCARGO_BUILDSPHERE only if out of tree: abs parent of build dir
+# NAILINGCARGO_BUILD_DIR absolute path of build dir (even if = src)
+
our $self;
our $cargo_lock_update;
our $cargo_manifest_args;
+our $cargo_target_arg=1;
our $alt_cargo_lock;
our @configs;
}
die "$e ?" if length $e;
+ $nail->{subdirs} //= [ ];
+
if (!ref $nail->{subdirs}) {
$nail->{subdirs} = [
grep /^[^\#]/,
sub addargs () {
if (@ARGV>=2 &&
- $ARGV[0] =~ m{\bcargo\b} &&
- $ARGV[1] =~ m/^(?:generate-lockfile|update)$/) {
- $cargo_lock_update //= 1;
- $target = undef;
- } else {
- $cargo_lock_update //= 0;
+ $ARGV[0] =~ m{\bcargo\b}) {
+ if ($ARGV[1] =~ m/^(?:generate-lockfile|update)$/) {
+ $cargo_lock_update //= 1;
+ $target = undef;
+ }
}
+ $cargo_lock_update //= 0;
$cargo_manifest_args //=
(defined $oot_dir) && !$cargo_lock_update;
if ($cargo_manifest_args) {
push @ARGV, "--manifest-path=${src_absdir}/Cargo.toml",
- qw(--locked --target-dir=target);
+ qw(--locked);
+ push @ARGV, qw(--target-dir=target) if $cargo_target_arg;
}
if (defined $target) {
ENDCP
$pre .= <<'ENDPRE';
shift;
- mkdir -p src; >src/lib.rs;
+ mkdir -p src; >src/lib.rs; >build.rs
ENDPRE
$post = <<'ENDPOST';
- rm -r src Cargo.toml;
+ rm -r src Cargo.toml build.rs;
ENDPOST
}
my $addpath = (cfg_uc qw(oot path_add)) //
$cargo_lock_update= $1=~m/[a-z]/;
} elsif (s{^-([mM])}{-}) {
$cargo_manifest_args= $1=~m/[a-z]/;
+ } elsif (s{^-([tT])}{-}) {
+ $cargo_target_arg= $1=~m/[a-z]/;
} else {
die "$self: unknown short option(s) $_\n";
}
$cargo_lock_update= !!$1;
} elsif (m{^--(no-)?cargo-manifest-args}) {
$cargo_manifest_args= !!$1;
+ } elsif (m{^--(no-)?cargo-target-arg}) {
+ $cargo_target_arg= !!$1;
} else {
die "$self: unknown long option $_\n";
}