← index #7714Issue #15615
Related · high · value 2.077
QUERY · ISSUE

Native machine code support on MacOS

openby Miraj98opened 2021-08-26updated 2025-11-14
port-unixproposed-close

The past few days I have been trying this example - https://docs.micropython.org/en/latest/develop/natmod.html#minimal-example
The thing is I am not able to compile this on my MacOS. My machine produces executable in the Mach-O format but mpy_ld.py expects an ELF executable.

I even tried using i386-elf-gcc which seems to be a cross compiler but using that throws error as well. It's throwing

assert.h: No such file or directory
 #include <assert.h>

I think the best thing would be if Mach-O format is supported but till then I was wondering if there is a way around all this.

CANDIDATE · ISSUE

Native code decorator should be best-effort

openby darconeousopened 2024-08-08updated 2026-03-24
bugpy-core

Port, board and/or hardware

MacOS X (Apple Silicon)

MicroPython version

MicroPython v1.23.0 on 2024-05-31; darwin [GCC 4.2.1] version

Reproduction

Try running the following code on a macOS device running Apple Silicon using a version of Micropython built for Apple Silicon:

@micropython.native
def test_fun():
    print("Hello, World!")

Expected behaviour

I understand that native code execution is not supported on Apple Silicon, but I would expect to still be able to generally execute code even if marked up with native decorators (in order words, I would expect them to be ignored in that case).

Observed behaviour

When trying to test this code locally on my MacBook Pro M2, all functions with the decorator @micropython.native end up generating the following exception:

>>> %Run -c $EDITOR_CONTENT
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
SyntaxError: invalid micropython decorator
>>> 

Additional Information

I understand that the @micropython.viper decorator has different behavior and might not be a good candidate for being ignored, so we may want different behavior there. Perhaps an opt-in for allowing it to be ignored? Something like this:

@micropython.viper(optional=true)
def test_fun():
    print("Hello, World!")

This would force anyone wanting to test code like this to attest that the behavior would be the same.

Code of Conduct

Yes, I agree

Keyboard

j / / n
next pair
k / / p
previous pair
1 / / h
show query pane
2 / / l
show candidate pane
c
copy suggested comment
r
toggle reasoning
g i
go to index
?
show this help
esc
close overlays

press ? or esc to close

copied