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

Allow macOS build #556

Merged
merged 1 commit into from
Feb 12, 2025
Merged

Allow macOS build #556

merged 1 commit into from
Feb 12, 2025

Conversation

jserv
Copy link
Contributor

@jserv jserv commented Feb 6, 2025

Commit 2ab8a68 failed to detect macOS/Arm64 properly, and commit 2e87a75 relied on the .SHELLSTATUS feature introduced in GNU make 4.2 (released on 2016-05-22). However, macOS ships with GNU make 3.81 by default, lacking of .SHELLSTATUS.

This commit fixes the macOS/Arm64 detection issue and reworks the build commands to run everything in a single shell invocation, capturing both the exit code and program output without relying on .SHELLSTATUS.

Summary by Bito

This PR enhances macOS build compatibility through two main changes: implementing ARM64 architecture detection and refactoring Makefile command execution for better compatibility with macOS GNU make 3.81. The changes focus on maintaining existing functionality while improving cross-platform support.

Unit tests added: False

Estimated effort to review (1-5, lower is better): 1

Copy link

bito-code-review bot commented Feb 6, 2025

Changelist by Bito

This pull request implements the following key changes.

Key Change Files Impacted
Feature Improvement - Build System Compatibility Enhancement

Makefile - Refactored command execution logic to support older GNU make versions

common.mk - Added macOS ARM64 platform detection support

@jserv jserv force-pushed the allow-macos-build branch from 3849ae8 to 9ea34d5 Compare February 6, 2025 22:00
@jserv jserv added this to the release-2025.1 milestone Feb 6, 2025
@jserv jserv force-pushed the allow-macos-build branch from 9ea34d5 to 357add2 Compare February 6, 2025 22:07
@sysprog21 sysprog21 deleted a comment from bito-code-review bot Feb 6, 2025
Copy link

bito-code-review bot commented Feb 6, 2025

Code Review Agent Run #ad92c8

Actionable Suggestions - 0
Review Details
  • Files reviewed - 3 · Commit Range: 357add2..357add2
    • Makefile
    • mk/artifact.mk
    • mk/common.mk
  • Files skipped - 0
  • Tools
    • Whispers (Secret Scanner) - ✔︎ Successful
    • Detect-secrets (Secret Scanner) - ✔︎ Successful

AI Code Review powered by Bito Logo

@sysprog21 sysprog21 deleted a comment from bito-code-review bot Feb 6, 2025
@ChinYikMing
Copy link
Collaborator

Sorry for the regression of macOS build.

