Commit graph

10 commits

Author SHA1 Message Date
David Tolnay
633426a8fc edition: Fill in macro imports
Macros were previously imported through `#[macro_use] extern crate`,
which is basically a glob import of all macros from the crate. As of
2018 edition of Rust, `extern crate` is no longer required and macros
are imported individually like any other item from a dependency. This CL
fills in all the appropriate macro imports that will allow us to remove
our use of `extern crate` in a subsequent CL.

TEST=cargo check --all-features --tests
TEST=kokoro

Change-Id: If2ec08b06b743abf5f62677c6a9927c3d5d90a54
Reviewed-on: https://chromium-review.googlesource.com/1565546
Commit-Ready: David Tolnay <dtolnay@chromium.org>
Commit-Ready: ChromeOS CL Exonerator Bot <chromiumos-cl-exonerator@appspot.gserviceaccount.com>
Tested-by: David Tolnay <dtolnay@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: David Tolnay <dtolnay@chromium.org>
2019-04-15 02:06:07 -07:00
David Tolnay
62041f0419 msg_socket: Simplify derive by removing const namespace
The derive(MsgOnSocket) macro used to expand to something like:

    const __MSG_ON_SOCKET_IMPL_Typename: () = {
        extern crate msg_socket as _msg_socket;
        impl _msg_socket::MsgOnSocket for Typename {
            ...
        }
    };

This was helpful in 2015 edition code by allowing callers to invoke the
derive without also writing `use msg_socket` at the top of the file to
bring the crate into scope.

In 2018 edition, paths beginning with a crate name do not need to be
otherwise imported, so this derive can simply expand to:

    impl msg_socket::MsgOnSocket for Typename {
        ...
    }

TEST=cargo test msg_socket
TEST=cargo test msg_on_socket_derive

Change-Id: I61b672b64404523f601de1d538ebe554985a0905
Reviewed-on: https://chromium-review.googlesource.com/1565545
Commit-Ready: David Tolnay <dtolnay@chromium.org>
Commit-Ready: ChromeOS CL Exonerator Bot <chromiumos-cl-exonerator@appspot.gserviceaccount.com>
Tested-by: David Tolnay <dtolnay@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: David Tolnay <dtolnay@chromium.org>
2019-04-15 02:06:06 -07:00
David Tolnay
48ff4165d2 cargo: Sort all dependency lists in Cargo.toml
This may help reduce cases of conflicts between independent CLs each
appending a dependency at the bottom of the list, of which I hit two
today rebasing some of my open CLs.

TEST=cargo check --all-features

Change-Id: Ief10bb004cc7b44b107dc3841ce36c6b23632aed
Reviewed-on: https://chromium-review.googlesource.com/1557172
Commit-Ready: David Tolnay <dtolnay@chromium.org>
Tested-by: David Tolnay <dtolnay@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
2019-04-09 01:55:14 -07:00
David Tolnay
a7d4ea6dd0 edition: Update msg_socket to 2018 edition
Separated out of CL:1513058 to make it possible to land parts
individually while the affected crate has no other significant CLs
pending. This avoids repeatedly introducing non-textual conflicts with
new code that adds `use` statements.

TEST=cargo check
TEST=cargo check --all-features
TEST=cargo check --target aarch64-unknown-linux-gnu

Change-Id: I6d541d6d51498612c82072c64cb78eefcb2abb8c
Reviewed-on: https://chromium-review.googlesource.com/1519700
Commit-Ready: David Tolnay <dtolnay@chromium.org>
Tested-by: David Tolnay <dtolnay@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: David Tolnay <dtolnay@chromium.org>
2019-04-08 22:30:26 -07:00
David Tolnay
fe3ef7d998 edition: Update absolute paths to 2018 style
This is an easy step toward adopting 2018 edition eventually, and will
make any future CL that sets `edition = "2018"` this much smaller.

The module system changes in Rust 2018 are described here:

https://doc.rust-lang.org/edition-guide/rust-2018/module-system/path-clarity.html

Generated by running:

    cargo fix --edition --all

in each workspace, followed by bin/fmt.

TEST=cargo check
TEST=cargo check --all-features
TEST=cargo check --target aarch64-unknown-linux-gnu

Change-Id: I000ab5e69d69aa222c272fae899464bbaf65f6d8
Reviewed-on: https://chromium-review.googlesource.com/1513054
Commit-Ready: ChromeOS CL Exonerator Bot <chromiumos-cl-exonerator@appspot.gserviceaccount.com>
Tested-by: David Tolnay <dtolnay@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: David Tolnay <dtolnay@chromium.org>
2019-03-13 21:05:03 -07:00
David Tolnay
d32efefb7a macros: Format code inside of quote! invocations
Rustfmt currently does not touch the content of macro invocations. Also
it used to have a bug where if it changed indentation of a block of code
containing a multi-line macro invocation then the macro input would not
get correspondingly indented. That bug was visible across some of the
code here.

For example:

    // rustfmt decides to un-indent the surrounding block:
        let data_size_in_bytes = quote!(
            ( #( #field_types::FIELD_WIDTH as usize )+* ) / 8
        );

    // poorly formatted resulting code:
    let data_size_in_bytes = quote!(
            ( #( #field_types::FIELD_WIDTH as usize )+* ) / 8
        );

    // should have been:
    let data_size_in_bytes = quote!(
        ( #( #field_types::FIELD_WIDTH as usize )+* ) / 8
    );

TEST=cargo check crosvm
TEST=cargo test each of the three proc-macro crates
CQ-DEPEND=CL:1338507

Change-Id: Id2d456a8d85d719fbc0a65624f153f0f9df6f500
Reviewed-on: https://chromium-review.googlesource.com/1338508
Commit-Ready: David Tolnay <dtolnay@chromium.org>
Tested-by: David Tolnay <dtolnay@chromium.org>
Reviewed-by: Chirantan Ekbote <chirantan@chromium.org>
2018-11-21 05:52:46 -08:00
David Tolnay
1d0b445be2 macros: Update syn to 0.15
This brings us onto the stable API surface area for procedural macros
that stabilized in Rust 1.30, rather than the string-based shim on
older compilers.

    https://blog.rust-lang.org/2018/10/25/Rust-1.30.0.html

Intervening release notes:

- https://github.com/dtolnay/syn/releases/tag/0.13.0
- https://github.com/dtolnay/syn/releases/tag/0.14.0
- https://github.com/dtolnay/syn/releases/tag/0.15.0

TEST=cargo check crosvm
TEST=cargo test each of the three proc-macro crates
TEST=build_packages
CQ-DEPEND=CL:1340766

Change-Id: Idcf14df0225ab41423b9a8639d0bba0a63513712
Reviewed-on: https://chromium-review.googlesource.com/1338507
Commit-Ready: David Tolnay <dtolnay@chromium.org>
Tested-by: David Tolnay <dtolnay@chromium.org>
Reviewed-by: Chirantan Ekbote <chirantan@chromium.org>
2018-11-21 05:52:45 -08:00
Zach Reizner
c527c1a7e8 fix formatting in msg_on_socket_derive.rs unit test
Turns out my cargo-fmt binary was being sourced from ~/.cargo/bin, which
was very out of date. Hopefully less formatting issues come out of my
chroot now.

TEST=cargo fmt --all -- --check
BUG=None

Change-Id: I50592e2781835840dc5d589c681b3438d6de3370
Reviewed-on: https://chromium-review.googlesource.com/1324669
Commit-Ready: Zach Reizner <zachr@chromium.org>
Tested-by: Zach Reizner <zachr@chromium.org>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
2018-11-09 07:20:12 -08:00
Zach Reizner
3c71bb953e msg_socket_on_derive: use fully qualified types
The types from msg_socket were assumed to be in scope for the custom
derive implementation, which would cause mysterious compiler errors if
the custom derive was invoked in a module without msg_socket types in
scope.

This CL uses fully qualified types in the generated output to avoid
these errors.

This change also uses `extern crate msg_socket` in case the call site
doesn't have it in scope.

BUG=None
TEST=cargo test -p msg_on_socket_derive

Change-Id: Ie6443cd4ffc070d27e71de123090a58f19846472
Reviewed-on: https://chromium-review.googlesource.com/1314208
Commit-Ready: ChromeOS CL Exonerator Bot <chromiumos-cl-exonerator@appspot.gserviceaccount.com>
Tested-by: Zach Reizner <zachr@chromium.org>
Reviewed-by: Jingkui Wang <jkwang@google.com>
2018-11-07 06:35:06 -08:00
Jingkui Wang
f5d565d693 crosvm: add msg_sock.
MsgSock wraps UnixDatagram and provides simple macro to define Messages
that could be send through sock easily.

TEST=cargo test
BUG=None

Change-Id: I296fabc41893ad6a3ec42ef82dd29c3b752be8b8
Reviewed-on: https://chromium-review.googlesource.com/1255548
Commit-Ready: ChromeOS CL Exonerator Bot <chromiumos-cl-exonerator@appspot.gserviceaccount.com>
Tested-by: Jingkui Wang <jkwang@google.com>
Reviewed-by: Zach Reizner <zachr@chromium.org>
2018-10-09 21:14:12 -07:00