Skip to content

Help with adding M1 Mac support #19

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

Closed
jurvis opened this issue Nov 28, 2021 · 7 comments · Fixed by #21
Closed

Help with adding M1 Mac support #19

jurvis opened this issue Nov 28, 2021 · 7 comments · Fixed by #21
Assignees
Labels
enhancement New feature or request
Milestone

Comments

@jurvis
Copy link
Contributor

jurvis commented Nov 28, 2021

Hello, after an unfortunate water-related incident, I needed to replace my Mac and have started attempting to put together a working dev environment for M1 machines. I got amd64 emulation working, but though it'll be cool to figure this one out.

I saw in the README an attached issue, and dived into the comments to find out that ptrace does not work on qemu when running the csci104 container in amd64 mode.

According to this comment, it seems possible for us to get GDB working if we build a native arm64 image, so I started poking around at the current image and was able to piece together a Dockerfile that looks something like this (pretty much a copy):

FROM arm64v8/ubuntu:20.04

# Scripts and configuration
COPY files/root/* /root/
COPY files/bin/* /bin/

# Make sure line endings are Unix
# This changes nothing if core.autocrlf is set to input
RUN sed -i 's/\r$//' /root/.bashrc

RUN apt-get update && apt-get install -y \
    clang \
    clang-tidy \
    clang-format \
    g++ \
    make \
    valgrind \
    gdb \
    llvm \
    libgtest-dev \
    software-properties-common \
    cmake

# GTEST installation for labs
WORKDIR /usr/src/gtest
RUN cmake CMakeLists.txt \
    && make \
    && cp ./lib/libgtest*.a /usr/lib \
    && mkdir -p /usr/local/lib/gtest/ \
    && ln -s /usr/lib/libgtest.a /usr/local/lib/gtest/libgtest.a \
    && ln -s /usr/lib/libgtest_main.a /usr/local/lib/gtest/libgtest_main.a

# Grading, curricula requires python3.9
RUN add-apt-repository ppa:deadsnakes/ppa \
    && apt-get install -y \
        git \
        acl \
        python3.9 \
        python3.9-dev \
        python3-pip \
    && python3.9 -m pip install curricula curricula-grade curricula-grade-cpp curricula-compile curricula-format watchdog

VOLUME ["/work"]
WORKDIR /work

To build the container I used the
ch create command with the --file argument pointing to this Dockerfile. However, I ran into an error when running cmake CMakeLists.txt, since it doesn't exist in my setup.

I believe that file is part of the image on Docker hub but was wondering if you could share it so I can continue attempting making progress there.

Thanks!

@camerondurham
Copy link
Contributor

Hi @jurvis! Appreciate you working on this already! arm64 support is definitely needed for 104 but I haven't had time to look into it.

Just some initial findings:

I was so far able to use docker buildx to make an arm64 image on my amd64 machine without any modifications to the Dockerfile:

docker buildx build --platform linux/arm64 .

So, the CMakeList.txt issue doesn't seem to happen when it's built this way using the same base ubuntu:20.04 image built for linux/arm64 platform.

I'm working on the multi-arch branch right now to build an arm64 image in the GH Action. So far the only meaningful change was adding platforms to the workflow yml and the image was built w/o errors and now is pushed to the usccsci104 repositories:
usccsci104/docker-multiarch (see the linux/amd64 and linux/arm64 tags 🎉).

I am very surprised this worked without changing package versions/repos at all but next step is to see if it actually compiles/runs/debugs C++ code. I will not have an M1 to test on until mid-December but if you do have time, you could try using the new image if your version of Docker supports buildx/the buildkit. I think you'd find out if you need to change anything by running this command:

# the platform flag shouldn't be necessary if docker commands work in a non-Rosetta emulated terminal
docker pull --platform linux/arm64 usccsci104/docker-multiarch:20.04

Thanks again and hope we can figure out adding M1 support!

@camerondurham camerondurham added the enhancement New feature or request label Nov 28, 2021
@camerondurham camerondurham added this to the apple-silicon-support milestone Nov 28, 2021
@jurvis
Copy link
Contributor Author

jurvis commented Nov 28, 2021

@camerondurham nice! thanks for sharing your notes on this! I'll take a stab at this later today/tomorrow and share what I find :)

@jurvis
Copy link
Contributor Author

jurvis commented Nov 28, 2021

@camerondurham great news: it works super well! good find. totally blown away by the buildx command.

GDB

image

Valgrind

image

Do we want to update setup.sh to pull from usccsci104/docker-multiarch, or update the GitHub action to push to usccsci104/docker instead?

@jurvis
Copy link
Contributor Author

jurvis commented Nov 28, 2021

Before:
image

After:
image

😌 this feels good

@jurvis
Copy link
Contributor Author

jurvis commented Nov 28, 2021

curricula tests working too:
image

@camerondurham
Copy link
Contributor

Before: image

After: image

relieved this feels good

Very satisfying, this is awesome! Agreed, buildx is super powerful.

Glad to hear it all works I really appreciate you testing gdb, valgrind and curricula! I did some preliminary tests on my Raspberry Pi but this is much better. And since the Dockerfile didn't change at all, I think it's simpler to update the GitHub action to do the multi-platform build to usccsci104/docker. Will send PR shortly.

One question about the ch install before I update this and README. I know non-Rosetta emulated binaries on Apple Silicon require notarizing and have not set that up with the ch macOS builds. Did you have to do a ad hoc sign or any special steps to run the ch without Rosetta like mentioned in the golang issue (codesign -s - $HOME/ch-darwin-arm64/ch or similar)? @jurvis

@jurvis
Copy link
Contributor Author

jurvis commented Nov 28, 2021

@camerondurham

hm, I did not need to codesign ch. In fact, I actually did not need to use the Rosetta terminal workaround either, so I think it must have been fixed 😄

@camerondurham camerondurham linked a pull request Nov 28, 2021 that will close this issue
camerondurham added a commit that referenced this issue Nov 28, 2021
* try multi-arch build in GH actions workflow

* platform format

* add setup qemu

* use max caching

* Update README and caching

* Update README

* Resolve #19, publish multi-arch images to usccsci104/docker
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants