Commit graph

46 commits

Author SHA1 Message Date
c2a760efcd Add %crate_instdir convenience macro
Fixes #41.

The template is adjusted to use the new macro. This will only work
if the macro is defined, thus the required version of rust-packaging
is bumped.
2022-02-14 14:01:44 +01:00
Aleksei Bavshin
f1be3a0d4d
macros: pass CFLAGS/CXXFLAGS to the processes started by cargo
This is mainly targeted to the crates using `rust-cc`, where we want to
apply system-wide compiler flags when invoking the compiler. `cc`
supports CFLAGS and CXXFLAGS, but we never set those.
Defining that per project is not possible, as we have no way to inherit
any build context from a dependency package.

Possibly also affects: `bindgen`, `cxx`, any other crate that invokes
the C/C++ compiler and passes the CFLAGSS
2021-12-05 22:20:52 -08:00
1482f79e28 Drop __cargo_skip_build logic
It looks like this logic was only used for module builds, which is not
how Rust packages have been built for a few Fedora releases now.

Fixes #142.
2021-11-25 08:49:17 +00:00
Alberto Planas
246ee489a0 Add bundled() provider for vendoring
This commit add basic support for crate vendoring in Rust. The user will
use something like `cargo vendor` to create a vendor directory (that can
later be deployed as a tgz) that contains all the dependencies.

This patch will analyze the output of `cargo manifest` to calculate the
closure of dependencies, and via the new parameter `--provides-vendor`,
print all the 'bundled(crate(NAME/FEATURE)) = 0.0.0' provided by the
binary.

The algorithm is not perfect, as today it will include all the features
resolved for the crate (not all the availables, tho), but basically is
something like:

1.- A dependency generator macro, cargo_bundled, will call
cargo-inspector like this:

  # In STDIN we will provide the name of the binary
  cargo-inspector --provides-vendor --path %{_builddir}

2.- cargo-inspector will search inside the 'path' tree a Cargo.toml that
generate the binary name send via STDIN.

3.- From this point, we go up to the tree to find the top-most
Cargo.toml, as this will be the directory where .cargo/config is living.
We make this directory our `cwd`.

4.- Using the metadata from `cargo manifest`, we generate the closure of
dependencies required by this binary. To simplify the problem, the
current code do not resolve the features, and accept the one resolved by
cargo as valid. Most of the time this will be OK, maybe will include
some extra features needed for other binaries.

5.- Print the 'bundled()' data.

This code will only be executed in the directory 'vendor' is present in
the top-most directory found on step 3.
2021-10-12 15:10:33 +02:00
Jan Staněk
035e458f0a
Parse features with + in their name
If a crate has a feature with `+` in it's name,
the `%__cargo_feature_from_name` macro fails to correctly parse it.
For example, the `cxxbridge-flags` crate declares (among others)
the `c++20` feature; that is currently parsed as follows:

```lua
> string.match("cxxbridge-flags+c++20-devel", "^.+%+(.+)-devel$")
20
```

The adjusted regex matches the *first* `+` as feature name separator:

```lua
> string.match("cxxbridge-flags+c++20-devel", "^[^+]+%+(.+)-devel$")
c++20
```
2021-02-01 13:56:37 +01:00
Andreas Schwab
8dcf851319 Add riscv64 to %rust_arches
Signed-off-by: Andreas Schwab <schwab@suse.de>
2020-08-13 21:24:06 +02:00
Thomas Jarosch
90d0e85da2
Fix up Cargo.toml.orig error message that started to appear with Rust 1.43.0
+ /usr/bin/env CARGO_HOME=.cargo RUSTC_BOOTSTRAP=1 /opt/rust/bin/cargo package -l
+ grep -w -v Cargo.lock
+ xargs -d '\n' /bin/cp --parents -a -t /user/rpmbuild/BUILDROOT/rust-term_size-0.3.0-1.i2n.x86_64/datastore/dev/rust/cargo/registry/term_size-0.3.0
warning: No (git) VCS found for `/datastore/rpmbuild/BUILD/term_size-0.3.0`
/bin/cp: cannot stat 'Cargo.toml.orig': No such file or directory

