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

Add daita as a custom config name #6202

Open
wants to merge 9 commits into
base: wireguard-go-rs
Choose a base branch
from

Conversation

MarkusPettersson98
Copy link
Contributor

@MarkusPettersson98 MarkusPettersson98 commented Apr 30, 2024

This PR adds support for gating DAITA behind a cfg option. This makes it way easier to track what code is strictly DAITA-related, as well as enabling DAITA support on other platforms down the line.

This PR also changes the build chain of the app on Android, Linux and macOS.

  • On Linux and macOS, libwg is now distributed as a shared library, which is how wireguard-go currently is built for Android.
  • On all of the above platforms, wireguard-go is now a submodule in the app repository. This means that it has to be checkout out in order to build the app on these platforms. This has been detailed in the general build instructions.

This fixes DES-937.


This change is Reviewable

Copy link

linear bot commented Apr 30, 2024

Copy link
Contributor

@Serock3 Serock3 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One big concern with making DAITA a feature is that you would not be able to use --all-features (on platforms without DAITA) anymore. The DAITA feature would have to be enabled on Windows and Linux and disabled on other platforms, and it would be up to the developer to know which platforms have the feature, otherwise the app will not build.

It seems that features simply cannot be specified per platform, it is a fundamental limitation of cargo. You cannot specify which features exists or are enabled by default per platform. It is not possible to get around this using build.rs either, as feature resolution is done before the build scripts are run. You can set cfg variables like we do with wireguard_go in talpid-wireguard, but this can't affect which features are enabled in dependencies.

I have thought a lot about how to get around this, but it may be the case that the only proper solution is to simply abandon this PR and keep the raw #[cfg(any(target_os = "windows", target_os = "linux"))] gates, unfortunately.

Copy link
Contributor

@hulthe hulthe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed 64 of 64 files at r1, all commit messages.
Reviewable status: all files reviewed, 5 unresolved discussions (waiting on @MarkusPettersson98)


mullvad-management-interface/build.rs line 7 at r1 (raw file):

    // Enable Daita by default on Linux and Windows.
    println!("cargo:rustc-check-cfg=cfg(daita)");

should be double :s, i thought it would reject the single-color syntax since check-cfg is a newly added thing 🤔


mullvad-relay-selector/build.rs line 5 at r1 (raw file):

    // Enable Daita by default on Linux and Windows.
    println!("cargo:rustc-check-cfg=cfg(daita)");

scobido doubleido, etc
maybe do a search replace


talpid-wireguard/src/lib.rs line 70 at r1 (raw file):

/// TODO: Document
/// TODO: Rename

👁️ 👄 👁️


wireguard-go-rs/Cargo.lock line 1 at r1 (raw file):

# This file is automatically @generated by Cargo.

wgrs is part of the workspace, this file should be deleted


wireguard-go-rs/libwg/wireguard-go line 1 at r1 (raw file):

Subproject commit 1e3bc447c174e243df151cf668ba8eab36739ce0

I guess update this after the other PR is merged

Copy link
Contributor Author

@MarkusPettersson98 MarkusPettersson98 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewable status: all files reviewed, 5 unresolved discussions (waiting on @hulthe)


mullvad-management-interface/build.rs line 7 at r1 (raw file):

Previously, hulthe (Joakim Hulthe) wrote…

should be double :s, i thought it would reject the single-color syntax since check-cfg is a newly added thing 🤔

Done. That's a bit weird aye, but good catch!


mullvad-relay-selector/build.rs line 5 at r1 (raw file):

Previously, hulthe (Joakim Hulthe) wrote…

scobido doubleido, etc
maybe do a search replace

Done.


talpid-wireguard/src/lib.rs line 70 at r1 (raw file):

Previously, hulthe (Joakim Hulthe) wrote…

👁️ 👄 👁️

Lmao, reverting this


wireguard-go-rs/Cargo.lock line 1 at r1 (raw file):

Previously, hulthe (Joakim Hulthe) wrote…

wgrs is part of the workspace, this file should be deleted

🤦


wireguard-go-rs/libwg/wireguard-go line 1 at r1 (raw file):

Previously, hulthe (Joakim Hulthe) wrote…

I guess update this after the other PR is merged

Yup

@MarkusPettersson98 MarkusPettersson98 force-pushed the add-daita-cfg-flag branch 2 times, most recently from 13d49d4 to a49697f Compare May 29, 2024 14:29
@Serock3 Serock3 force-pushed the wireguard-go-rs branch 2 times, most recently from b13dcc3 to 09f121c Compare June 3, 2024 13:28
Copy link
Contributor Author

@MarkusPettersson98 MarkusPettersson98 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewable status: 66 of 67 files reviewed, 8 unresolved discussions (waiting on @hulthe and @Serock3)


mullvad-daemon/build.rs line 40 at r5 (raw file):

Previously, Serock3 (Sebastian Holmin) wrote…

