windelbouwman / ppci

A compiler for ARM, X86, MSP430, xtensa and more implemented in pure Python
https://ppci.readthedocs.io/en/latest/
BSD 2-Clause "Simplified" License
337 stars 36 forks source link

Add darwin check in get_current_arch #109

Closed klauer closed 4 years ago

klauer commented 4 years ago

Adds check for darwin in get_current_arch. I was expecting more resistance to getting this going, but its pure Python nature made it a simple one-line change.

Local testing with LONGTEST=python,any pytest -vv test/ shows 1509 passed, 634 skipped in 46.44s

Running the example executable from ppci-cc/-ld works fine with Docker:

Example test on darwin ``` $ uname -a Darwin klauer-osx 19.4.0 Darwin Kernel Version 19.4.0: Wed Mar 4 22:28:40 PST 2020; root:xnu-6153.101.6~15/RELEASE_X86_64 x86_64 $ ppci-cc -c -O1 -o hello.o hello.c 2020-07-10 10:36:40,408 | INFO | root | ppci 0.5.9 on CPython 3.7.6 on Darwin-19.4.0-x86_64-i386-64bit 2020-07-10 10:36:40,414 | INFO | cbuilder | Starting C compilation (c99) 2020-07-10 10:36:40,426 | INFO | cparser | Parsing finished 2020-07-10 10:36:40,429 | WARNING | ccodegen | Function does not return a value 2020-07-10 10:36:40,429 | INFO | ccodegen | Finished IR-code generation 2020-07-10 10:36:40,429 | INFO | optimize | Optimizing module main level 1 2020-07-10 10:36:40,442 | INFO | codegen | Generating x86_64-arch code for module main 2020-07-10 10:36:40,442 | INFO | codegen | Generating x86_64-arch code for function puts 2020-07-10 10:36:40,451 | INFO | codegen | Generating x86_64-arch code for function putc 2020-07-10 10:36:40,457 | INFO | codegen | Generating x86_64-arch code for function exit 2020-07-10 10:36:40,463 | INFO | codegen | Generating x86_64-arch code for function syscall 2020-07-10 10:36:40,513 | INFO | codegen | Generating x86_64-arch code for function main 2020-07-10 10:36:40,519 | WARNING | root | TODO: Linking with stdlibs $ ppci-ld --entry main --layout linux64.ld hello.o -o hello 2020-07-10 10:36:52,463 | INFO | root | ppci 0.5.9 on CPython 3.7.6 on Darwin-19.4.0-x86_64-i386-64bit $ cat Dockerfile FROM quay.io/pypa/manylinux1_x86_64 COPY hello hello RUN ./hello $ docker build --no-cache . Sending build context to Docker daemon 22.02kB Step 1/3 : FROM quay.io/pypa/manylinux1_x86_64 ---> 3317c29096eb Step 2/3 : COPY hello hello ---> 97b527157f53 Step 3/3 : RUN ./hello ---> Running in ee23dd034fc2 Hello, World! Removing intermediate container ee23dd034fc2 ---> 294963088815 Successfully built 294963088815 ```
codecov-commenter commented 4 years ago

Codecov Report

Merging #109 into master will not change coverage. The diff coverage is 100.00%.

Impacted file tree graph

@@           Coverage Diff           @@
##           master     #109   +/-   ##
=======================================
  Coverage   78.55%   78.55%           
=======================================
  Files         350      350           
  Lines       45616    45616           
=======================================
  Hits        35835    35835           
  Misses       9781     9781           
Impacted Files Coverage Δ
ppci/arch/__init__.py 82.60% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update 736277d...a60862d. Read the comment docs.

windelbouwman commented 4 years ago

Thanks for test driving on Mac! I'm not aware of any tests on Mac so far, so this is good news.

The change as such is good I assume, however for your use case you are strictly speaking cross compiling from mac to linux, so you could also add the command line option -m x86_64 to ppci-cc to target x86_64 architecture for linux. Did you also try to produce a native Mac executable? Do you have any ideas what would be involved here? Does Mac use ELF format as well?

klauer commented 4 years ago

No problem. Thanks for the very neat library - I expect to have a lot of fun playing around with it!

I didn't try to produce a native OSX executable, as I believe they're an entirely different beast (https://en.wikipedia.org/wiki/Mach-O). That's about the extent of my knowledge, though.