Signed-off-by: Igor Raits <ignatenkobrain@fedoraproject.org>
2020-05-02 19:12:54 +02:00
Josh Stone
b4581d8f5b Use cargo install --no-track with cargo 1.41
In cargo 1.41, `cargo install` adds a new `.crates2.json` file in the
install root for tracking version upgrades. This would be another file
that `%cargo_install` should remove afterward, but there is also a new
`--no-track` option which disables such metadata files altogether.

This update should be coordinated with the Rust toolchain update in the
distro, e.g. with rust-packaging `Requires: cargo >= 1.41`. The new
option will be rejected as an unstable option on earlier versions.
2020-01-30 22:02:59 -08:00
Igor Gnatenko
b2d348bd41
inspector: Add support for multiple features
Fixes: https://pagure.io/fedora-rust/rust2rpm/issue/103
Signed-off-by: Igor Gnatenko <ignatenkobrain@fedoraproject.org>
2019-12-16 08:02:47 +01:00
Igor Gnatenko
a6bde5599a
Pass --cap-lints=warn to the RUSTFLAGS
It is simply impossible to fight against people putting
 #![deny(warnings)] into the code…

Closes: https://pagure.io/fedora-rust/rust2rpm/issue/98
Signed-off-by: Igor Gnatenko <ignatenkobrain@fedoraproject.org>
2019-12-03 19:11:20 +01:00
Igor Gnatenko
b5e2db003f
Ignore Cargo.lock
Fixes: https://pagure.io/fedora-rust/rust2rpm/issue/90

Signed-off-by: Igor Gnatenko <ignatenkobrain@fedoraproject.org>
2019-09-08 15:44:37 +02:00
Igor Gnatenko
4c891852b5
Implement %__cargo_skip_build
We need to have an easy way how to skip doing 'cargo build' to speedup a
module builds.

Signed-off-by: Igor Gnatenko <ignatenkobrain@fedoraproject.org>
2019-06-09 16:00:25 +02:00
Igor Gnatenko
c54d2409da
Remove temporary Cargo.toml.deps
Signed-off-by: Igor Gnatenko <ignatenkobrain@fedoraproject.org>
2019-04-28 07:47:06 +02:00
Igor Gnatenko
ecc850755e
macros: Use %{build_rustflags} convention
But keep %__global_rustflags around for compatibility.

Signed-off-by: Igor Gnatenko <ignatenkobrain@fedoraproject.org>
2019-04-23 21:14:51 +02:00
Igor Gnatenko
3076bbaa3a
macros: Pass -Ccodegen-units=1 in RUSTFLAGS
This has good impact on performance and binary size at cost of
compilation time. As nice side effect, it fixes bug which breaks
compilation of binaries in Fedora Rawhide.

For example, ffsend binary went from 107M to 70M.

References: https://bugzilla.redhat.com/show_bug.cgi?id=1701339
Signed-off-by: Igor Gnatenko <ignatenkobrain@fedoraproject.org>
2019-04-23 21:14:51 +02:00
Igor Gnatenko
c57afa88aa
Add support for %generate_buildrequires
Signed-off-by: Igor Gnatenko <ignatenkobrain@fedoraproject.org>
2019-04-16 11:46:27 +02:00
Igor Gnatenko
5d7a0b2444
Do not pull optional dependencies
Signed-off-by: Igor Gnatenko <ignatenkobrain@fedoraproject.org>
2019-03-14 10:37:37 +01:00
Igor Gnatenko
7f0a499ff3
data: Escape \n properly
Signed-off-by: Igor Gnatenko <ignatenkobrain@fedoraproject.org>
2019-03-10 10:14:28 +01:00
Igor Gnatenko
84a73bfa24
data: Cargo doesn't escape paths with space
When building matrixmultiply v0.2.2:

BUILDSTDERR: /usr/bin/cp: cannot stat 'spare': No such file or directory
BUILDSTDERR: /usr/bin/cp: failed to get attributes of 'kernels': No such file or directory