I do not have macOS machine right now for verifying the changes. Shall we partially introduce build CI on macOS without triggering any fetch-checksum (related to #519) which similar to the build check in #546.

@jserv
Copy link
Contributor Author

jserv commented Feb 7, 2025

Shall we partially introduce build CI on macOS without triggering any fetch-checksum (related to #519) which similar to the build check in #546.

Hopefully, yes. I do suffer from repeated CI breakage related to checksum.

@jserv jserv force-pushed the allow-macos-build branch from 357add2 to 80678a5 Compare February 9, 2025 11:17
Copy link

bito-code-review bot commented Feb 9, 2025

Code Review Agent Run #a698c2

Actionable Suggestions - 0
Review Details
  • Files reviewed - 3 · Commit Range: 80678a5..80678a5
    • Makefile
    • mk/artifact.mk
    • mk/common.mk
  • Files skipped - 0
  • Tools
    • Whispers (Secret Scanner) - ✔︎ Successful
    • Detect-secrets (Secret Scanner) - ✔︎ Successful

AI Code Review powered by Bito Logo

@jserv jserv force-pushed the allow-macos-build branch from 80678a5 to d738bfc Compare February 9, 2025 15:14
Copy link

bito-code-review bot commented Feb 9, 2025

Code Review Agent Run #6df34b

Actionable Suggestions - 0
Review Details
  • Files reviewed - 3 · Commit Range: d738bfc..d738bfc
    • Makefile
    • mk/artifact.mk
    • mk/common.mk
  • Files skipped - 0
  • Tools
    • Whispers (Secret Scanner) - ✔︎ Successful
    • Detect-secrets (Secret Scanner) - ✔︎ Successful

AI Code Review powered by Bito Logo

@jserv jserv force-pushed the allow-macos-build branch from d738bfc to 8da8f0e Compare February 11, 2025 09:00
Copy link

bito-code-review bot commented Feb 11, 2025

Code Review Agent Run #805c88

Actionable Suggestions - 1
  • Makefile - 1
Review Details
  • Files reviewed - 2 · Commit Range: 8da8f0e..8da8f0e
    • Makefile
    • mk/common.mk
  • Files skipped - 0
  • Tools
    • Whispers (Secret Scanner) - ✔︎ Successful
    • Detect-secrets (Secret Scanner) - ✔︎ Successful

AI Code Review powered by Bito Logo

Makefile Outdated
$(PRINTF) "Running $(3) ... "; \
OUTPUT_FILE="$$(mktemp)"; \
if (LC_ALL=C $(BIN) $(1) $(2) > "$$OUTPUT_FILE") && \
[ "$$(cat "$$OUTPUT_FILE" | $(LOG_FILTER) | $(4))" = "$(strip $(5))" ]; then \
Copy link
Collaborator

@ChinYikMing ChinYikMing Feb 11, 2025

Choose a reason for hiding this comment

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

No need $(strip)? Since it truncates the whitespace in the sha1sum output of the misalign test when running uaes.elf, causing the test to fail."

Copy link
Collaborator

Choose a reason for hiding this comment

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

If $(strip) is removed, the last argument of line 380, 383, 387, 391, 394 should be refined by removing the whitespace after the comma to pass the test.

Copy link
Collaborator

Choose a reason for hiding this comment

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

diff --git a/Makefile b/Makefile
index d2ab6f2..a0224cd 100644
--- a/Makefile
+++ b/Makefile
@@ -367,7 +367,7 @@ $(Q)true; \
 $(PRINTF) "Running $(3) ... "; \
 OUTPUT_FILE="$$(mktemp)"; \
 if (LC_ALL=C $(BIN) $(1) $(2) > "$$OUTPUT_FILE") && \
-   [ "$$(cat "$$OUTPUT_FILE" | $(LOG_FILTER) | $(4))" = "$(strip $(5))" ]; then \
+   [ "$$(cat "$$OUTPUT_FILE" | $(LOG_FILTER) | $(4))" = "$(5)" ]; then \
     $(call notice, [OK]); \
 else \
     $(PRINTF) "Failed.\n"; \
@@ -377,22 +377,22 @@ $(RM) "$$OUTPUT_FILE"
 endef
 
 check-hello: $(BIN)
-	$(call check-test, , $(OUT)/hello.elf, hello.elf, uniq, $(EXPECTED_hello))
+	$(call check-test, , $(OUT)/hello.elf, hello.elf, uniq,$(EXPECTED_hello))
 
 check: $(BIN) check-hello artifact
-	$(Q)$(foreach e, $(CHECK_ELF_FILES), $(call check-test, , $(OUT)/riscv32/$(e), $(e), uniq, $(EXPECTED_$(e))))
+	$(Q)$(foreach e, $(CHECK_ELF_FILES), $(call check-test, , $(OUT)/riscv32/$(e), $(e), uniq,$(EXPECTED_$(e))))
 
 EXPECTED_aes_sha1 = 89169ec034bec1c6bb2c556b26728a736d350ca3  -
 misalign: $(BIN) artifact
-	$(call check-test, -m, $(OUT)/riscv32/uaes, uaes.elf, $(SHA1SUM), $(EXPECTED_aes_sha1))
+	$(call check-test, -m, $(OUT)/riscv32/uaes, uaes.elf, $(SHA1SUM),$(EXPECTED_aes_sha1))
 
 EXPECTED_misalign = MISALIGNED INSTRUCTION FETCH TEST PASSED!
 misalign-in-blk-emu: $(BIN)
-	$(call check-test, , tests/system/alignment/misalign.elf, misalign.elf, tail -n 1, $(EXPECTED_misalign))
+	$(call check-test, , tests/system/alignment/misalign.elf, misalign.elf, tail -n 1,$(EXPECTED_misalign))
 
 EXPECTED_mmu = STORE PAGE FAULT TEST PASSED!
 mmu-test: $(BIN)
-	$(call check-test, , tests/system/mmu/vm.elf, vm.elf, tail -n 1, $(EXPECTED_mmu))
+	$(call check-test, , tests/system/mmu/vm.elf, vm.elf, tail -n 1,$(EXPECTED_mmu))
 
 # Non-trivial demonstration programs
 ifeq ($(call has, SDL), 1)

Copy link
Collaborator

Choose a reason for hiding this comment

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

After applying the proposed changes to allow build on macOS and the above diff of Makefile, the default tests passed on both host-x64 and macOS-arm64, check CI. Note that the macOS CI currently excludes the gdbstub-test and arch-test because the RISC-V toolchain cannot be installed using the existing scripts (will try to fix it).

@@ -10,6 +10,8 @@ ifeq ($(UNAME_M),x86_64)
HOST_PLATFORM := x86
else ifeq ($(UNAME_M),aarch64)
HOST_PLATFORM := aarch64
else ifeq ($(UNAME_M),arm64) # macOS
HOST_PLATFORM := arm64
Copy link
Collaborator

Choose a reason for hiding this comment

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

There is no Sail model with suffix arm64 currently (Check sail model in rv32emu-prebuilt). I would defer the integration of arch-test on masOS CI.

Commit 2ab8a68 failed to detect macOS/Arm64 properly, and commit 2e87a75
relied on the .SHELLSTATUS feature introduced in GNU make 4.2 (released
on 2016-05-22). However, macOS ships with GNU make 3.81 by default.

This commit fixes the macOS/Arm64 detection issue and runs everything in
a single shell invocation, capturing both the exit code and program
output without relying on '.SHELLSTATUS'.

Co-authored-by: ChinYikMing <[email protected]>
@jserv jserv force-pushed the allow-macos-build branch from 8da8f0e to b23860d Compare February 12, 2025 01:35
Copy link

bito-code-review bot commented Feb 12, 2025

Code Review Agent Run #8c8988

Actionable Suggestions - 0
Review Details
  • Files reviewed - 2 · Commit Range: b23860d..b23860d
    • Makefile
    • mk/common.mk
  • Files skipped - 0
  • Tools
    • Whispers (Secret Scanner) - ✔︎ Successful
    • Detect-secrets (Secret Scanner) - ✔︎ Successful

AI Code Review powered by Bito Logo

@jserv jserv merged commit e9675f7 into master Feb 12, 2025
17 of 19 checks passed
@jserv
Copy link
Contributor Author

jserv commented Feb 12, 2025

Thank @ChinYikMing for contributing!

@jserv jserv deleted the allow-macos-build branch February 12, 2025 02:11
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.

3 participants