Skip to content

Commit

Permalink
WIP compile a native led without phy on wasm
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolas-rabault committed Jan 10, 2024
1 parent 38605d5 commit d956ba9
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 3 deletions.
16 changes: 16 additions & 0 deletions examples/projects/native/led/platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,19 @@ build_flags =
-lpthread
-lm
-D LUOSHAL=NATIVE

[env:wasm]
lib_ldf_mode =off
lib_extra_dirs =
$PROJECT_DIR/../../../../../
$PROJECT_DIR/../../../../network/
platform = native
extra_scripts = pre:wasm_modifier.py
lib_deps =
Led
build_unflags = -Os
build_flags =
-I inc
-include node_config.h
-O3
-D LUOSHAL=NATIVE
6 changes: 3 additions & 3 deletions examples/projects/native/led/src/main.c
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
#include "luos_engine.h"
#include "ws_network.h"
// #include "ws_network.h"
#include "led.h"

int main(void)
{
Luos_Init();
Ws_Init();
// Ws_Init();
Led_Init();
while (1)
{
Luos_Loop();
Ws_Loop();
// Ws_Loop();
Led_Loop();
}
}
42 changes: 42 additions & 0 deletions examples/projects/native/led/wasm_modifier.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import os
Import("env")

# Create a symlink to clang++ in gcc
try:
os.symlink('/Applications/cheerp/bin/clang++', '/Applications/cheerp/bin/gcc')
except FileExistsError:
pass

try:
os.symlink('/Applications/cheerp/bin/llvm-link', '/Applications/cheerp/bin/ar')
except FileExistsError:
pass

# Add the cheerp path at the beginning of the PATH environment variable
new_gcc_path = '/Applications/cheerp/bin'
current_path = os.environ.get('PATH', '')
os.environ['PATH'] = f"{new_gcc_path}{os.pathsep}{current_path}"

# Print the path used when calling gcc
print("GCC used by platformio is :" + os.popen("which gcc").read())

# Add the cheerp-wasm target to the linker flags
env.Append(
LINKFLAGS=[
"--target=cheerp-wasm"
]
)

# Add the cheerp-wasm target to the compiler flags
env.Append(
CCFLAGS=[
"--target=cheerp-wasm"
]
)

# Replace the ar and ranlib commands with the appropriate llvm-ar command
env.Replace(AR="/Applications/cheerp/bin/llvm-ar",
RANLIB="/Applications/cheerp/bin/llvm-ar s",
LD="/Applications/cheerp/bin/llvm-link",
PROGNAME="program.bc")

0 comments on commit d956ba9

Please sign in to comment.