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 the GetPlatformInfo action #55

Closed
wants to merge 1 commit into from
Closed

Add the GetPlatformInfo action #55

wants to merge 1 commit into from

Conversation

realtimetodie
Copy link
Contributor

Adds the GetPlatformInfo action.

The implementation is following the Python cpython runtime, but is not as backwards compatible.

Known compatibility requirements

  • MacOS: >=10.10
  • Windows: >=7 (?)

Comparison matrix table of the protocol buffer properties (source code)

Property grr rrg grr rrg grr rrg
Linux Linux MacOS MacOS Windows Windows
system Yes Yes Yes Yes Yes Yes (*)
node Yes Yes Yes Yes Yes Yes
release Yes Yes (*) Yes Yes Yes Yes
version Yes Yes (*) Yes Yes (*) Yes Yes (*)
machine Yes Yes Yes Yes Yes Yes (*)
kernel Yes Yes Yes Yes Yes Yes
fqdn Yes Yes Yes Yes Yes Yes
install_date Yes Yes Yes
libc_ver Yes (*)
architecture Yes Yes Yes Yes Yes Yes
pep425tag Yes Yes Yes

Differences (marked with an asterisk * in the comparison matrix table above)

  • Linux: The grr client uses the Python distro package to generate human readable values for the release and version properties. As the library is quite extensive (source code), the raw values from libc::utsname are used instead. The conversion to a human readable format should be done on the server.
  • The pep425tag property is always unset, as it only exists on Python to identify the unique signature of a Python runtime (PEP 425 specification).
  • Linux: The libc_version property is only set, if the client was compiled against the GNU libc library.
  • MacOS: The release property is hardcoded and set to the value "OSX" by default, similar to the grr client (source code).
  • MacOS: The version property is set using the NSProcessInfo.processInfo function. The interface containing the operating system version is available equal to or after MacOS 10.10. In the Python cpython runtime implementation, the MacOS version is read using the SystemVersion.plist file (source code).
  • Windows: The system property is hardcoded and set to the value "Windows" by default.
  • Windows: The version property does not include the service pack version. The service pack version can be read using the GetVersionExA function, but this function might be altered or unavailable for releases after Windows 8.1. The concept of service packs is obsolete since Windows 10.
  • Windows: The machine property is set using the GetVersion function and uses the SYSTEM_INFO structure to determine the processor architecture.

Example - Linux

PlatformInfo { system: "Linux", node: "fv-az371-529", release: "5.15.0-1022-azure", version: Some("#27~20.04.1-Ubuntu SMP Mon Oct 17 02:03:50 UTC 2022"), machine: Some("x86_64"), kernel: "5.15.0-1022-azure", fqdn: "fv-az371-529.ipdn00qvwfrujbrcphh0gwusye.dx.internal.cloudapp.net", install_date: Some(SystemTime { tv_sec: 1667763649, tv_nsec: 0 }), libc_ver: Some("2.31"), architecture: "x86_64" }

Example - MacOS

PlatformInfo { system: "Darwin", node: "Mac-1667763736626.local", release: "OSX", version: Some("12.6.1"), machine: Some("x86_64"), kernel: "21.6.0", fqdn: "mac-1667763736626.local", install_date: Some(SystemTime { tv_sec: 1667763649, tv_nsec: 480097701 }), libc_ver: None, architecture: "x86_64" }

Example - Windows

PlatformInfo { system: "Windows", node: "fv-az449-397", release: "10", version: Some("10.0 (20348)"), machine: Some("x86_64"), kernel: "10.0.20348 Build 20348", fqdn: "fv-az449-397", install_date: Some(SystemTime { intervals: 133117186730000000 }), libc_ver: None, architecture: "x86_64" }

References

Resolves #6

Copy link
Member

@panhania panhania left a comment

Choose a reason for hiding this comment

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

Thanks for this pull request, a lot of solid research! I left some initial comments that can shape how the overall code looks in the future, so not diving into details yet.

Comment on lines +1 to +10
fn main() {
#[cfg(all(target_os = "linux", feature = "action-platform-info"))]
{
println!("cargo:rerun-if-changed=src/action/libc_version.c");

cc::Build::new()
.file("src/action/libc_version.c")
.compile("liblibc_version.a");
}
}
Copy link
Member

Choose a reason for hiding this comment

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

I am affraid build script is not an option — this does not play well with our internal build infrastructure (for rrg-proto I already have to do some awkward workarounds).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, we can scrap the build script. The libc::gnu_get_libc_version function is now available in the standard library.

Comment on lines +49 to +50
cocoa = { git = "https://github.com/servo/core-foundation-rs.git", rev = "786895643140fa0ee4f913d7b4aeb0c4626b2085", optional = true }
objc = { version = "0.2", optional = true }
Copy link
Member

Choose a reason for hiding this comment

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

These seem like a quite heavy dependencies, I wonder if there is a way to avoid these. Moreover, I would prefer not to depend on anything that is not on crates.io because of our internal build infrastructure.

Comment on lines +1 to +14
#include <features.h>
#ifdef __GNU_LIBRARY__
#include <gnu/libc-version.h>
#else
#include <stddef.h>
#endif

const char *libc_version(void) {
#ifdef __GNU_LIBRARY__
return gnu_get_libc_version();
#else
return NULL;
#endif
}
Copy link
Member

Choose a reason for hiding this comment

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

What is the benefit over libc::gnu_get_libc_version?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, excellent. I did not know that the gnu_get_* APIs were added recently

rust-lang/libc@f415078

Comment on lines +76 to +77
/// The system platform (Windows|Darwin|Linux).
system: String,
Copy link
Member

Choose a reason for hiding this comment

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

Why not an enum?

/// The architecture of this binary. (Note this can be different from
/// the machine architecture in the case of a 32 bit binary running
/// on a 64 bit system)
architecture: String,
Copy link
Member

Choose a reason for hiding this comment

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

Since this just uses std::env::consts::ARCH this can be typed as &'static str.

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.

Implement the GetPlatformInfo action
2 participants