Signed-off-by: Igor Gnatenko <ignatenkobrain@fedoraproject.org>
2019-02-17 17:19:25 +01:00
Igor Gnatenko
00c0c5cec9 Add support for prerelease versions
Signed-off-by: Igor Gnatenko <ignatenkobrain@fedoraproject.org>
2019-01-28 09:15:18 +00:00
Josh Stone
a04e95bc4f Set the install root in .cargo/config 2018-12-07 13:59:03 -08:00
Josh Stone
b4e2503829 Set CARGO_HOME to the local .config 2018-12-07 13:58:41 -08:00
Igor Gnatenko
2cac5e5ad5
split features into subpackages
References: https://discussion.fedoraproject.org/t/rfc-new-crates-packaging-design-features-have-their-own-subpackages/563?u=ignatenkobrain
Signed-off-by: Igor Gnatenko <ignatenkobrain@fedoraproject.org>
2018-11-03 21:45:04 +01:00
Igor Gnatenko
80237720ae
macros: remove support for target-dir
Signed-off-by: Igor Gnatenko <ignatenkobrain@fedoraproject.org>
2018-06-22 21:53:09 +02:00
Igor Gnatenko
c9ce952e26
macros: make %cargo_* macros parametric
Unfortunately cargo-install doesn't accept --target-dir, so have to pass
setting through envvar.

Also %{shrink:…} them so it looks nicer in build log.

Signed-off-by: Igor Gnatenko <ignatenkobrain@fedoraproject.org>
2018-06-22 21:05:42 +02:00
Igor Gnatenko
c5bab762f5 macros: pass %__cargo_common_opts to %cargo_install
Reason this has not been done before is that cargo-install doesn't
understand --release. Let's just add it to other commands and be done
with it.

Reported-by: Josh Stone <jistone@redhat.com>
Signed-off-by: Igor Gnatenko <ignatenkobrain@fedoraproject.org>
2018-02-20 22:08:02 +01:00
Igor Gnatenko
cd63296353 macros: remove spurious whitespace
Fixes: https://pagure.io/fedora-rust/rust2rpm/issue/48
Reported-by: Josh Stone <jistone@redhat.com>
Signed-off-by: Igor Gnatenko <ignatenkobrain@fedoraproject.org>
2018-01-09 06:52:36 +01:00
Igor Gnatenko
5313b35271 macros: remove Cargo.lock
cargo-package automatically strips it out, but we package also some
things directly from git.

Acked-by: Josh Stone <jistone@redhat.com>
Signed-off-by: Igor Gnatenko <ignatenkobrain@fedoraproject.org>
2018-01-09 00:00:04 +01:00
Igor Gnatenko
09a434b55a make 'rlib' first-class citizen
Fixes: https://pagure.io/fedora-rust/rust2rpm/issue/47
Signed-off-by: Igor Gnatenko <ignatenkobrain@fedoraproject.org>
2018-01-08 19:09:54 +01:00
Igor Gnatenko
4b31b3e594 macros: search for whole string
Signed-off-by: Igor Gnatenko <ignatenkobrain@fedoraproject.org>
2018-01-08 19:09:10 +01:00
Igor Gnatenko
47b6c3ef80 macros.crago: pass --no-fail-fast
It is quite useful to see all failing tests instead of few of first.

Signed-off-by: Igor Gnatenko <ignatenkobrain@fedoraproject.org>
Reviewed-by: Josh Stone <jistone@redhat.com>
2017-12-05 13:03:41 +01:00
Igor Gnatenko
59809d4940 use cp instead of install
We want to preserve original modes and so on.

Signed-off-by: Igor Gnatenko <ignatenkobrain@fedoraproject.org>
2017-11-04 15:32:39 +01:00
Martin Sehnoutka
2c556e1473 macros: explicitly set rustdoc
On systems where rustup is used, simple rpmbuild will use rustc from system,
but rustdoc will be taken from PATH which might be different from system.
Given this, doc-tests or anything related to rustdoc will fail with mis-mathching
rustc version.

Merges: https://pagure.io/fedora-rust/rust2rpm/pull-request/38
2017-06-23 13:41:42 +02:00
Igor Gnatenko
cce3d7bc92 macros: switch to /usr/share/cargo/registry
We should not be using /usr/src because that one is supposed to be used for
"Source code may be placed in this subdirectory, only for reference purposes".

Signed-off-by: Igor Gnatenko <ignatenkobrain@fedoraproject.org>
2017-06-20 23:10:28 +02:00
Josh Stone
23b334286c Switch rustflags from -g to -Cdebuginfo=2
Since rustc doesn't allow `-g` and `-Cdebuginfo` options to mix, we need
to make sure we're consistent with the option crates may set in their
own `[profile] debug` settings.  Cargo used to send `-g` for that, but
switched to `-Cdebuginfo` in version 0.17.0.

Fixes #32.
2017-03-30 10:37:25 -07:00
Igor Gnatenko
a254693cde Revert "macros: move Cargo.toml.orig inplace"
Somehow this doesn't really work. No time for investigation.

This reverts commit fc12436f25.
2017-02-25 21:51:08 +01:00
Igor Gnatenko
86d06ae613 macros: strip all dev-dependencies sections
Even [dev-dependencies.foo].

Signed-off-by: Igor Gnatenko <ignatenkobrain@fedoraproject.org>
2017-02-25 21:45:24 +01:00
Igor Gnatenko
fc12436f25 macros: move Cargo.toml.orig inplace
cargo package -l lists Cargo.toml.orig and we're installing it anyway,
so let's just do mv -f instead of doing new install.

Signed-off-by: Igor Gnatenko <ignatenkobrain@fedoraproject.org>
2017-02-25 19:21:40 +01:00
Igor Gnatenko
f487983d6c use rich dependencies to fullfill requirements
Imagine, that:
* A requires 0.6.0 <= X < 0.7.0
* B requires 0.9.0 <= X < 0.10.0
* C requires A and B

If we use Requires + Conflicts, then we just can't build or install
C, because sub-dependencies are conflicting between each other.

Proper syntax is: (X >= 0.6.0 with X < 0.7.0)

Signed-off-by: Igor Gnatenko <ignatenkobrain@fedoraproject.org>
2017-02-25 10:02:05 +01:00
Igor Gnatenko
e834debc6a add support for proc-macro kind
Closes: https://pagure.io/fedora-rust/rust2rpm/issue/19
Signed-off-by: Igor Gnatenko <ignatenkobrain@fedoraproject.org>
2017-02-18 19:53:08 +01:00
Igor Gnatenko
d4334a2ee7 macros: automatically strip dev-dependencies
All background written in upstream cargo GitHub issue[0].

In short, cargo build/install enforces us to have all dev-dependencies
even they are not used for building/installed.

[0] https://github.com/rust-lang/cargo/issues/3732

Signed-off-by: Igor Gnatenko <ignatenkobrain@fedoraproject.org>
2017-02-18 16:10:50 +01:00
Igor Gnatenko
ee68fab15b macros: don't define %cargo_build/test as functions
There are only problems from this.

Signed-off-by: Igor Gnatenko <ignatenkobrain@fedoraproject.org>
2017-02-18 02:25:21 +01:00
Igor Gnatenko
2fbb50e1dc distribute rust2rpm in PyPI via setuptools
Signed-off-by: Igor Gnatenko <ignatenkobrain@fedoraproject.org>
2017-02-12 11:35:45 +01:00
Igor Gnatenko
c12df7d085 %cargo_install is now smart to handle libs and bins
So far we had %cargo_install (for binaries) and %cargo_install_crate
(for libraries) which is a bit awkward and requires us to put
additional arguments for latter one.

We can do all the magic behind the scene.

Closes: https://pagure.io/fedora-rust/rust2rpm/issue/7
Signed-off-by: Igor Gnatenko <ignatenkobrain@fedoraproject.org>
2017-02-10 22:17:45 +01:00
Igor Gnatenko
0038452903 Makefile: install cargodeps without extension
Otherwise RPM bytecompile script will try to create bytecompiled
code and will fail.

Signed-off-by: Igor Gnatenko <ignatenkobrain@fedoraproject.org>
2017-02-05 22:48:41 +01:00
Igor Gnatenko
74beb9388f move RPM stuff into subdirectory
Signed-off-by: Igor Gnatenko <ignatenkobrain@fedoraproject.org>
2017-02-05 18:15:28 +01:00