-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
feat: runtime musl/glibc detection for correct libc variant selection #8490
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
Merged
Merged
Changes from 2 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
968cfda
feat: runtime musl/glibc detection for correct libc variant selection
jdx a68a164
fix: address review feedback for musl detection
jdx 049a44d
fix(backend): use lockfile fallback for aqua platform lookup
jdx 142f017
fix: remove musl→glibc lockfile fallback that installs wrong binary
jdx 7874b45
fix: use ldd-based musl detection and update e2e test for 7 platforms
jdx bd5f8d2
fix: avoid shelling out for musl detection, use filesystem checks
jdx File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,2 @@ | ||
| backends = ["aqua:snyk/cli", "asdf:nirfuchs/asdf-snyk"] | ||
| backends = ["aqua:snyk/cli", "github:snyk/cli", "asdf:nirfuchs/asdf-snyk"] | ||
| description = "Snyk CLI scans and monitors your projects for security vulnerabilities" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -38,13 +38,20 @@ impl Platform { | |
| } | ||
| } | ||
|
|
||
| /// Get the current platform from system information | ||
| /// Get the current platform from system information. | ||
| /// On Linux, detects musl vs glibc at runtime and sets the qualifier accordingly. | ||
| pub fn current() -> Self { | ||
| let settings = Settings::get(); | ||
| let os = settings.os().to_string(); | ||
| let qualifier = if os == "linux" && is_musl_system() { | ||
| Some("musl".to_string()) | ||
| } else { | ||
| None | ||
| }; | ||
| Platform { | ||
| os: settings.os().to_string(), | ||
| os, | ||
| arch: settings.arch().to_string(), | ||
| qualifier: None, | ||
| qualifier, | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -117,7 +124,9 @@ impl Platform { | |
| pub fn common_platforms() -> Vec<Self> { | ||
| vec![ | ||
| Platform::parse("linux-x64").unwrap(), | ||
| Platform::parse("linux-x64-musl").unwrap(), | ||
| Platform::parse("linux-arm64").unwrap(), | ||
| Platform::parse("linux-arm64-musl").unwrap(), | ||
| Platform::parse("macos-x64").unwrap(), | ||
| Platform::parse("macos-arm64").unwrap(), | ||
| Platform::parse("windows-x64").unwrap(), | ||
|
|
@@ -174,6 +183,32 @@ impl From<&str> for Platform { | |
| } | ||
| } | ||
|
|
||
| /// Detect whether the system uses musl libc at runtime. | ||
| /// Checks for the musl dynamic linker in /lib, which is present on musl-based | ||
| /// systems like Alpine Linux. This is a runtime check (not compile-time) so a | ||
| /// statically-linked or musl-built mise binary running on a glibc system will | ||
| /// correctly detect glibc, and vice versa. | ||
| #[cfg(target_os = "linux")] | ||
| fn is_musl_system() -> bool { | ||
| use std::sync::LazyLock; | ||
| static IS_MUSL: LazyLock<bool> = LazyLock::new(|| { | ||
| if let Ok(entries) = std::fs::read_dir("/lib") { | ||
| for entry in entries.flatten() { | ||
| if entry.file_name().to_string_lossy().starts_with("ld-musl-") { | ||
| return true; | ||
| } | ||
| } | ||
| } | ||
| false | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The logic for checking for musl can be made more concise and idiomatic by using iterator methods like std::fs::read_dir("/lib")
.map(|entries| {
entries.flatten().any(|entry| {
entry
.file_name()
.to_string_lossy()
.starts_with("ld-musl-")
})
})
.unwrap_or(false) |
||
| }); | ||
| *IS_MUSL | ||
| } | ||
|
cursor[bot] marked this conversation as resolved.
|
||
|
|
||
| #[cfg(not(target_os = "linux"))] | ||
| fn is_musl_system() -> bool { | ||
| false | ||
| } | ||
|
|
||
| #[cfg(test)] | ||
| mod tests { | ||
| use super::*; | ||
|
|
@@ -283,11 +318,13 @@ mod tests { | |
| #[test] | ||
| fn test_common_platforms() { | ||
| let platforms = Platform::common_platforms(); | ||
| assert_eq!(platforms.len(), 5); | ||
| assert_eq!(platforms.len(), 7); | ||
|
|
||
| let keys: Vec<String> = platforms.iter().map(|p| p.to_key()).collect(); | ||
| assert!(keys.contains(&"linux-x64".to_string())); | ||
| assert!(keys.contains(&"linux-x64-musl".to_string())); | ||
| assert!(keys.contains(&"linux-arm64".to_string())); | ||
| assert!(keys.contains(&"linux-arm64-musl".to_string())); | ||
| assert!(keys.contains(&"macos-x64".to_string())); | ||
| assert!(keys.contains(&"macos-arm64".to_string())); | ||
| assert!(keys.contains(&"windows-x64".to_string())); | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.