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

CompileBinaries Struct #214

Closed
wants to merge 29 commits into from
Closed

CompileBinaries Struct #214

wants to merge 29 commits into from

Conversation

hone
Copy link
Member

@hone hone commented Nov 30, 2021

This is a change to #199. Let's leverage some Rust types to reduce some code duplication and group the cc/ld concepts together into a single struct. This moves all the defaults into const at the top of the file. In addition, I took @edmorley's suggestion to add some help/binary checking for the musl-tools on linux as well.

Malax and others added 14 commits November 24, 2021 10:15
Co-authored-by: Ed Morley <501702+edmorley@users.noreply.github.com>
Co-authored-by: Ed Morley <501702+edmorley@users.noreply.github.com>
Co-authored-by: Ed Morley <501702+edmorley@users.noreply.github.com>
Co-authored-by: Ed Morley <501702+edmorley@users.noreply.github.com>
Co-authored-by: Ed Morley <501702+edmorley@users.noreply.github.com>
@hone hone requested review from Malax and edmorley November 30, 2021 03:10
Copy link
Member

@edmorley edmorley left a comment

Choose a reason for hiding this comment

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

Thank you for demonstrating this alternative via code - much easier to visualise! :-)

With the reduction of binaries from 4 to 2 (after dropping the *-ld variants), I feel like this is perhaps a bit over-complex for replacing two which calls?

If we wanted to simplify cross_compile_env(), then perhaps adding a single which() function that performed the .map_err and .into_os_string() would be a good middle ground?

Comment on lines 5 to 12
const MAC_BINARIES: CompilerBinaries = CompilerBinaries {
ld: Binary("x86_64-linux-musl-ld"),
cc: Binary("x86_64-linux-musl-gcc"),
};
const LINUX_BINARIES: CompilerBinaries = CompilerBinaries {
ld: Binary("musl-ld"),
cc: Binary("musl-gcc"),
};
Copy link
Member

Choose a reason for hiding this comment

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

We don't need the *-ld variants (whilst they are present in the cargo-make examples and #199, they are not needed and differ from the more commonly used configuration):
https://github.com/Malax/libcnb.rs/pull/199#discussion_r757620799

),
]);
} else if cfg!(target_os = "linux") {
// Do we want to set the env vars here?
Copy link
Member

Choose a reason for hiding this comment

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

The env vars do not need to be set on Linux, since cargo/rustc correctly finds the compiler there.
Ideally in the future it will be able to do so for the OS X musl-cross too:
rust-lang/cargo#4133

As such I think we shouldn't set env vars on Linux, since I see them as more of a workaround, rather than necessary configuration.

Copy link
Member Author

Choose a reason for hiding this comment

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

@edmorley thoughts on just keeping the which checks?

@hone
Copy link
Member Author

hone commented Nov 30, 2021

With the reduction of binaries from 4 to 2 (after dropping the *-ld variants), I feel like this is perhaps a bit over-complex for replacing two which calls?

If we wanted to simplify cross_compile_env(), then perhaps adding a single which() function that performed the .map_err and .into_os_string() would be a good middle ground?

For me the most important thing I wanted out of the PR are 2 things:

  1. const at the top
  2. reducing code duplication (since I think we also want to check the binaries for linux and maybe windows some day)

What about just keeping the Binary struct which has the which implementation and we save these as constants. I can throw a commit up to show on this PR.

@hone
Copy link
Member Author

hone commented Nov 30, 2021

I also think we should only insert env vars if the env var isn't set already.

@Malax
Copy link
Member

Malax commented Dec 1, 2021

I'd much prefer having this discussion either directly in #199 or a subsequent PR with potential improvements. It's hard to keep track of both the original PR with 150+ comments, the resulting changes and then this PR in on top.

@hone would you be fine rebasing this to main after #199 is merged?

@schneems
Copy link
Contributor

schneems commented Dec 1, 2021

I like using constants rather than magic strings. I also like putting the which behavior on a type. I also agree it's best done afterward as #199 is a moving target.

@hone
Copy link
Member Author

hone commented Dec 1, 2021

I'd much prefer having this discussion either directly in #199 or a subsequent PR with potential improvements. It's hard to keep track of both the original PR with 150+ comments, the resulting changes and then this PR in on top.

@hone would you be fine rebasing this to main after #199 is merged?

yeah, I'm fine either way. None of these are blocking changes to #199. My original hope is this was going to be a quick merge in or reject.

@Malax Malax force-pushed the malax/cargo branch 2 times, most recently from 31ddae8 to fb16494 Compare December 2, 2021 09:35
Base automatically changed from malax/cargo to main December 3, 2021 08:50
@edmorley
Copy link
Member

edmorley commented Dec 9, 2021

@hone Can this be closed out? Comparing the implementation here with the one that landed in #199, I see many of the suggestions were incorporated, plus the module was refactored quite a bit on top:
https://github.com/Malax/libcnb.rs/blob/main/libcnb-cargo/src/cross_compile.rs

As such, I don't think there is anything else more we need from this PR?

@hone
Copy link
Member Author

hone commented Dec 13, 2021

Yeah, let's close this out for now. I can open up a new PR if I want to bring some of these ideas forward.

@hone hone closed this Dec 13, 2021
@edmorley edmorley deleted the cargo-command branch December 13, 2021 17:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants