Skip to content

Need --cfg=libc_align in v0.3.16 but not v0.3.15; why? #130

Closed
@wchargin

Description

@wchargin

Hi! I transitively use socket2 as part of a Rust project built with
Bazel. I’m noting that socket2 builds successfully for me at v0.3.15,
but not at version v0.3.16 (released today) unless I specify the extra
flag --cfg=libc_align. I’m a bit hesitant to do so because it feels
low-level and platform specific, so I wanted to check and see whether
this is expected or whether there’s a better solution?

Here is a repro repo. You do need to have Bazel to repro, but you
don’t need any additional setup. The error is:

INFO: From Compiling Rust lib socket2 v0.3.16 (7 files):
error[E0063]: missing field `__align` in initializer of `libc::in6_addr`
   --> external/raze__socket2__0_3_16/src/sockaddr.rs:243:25
    |
243 |         let sin6_addr = in6_addr {
    |                         ^^^^^^^^ missing `__align`

error: aborting due to previous error

For more information about this error, try `rustc --explain E0063`.
ERROR: /HOMEDIR/.cache/bazel/_bazel_wchargin/e6b2d93af64d3456b38c9c9d2131e939/external/raze__socket2__0_3_16/BUILD.bazel:33:13: output 'external/raze__socket2__0_3_16/libsocket2--1560485693.rlib' was not created
ERROR: /HOMEDIR/.cache/bazel/_bazel_wchargin/e6b2d93af64d3456b38c9c9d2131e939/external/raze__socket2__0_3_16/BUILD.bazel:33:13: not all outputs were created or valid
Target @raze__socket2__0_3_16//:socket2 failed to build
Use --verbose_failures to see the command lines of failed build steps.
INFO: Elapsed time: 0.707s, Critical Path: 0.20s
INFO: 2 processes: 1 internal, 1 linux-sandbox.
FAILED: Build did NOT complete successfully

I dug far enough into the libc structure to see the align/no_align
modules and guess that this cfg flag would probably fix it; it does.

The failing Bazel action, with directory structure and command line
invocation, is here (in a Gist because it has some long paths):
https://gist.github.com/wchargin/4da947cf43d2a241cfffb89873788a82

In all cases, the libc dependency is at version 0.2.80. But I note
that socket2 v0.3.15 depends on libc with default features, whereas
in v0.3.16 it depends on the align feature:

$ cargo tree -e features --manifest-path socket2-0.3.15/Cargo.toml
socket2-libc-align-demo v0.0.0 (/HOMEDIR/git/socket2-libc-align-demo/socket2-0.3.15)
└── socket2 feature "default"
    └── socket2 v0.3.15
        ├── cfg-if feature "default"
        │   └── cfg-if v0.1.10
        └── libc feature "default"
            ├── libc v0.2.80
            └── libc feature "std"
                └── libc v0.2.80
$ cargo tree -e features --manifest-path socket2-0.3.16-default/Cargo.toml
socket2-libc-align-demo v0.0.0 (/HOMEDIR/git/socket2-libc-align-demo/socket2-0.3.16-default)
└── socket2 feature "default"
    └── socket2 v0.3.16
        ├── cfg-if feature "default"
        │   └── cfg-if v0.1.10
        ├── libc feature "align"
        │   └── libc v0.2.80
        └── libc feature "default"
            ├── libc v0.2.80
            └── libc feature "std"
                └── libc v0.2.80
$ cargo tree -e features --manifest-path socket2-0.3.16-libc-align/Cargo.toml
socket2-libc-align-demo v0.0.0 (/HOMEDIR/git/socket2-libc-align-demo/socket2-0.3.16-libc-align)
└── socket2 feature "default"
    └── socket2 v0.3.16
        ├── cfg-if feature "default"
        │   └── cfg-if v0.1.10
        ├── libc feature "align"
        │   └── libc v0.2.80
        └── libc feature "default"
            ├── libc v0.2.80
            └── libc feature "std"
                └── libc v0.2.80

So I’m hoping that you can help me understand what caused this change,
why it requires me to build with --cfg=libc_align, (maybe) why it’s
needed with Bazel but not with Cargo (though I understand if that’s
outside your purview/expertise), and whether I should feel comfortable
doing so? I want to build for non-Linux platforms, too, eventually.

I’m on rustc 1.47.0 (18bf6b4f0 2020-10-07) on Debian-like Linux.

Thanks much!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions