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

netdog: Enable conditional compilation based on network backend #2750

Merged
merged 2 commits into from
Jan 30, 2023

Conversation

zmrow
Copy link
Contributor

@zmrow zmrow commented Jan 25, 2023

Issue number:
Related to #2449

Description of changes:
This set of temporary changes enables conditional compilation of netdog based on network backend. "Temporary" in this case means that these changes (similar to those in #2741 ) will be removed once systemd-networkd development has finished.

A new function emit_net_backend_cfgs() has been added to netdog's build.rs that triggers off the SYSTEMD_NETWORKD environment variable that has been added to the build environment. The crate can now use the following to conditionally compile code:

#[cfg(net_backend = "systemd-networkd")]
{ do stuff }

Testing done:
Added the following blurb to netdog generate-net-config to be conditionally compiled:

#[cfg(net_backend = "systemd-networkd")]
{
    eprintln!("I'm on systemd-networkd!!!")
}
  • Build and boot an aws-k8s-1.22 image that runs properly and connects to the cluster - do not observe the above lines in the journal
  • Build and locally boot an aws-dev variant. I added an early dependency on console-getty.service to the preconfigured.target since I knew early services would be broken but I still wanted to be able to poke around and verify the above. With the systemd-networkd build flag, I observed the above message in the journal. Without the flag, the message didn't show up.
Starting Network Configuration...
[    2.081577] netdog[901]: I'm on systemd-networkd!!!

Terms of contribution:

By submitting this pull request, I agree that this contribution is dual-licensed under the terms of both the Apache License, version 2.0, and the MIT license.

This commit sets the `SYSTEMD_NETWORKD` environment variable during the
RPM build stage, which is useful to trigger on and emit additional Rust
cfgs for conditional compilation.
@zmrow zmrow requested review from bcressey, webern and yeazelm January 25, 2023 00:00
Copy link
Contributor

@bcressey bcressey left a comment

Choose a reason for hiding this comment

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

I'm on the fence about merging this in the current state, since there's no real functionality tied to it, and it seems like an easy patch to maintain on a feature branch. If you can scope it down to netdog then it's probably OK.

sources/bottlerocket-variant/src/lib.rs Outdated Show resolved Hide resolved
This commit enables conditional compilation of `netdog` based on the
network backend.  A temporary function has been added that reads the
environment variable `SYSTEMD_NETWORKD`, and emits additional cfgs to
direct compilation.  This environment variable will be passed to the
build if a user has enabled the build flag to use systemd-networkd
rather than wicked in their variant.
@zmrow zmrow force-pushed the emit-net-backend-cfgs branch from f6e9d53 to 8a47c02 Compare January 26, 2023 23:30
@zmrow zmrow changed the title Enable Rust conditional compilation based on network backend netdog: Enable Rust conditional compilation based on network backend Jan 26, 2023
@zmrow
Copy link
Contributor Author

zmrow commented Jan 26, 2023

^ Scoped these changes to netdog per @bcressey

Comment on lines +37 to +39
NET_BACKEND_OVERRIDE
} else {
DEFAULT_NET_BACKEND
Copy link
Contributor

Choose a reason for hiding this comment

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

very much a nit: our other cfg! compile guards use lowercase, kebab-case strings, e.g. aws-k8s etc. So these screaming snake cases might look a little out of place at their usage sites.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The actual cfgs emitted will be: wicked and systemd-networkd. These screaming snake case constants are set to those static strings. :)

Copy link
Contributor

Choose a reason for hiding this comment

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

ah i see 👍

@zmrow zmrow changed the title netdog: Enable Rust conditional compilation based on network backend netdog: Enable conditional compilation based on network backend Jan 27, 2023
@zmrow zmrow merged commit f8f988e into bottlerocket-os:develop Jan 30, 2023
@zmrow zmrow deleted the emit-net-backend-cfgs branch January 30, 2023 17:45
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.

3 participants