Dr-Noob / cpufetch

Simple yet fancy CPU architecture fetching tool
GNU General Public License v2.0
1.83k stars 100 forks source link

Build is broken on macOS (x86_64 and ppc) #168

Closed barracuda156 closed 1 year ago

barracuda156 commented 1 year ago

So in addition to PPC being broken https://github.com/Dr-Noob/cpufetch/issues/167 macOS builds on Intel also fail:

src/x86/cpuid.c:368:11: error: implicit declaration of function 'bind_to_cpu' is invalid in C99 [-Werror,-Wimplicit-function-declaration]
        if(!bind_to_cpu(i)) {
            ^
  src/x86/cpuid.c:397:9: error: implicit declaration of function 'bind_to_cpu' is invalid in C99 [-Werror,-Wimplicit-function-declaration]
      if(!bind_to_cpu(core_id)) {
          ^
  2 errors generated.
  src/x86/apic.c:115:3: error: use of undeclared identifier 'cpu_set_t'
    cpu_set_t original_mask;
    ^
  src/x86/apic.c:116:6: error: implicit declaration of function 'sched_getaffinity' is invalid in C99 [-Werror,-Wimplicit-function-declaration]
    if(sched_getaffinity(0, sizeof(original_mask), &original_mask) == -1) {
       ^
  src/x86/apic.c:116:34: error: use of undeclared identifier 'original_mask'
    if(sched_getaffinity(0, sizeof(original_mask), &original_mask) == -1) {
                                   ^
  src/x86/apic.c:116:51: error: use of undeclared identifier 'original_mask'
    if(sched_getaffinity(0, sizeof(original_mask), &original_mask) == -1) {
                                                    ^
  src/x86/apic.c:122:9: error: implicit declaration of function 'bind_to_cpu' is invalid in C99 [-Werror,-Wimplicit-function-declaration]
      if(!bind_to_cpu(i)) {
          ^
  src/x86/apic.c:149:7: error: implicit declaration of function 'sched_setaffinity' is invalid in C99 [-Werror,-Wimplicit-function-declaration]
    if (sched_setaffinity (0, sizeof(original_mask), &original_mask) == -1) {
        ^
  src/x86/apic.c:149:7: note: did you mean 'sched_getaffinity'?
  src/x86/apic.c:116:6: note: 'sched_getaffinity' declared here
    if(sched_getaffinity(0, sizeof(original_mask), &original_mask) == -1) {
       ^
  src/x86/apic.c:149:36: error: use of undeclared identifier 'original_mask'
    if (sched_setaffinity (0, sizeof(original_mask), &original_mask) == -1) {
                                     ^
  src/x86/apic.c:149:53: error: use of undeclared identifier 'original_mask'
    if (sched_setaffinity (0, sizeof(original_mask), &original_mask) == -1) {
                                                      ^
  src/x86/apic.c:353:44: warning: unused parameter 'first_core' [-Wunused-parameter]
  bool fill_apic_ids(uint32_t* apic_ids, int first_core, int n, bool x2apic_id) {
                                             ^
  1 warning and 8 errors generated.
  make: *** [cpufetch] Error 1

Pretty much broken for every macOS version: https://ports.macports.org/port/cpufetch/details

p-linnane commented 1 year ago

Confirming this from the Homebrew side as well: https://github.com/Homebrew/homebrew-core/actions/runs/3849686797/jobs/6559040414

Schamschula commented 1 year ago

It so happens that I updated the MacPorts Portfile under Monterey on an M1 machine, which is one of only two builds that succeeded (arm64 under Monterey and Ventura).

barracuda156 commented 1 year ago

It so happens that I updated the MacPorts Portfile under Monterey on an M1 machine, which is one of only two builds that succeeded (arm64 under Monterey and Ventura).

@Schamschula PPC build should be fixed with my PR https://github.com/macports/macports-ports/pull/17225 – at least on Rosetta all good:

10:Dr-Noob-cpufetch-49941b1 svacchanda$ port -v installed cpufetch
The following ports are currently installed:
  cpufetch @1.03_0 (active) requested_variants='' platform='darwin 10' archs='ppc' date='2023-01-06T02:45:07+0700'
Dr-Noob commented 1 year ago

I have pushed a commit to master that should fix everything. Can you test it out and confirm it builds correctly?

p-linnane commented 1 year ago

Confirming that applying both 22a80d817d57814fc552365ad553c0a22f065fcd and 095bbfb784f0b367558741e9b02f6278126e1c93 allows us to build on macOS.

barracuda156 commented 1 year ago

I have pushed a commit to master that should fix everything. Can you test it out and confirm it builds correctly?

I will check it on PPC now.

UPD. Yes, with the PPC patch plus two other it builds fine on PPC.

@Dr-Noob Regarding the flag: it is okay with gcc12, but breaks the build with gcc-4.2. The problem is that the latter is the default one on macOS PPC, and since cpufetch does not ask for C11, gcc-4.2 is used. For Macports this is no problem to fix: we just patch out the flag (or can blacklist gcc-4.2 otherwise). But if anyone tries to build cpufetch from git repo directly, that will fail.

barracuda156 commented 1 year ago

It so happens that I updated the MacPorts Portfile under Monterey on an M1 machine, which is one of only two builds that succeeded (arm64 under Monterey and Ventura).

@Schamschula I have updated the PR with patches from @Dr-Noob now and rebased. Hopefully that fixes the build across the board.

barracuda156 commented 1 year ago

Since the build is fixed now, both PPC and Intel, closing.