Skip to content

Conversation

@sno2
Copy link
Contributor

@sno2 sno2 commented Oct 23, 2022

Ref: https://nodejs.org/api/os.html#osmachine

Please wait on CI/CD, not sure about Darwin stuff and I don't have a mac to test it on.

@github-actions github-actions bot added packages:bun needs tests Something that needs more testing labels Oct 23, 2022
@sno2
Copy link
Contributor Author

sno2 commented Oct 26, 2022

Someone responded to my question related to finding the machine on darwin (kernel in the Zig discord):

Ah, I think that’s just the “hw.cputype” property on OSX’s sysctl
I have it somewhere in my Analyzer KEXT
I imagine you’re doing this from within Zig via the C headers

yeah it's hw.cputype; you're going to probably have to make use of the machine.h header:

#define CPU_ARCH_MASK           0xff000000      /* mask for architecture bits */
#define CPU_ARCH_ABI64          0x01000000      /* 64 bit ABI */
#define CPU_ARCH_ABI64_32       0x02000000      /* ABI for 64-bit hardware with 32-bit types; LP32 */

#define CPU_TYPE_X86            ((cpu_type_t) 7)
#define CPU_TYPE_ARM            ((cpu_type_t) 12)
#define CPU_TYPE_ARM64          (CPU_TYPE_ARM | CPU_ARCH_ABI64)
#define CPU_TYPE_ARM64_32       (CPU_TYPE_ARM | CPU_ARCH_ABI64_32)

then the final type should be something like:

cpu_type_t cputype_aligned = cputype & CPU_ARCH_MASK;

if (cputype_aligned == CPU_TYPE_X86)
   /* ... */
 

should also probably check if the system is 64-bit capable
via hw.cpu64bit_capable I think

Going to dissect this and hopefully use it to implement the behavior in this PR when I find some time.

@Jarred-Sumner
Copy link
Collaborator

if all we want is CPU_ARCH

bun is statically compiled

we can just use

if (Environment.isAARCH64)
    return "aarch64";
else if (Environment.isX64) 
   return "x64";

etc

@sno2
Copy link
Contributor Author

sno2 commented Oct 26, 2022

Hmm yeah, not sure about all those other options, though. I guess we would have to ship specific executables to run on those archs so it's fine to just include aarch/x86_64 at comptime.

@sno2 sno2 requested a review from Jarred-Sumner October 30, 2022 14:40
@sno2
Copy link
Contributor Author

sno2 commented Nov 8, 2022

Alright, I renamed the option to arm64 as per the uname Wikipedia page: aarch64 is only possible on a Raspberry PI which I don't suppose we will support anytime soon.

@jwhear
Copy link
Contributor

jwhear commented Feb 17, 2023

Fixes #1981

@jwhear jwhear requested review from jwhear and removed request for Jarred-Sumner February 17, 2023 22:54
@jwhear
Copy link
Contributor

jwhear commented Feb 17, 2023

@sno2 Thank you for this PR and sorry about the delay. I am interested in getting this merged up once we get builds passing.

@jwhear jwhear merged commit 963bb54 into oven-sh:main Feb 18, 2023
@sno2 sno2 deleted the feat/os-machine branch February 24, 2023 02:31
@jwhear jwhear mentioned this pull request Feb 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs tests Something that needs more testing

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants