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

Create aarch64-apple-darwin build script. #236

Closed
wants to merge 17 commits into from

Conversation

usiegl00
Copy link

@usiegl00 usiegl00 commented Oct 21, 2022

This adds a build script and changes the required files to build mettle targeting aarch64-apple-darwin.
Usage: bash build_m1.sh

See: rapid7/metasploit-framework#17129

Copy link
Contributor

@adfoster-r7 adfoster-r7 left a comment

Choose a reason for hiding this comment

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

It looks like @space-r7 has noticed a similar PR from @Ishaanahuja7 which has made some similar and different changes over here: #237

It'd be cool if there's anything that needs collaborating over for that to land in this PR 🎉

build_m1.sh Outdated
Comment on lines 1 to 8
cp deps/config.sub mettle/config.sub
make TARGET=aarch64-apple-darwin
cd build/aarch64-apple-darwin/json-c/ && autoreconf -fiv && cd ../../..
make TARGET=aarch64-apple-darwin
cp darwin_sigar.c build/aarch64-apple-darwin/libsigar/src/os/darwin/darwin_sigar.c
make TARGET=aarch64-apple-darwin
cd build/aarch64-apple-darwin/libdnet/ && autoreconf -fiv && cd ../../..
make TARGET=aarch64-apple-darwin
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think this is needed if we modify the top level ARCHES file, which should get pulled in automagically to the Makefile + build process over here:

mettle/Makefile

Lines 14 to 41 in bf5a4be

ARCHES := $(shell cat ARCHES)
# Create the individual build/clean/dist-clean rules for each arch...
define rules_for_each_arch
$(strip $(1)).build: $(TOOLS)/musl-cross/.unpacked $(ROOT)/mettle/configure
make TARGET=$(strip $(1))
$(strip $(1)).install:
make TARGET=$(strip $(1)) install
$(strip $(1)).clean:
make TARGET=$(strip $(1)) clean
$(strip $(1)).distclean:
make TARGET=$(strip $(1)) distclean
endef
$(foreach a, $(ARCHES), $(eval $(call rules_for_each_arch, $(strip $(a)))))
all-parallel: $(TOOLS) $(patsubst %,%.build,$(ARCHES))
clean-parallel: $(patsubst %,%.clean,$(ARCHES))
distclean-parallel: $(patsubst %,%.distclean,$(ARCHES))
install-parallel: $(patsubst %,%.install,$(ARCHES))

darwin_sigar.c Outdated
@@ -0,0 +1,2772 @@
/*
Copy link
Contributor

@adfoster-r7 adfoster-r7 Nov 3, 2022

Choose a reason for hiding this comment

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

I believe the sigar dependency is actually pulled in from over here https://github.com/rapid7/sigar

If this new darwin_sigar file is the same content as what's in the rapid7/sigar#1
PR, I think we'd be able to merge that in, or you could create a new pull request if there's additional changes to make 👍

@Ishaanahuja7
Copy link
Contributor

Hi @adfoster-r7 @usiegl00 I have opened a PR in rapid7/sigar with the fixed changes for darwin_sigar.c and in my PR for this repo also added darwin and iphone targets in ARCHES #237, rapid7/sigar#2

Ishaanahuja7 and others added 5 commits November 6, 2022 03:24
…e-darwin

This integrates Ishaanahuja7's changes with usiegl00s and enables
building for the aarch64-apple-darwin target.
@usiegl00
Copy link
Author

usiegl00 commented Nov 5, 2022

@Ishaanahuja7 I have incorporated your changes and separated out the cam and mic additions for a later pr. Thanks for the assist!
@adfoster-r7 This pr is ready to be merged and building normally with make TARGET=aarch64-apple-darwin on my machine.

@jmartin-tech
Copy link
Contributor

@usiegl00 as noted in #237 (comment) the changes to sigar need to land and will be packaged for inclusion from a tagged release which can then be added to this PR. darwin_sigar.c and changes to the make file that copy it over the extraction will need to be removed.

@@ -11,6 +11,7 @@ $(BUILD)/libsigar/Makefile: $(TOOLS) $(BUILD)/libsigar/configure
@mkdir -p $(BUILD)/libsigar
@$(SETUP_BUILDENV) cd $(BUILD)/libsigar; \
$(CONFIG_FIXUP) \
cp $(DEPS)/darwin_sigar.c src/os/darwin; \
Copy link
Contributor

Choose a reason for hiding this comment

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

This line and the darwin_sigar.c file should be removed since a PR was added to the sigar repository

ARCHES Outdated
Comment on lines 1 to 3
i386-apple-darwin
x86_64-apple-darwin
aarch64-apple-darwin
Copy link
Contributor

Choose a reason for hiding this comment

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

Sorry for the confusion, darwin tuples are not currently built using the ARCHES pattern. Currently the ARCHES list builds only artifacts that can be cross compiled using a linux build system.

The gem build process currently calls the following in a macOS VM with Xcode available.

make TARGET=x86_64-apple-darwin
make TARGET=arm-iphone-darwin
make TARGET=aarch64-iphone-darwin

I do like the idea of having all supported tuples in the ARCHES file however the Makefile would need to be updated to either detect the running OS and skip darwin when run on a linux platform or darwin tuples need to be a separate file.

Copy link
Contributor

Choose a reason for hiding this comment

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

Note if removing is the path the other darwin added targets for iphone at the end of the file are also not compilable on Linux.

@jmartin-tech
Copy link
Contributor

Closing this as all changes here are believed to have been incorporated in #237.

The framework PR referenced should be able to move forward utilizing the latest released gem for v1.0.23

@usiegl00
Copy link
Author

usiegl00 commented Mar 2, 2023

Thank you @Ishaanahuja7 and @jmartin-r7!

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.

5 participants