"when development"?

Done Updated the text


wireguard-go-rs/build.rs line 43 at r5 (raw file):

Previously, Serock3 (Sebastian Holmin) wrote…

Great that you documented this. Perhaps we could even be more specific about the double symbol issue, to make it easier for future devs to find other solutions.

Done clarified that part 😊


wireguard-go-rs/build-wireguard-go.sh line 51 at r5 (raw file):

Previously, Serock3 (Sebastian Holmin) wrote…

I left this comment, though it's a very inconsequential style issue. We should remove the comment or implement it.

Since the output most likely will be consumed by cargo, and would seldom be seen by a human, I think it's fine to just not implement it here. At least for now 😊


wireguard-go-rs/build-wireguard-go.sh line 97 at r5 (raw file):

Previously, Serock3 (Sebastian Holmin) wrote…

Do we need two copies of the object file? Is it not ok to just move it instead?

Kind of, yes. 😢 cargo won't look outside of target for stuff that we want to link against, which we let cargo know about via the rustc-link-search instruction. This is needed to do to make debug builds / cargo test work as expected. However, OUT_DIR changes between compilations, which means that rebuilding the project becomes kind of expensive (since we have to build wireguard-go each time we hit cargo check/build/test. Thus, it is cheaper to dump it into a known location build/lib/<arch> and copy it from there to OUT_DIR as needed.

Copy link
Contributor

@Serock3 Serock3 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed 24 of 24 files at r6, all commit messages.
Reviewable status: all files reviewed, 5 unresolved discussions (waiting on @hulthe)


wireguard-go-rs/build.rs line 43 at r5 (raw file):

Previously, MarkusPettersson98 (Markus Pettersson) wrote…

Done clarified that part 😊

Nice!


wireguard-go-rs/build-wireguard-go.sh line 51 at r5 (raw file):

Previously, MarkusPettersson98 (Markus Pettersson) wrote…

Since the output most likely will be consumed by cargo, and would seldom be seen by a human, I think it's fine to just not implement it here. At least for now 😊

Sure


wireguard-go-rs/build-wireguard-go.sh line 97 at r5 (raw file):

Previously, MarkusPettersson98 (Markus Pettersson) wrote…

Kind of, yes. 😢 cargo won't look outside of target for stuff that we want to link against, which we let cargo know about via the rustc-link-search instruction. This is needed to do to make debug builds / cargo test work as expected. However, OUT_DIR changes between compilations, which means that rebuilding the project becomes kind of expensive (since we have to build wireguard-go each time we hit cargo check/build/test. Thus, it is cheaper to dump it into a known location build/lib/<arch> and copy it from there to OUT_DIR as needed.

Thanks for clarifying 😊

Copy link
Contributor

@Serock3 Serock3 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:lgtm:

Reviewable status: all files reviewed, 5 unresolved discussions (waiting on @hulthe)

@MarkusPettersson98 MarkusPettersson98 force-pushed the add-daita-cfg-flag branch 3 times, most recently from 841ccb7 to 239afa8 Compare June 5, 2024 11:10
@MarkusPettersson98 MarkusPettersson98 changed the title Add daita as a Cargo feature Add daita as a custom config name Jun 5, 2024
@MarkusPettersson98 MarkusPettersson98 force-pushed the add-daita-cfg-flag branch 4 times, most recently from 036c314 to 8aa69c1 Compare June 5, 2024 12:33
@MarkusPettersson98 MarkusPettersson98 marked this pull request as ready for review June 5, 2024 12:36
@MarkusPettersson98 MarkusPettersson98 force-pushed the add-daita-cfg-flag branch 2 times, most recently from d248a6b to a74161b Compare June 5, 2024 12:44
Copy link
Contributor

@Serock3 Serock3 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed 15 of 15 files at r7, 2 of 2 files at r8, all commit messages.
Reviewable status: all files reviewed, 6 unresolved discussions (waiting on @hulthe and @MarkusPettersson98)


ci/buildserver-build.sh line 166 at r7 (raw file):

    git checkout "$ref"
    git submodule update
    git submodule update --init --recursive --depth=1 wireguard-go-rs || true

What does the || true part do? My guess is that it swallows error non-zero exit codes. Would it not be equivalent to add a;?

MarkusPettersson98 and others added 9 commits June 5, 2024 16:15
Gate DAITA compilation on `"cargo::rustc-cfg=daita"` emitted in build
files per platform.
Distribute the app with `libwg.so`

Embed absolute rpath for dev builds on platforms which dynamically links
`libwg`

Add WorkingDirectory key to plist file to load `libwg.so` correctly on
macOS.
Align `build-apk.sh` with `build.sh`
Fix the build server scripts for Linux and Android by checking out the
wireguard-go submodule.
Also:
- Use u64 instead of *mut void as log context
- Make Tunnel::set_config take a &mut self
- Use dyn Error instead of i32s for wg errors
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

4 participants