Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix windows build error #17753

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

VishvaWang
Copy link

@VishvaWang VishvaWang commented May 15, 2024

Problem:
When compiling on the Windows platform, the following error occurs:

error[E0599]: no method named `set_reuseport` found for struct `TcpSocket` in the current scope
   --> consensus\core\src\network\tonic_network.rs:589:44
    |
589 |                     if let Err(e) = socket.set_reuseport(true) {
    |                                            ^^^^^^^^^^^^^ help: there is a method with a similar name: `set_reuseaddr`

Cause:
The set_reuseport method in the relevant dependency library uses the following conditional compilation:

#[cfg(all(unix, not(target_os = "solaris"), not(target_os = "illumos")))]
  #[cfg_attr(
      docsrs,
      doc(cfg(all(unix, not(target_os = "solaris"), not(target_os = "illumos"))))
  )]
  pub fn set_reuseport(&self, reuseport: bool) -> io::Result<()> {
      self.inner.set_reuse_port(reuseport)
  }

Therefore, this method is not compiled on Windows.

Solution:
Use the same compilation condition on the code block that uses set_reuseport.

#[cfg(all(unix, not(target_os = "solaris"), not(target_os = "illumos")))]
if let Err(e) = socket.set_reuseport(true) {
    // handle error
}

Due to the use of conditional compilation for the set_reuseport method, it will not be compiled on certain systems (such as Windows). Use the same conditional compilation tag to ensure that this conditional branch is also not compiled when the set_reuseport method is not compiled. This can fix compilation errors on specific systems.
Copy link

vercel bot commented May 15, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
sui-docs ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 15, 2024 10:52am

Copy link

vercel bot commented May 15, 2024

@VishvaWang is attempting to deploy a commit to the Mysten Labs Team on Vercel.

A member of the Team first needs to authorize it.

@arun-koshy
Copy link
Contributor

This may have been already addressed in #17752, do you mind rebasing against main and seeing if you still have issues?

@mwtian mwtian changed the title fix-windews-build-error Fix windows build error May 31, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants