Skip to content
Closed
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 48 additions & 0 deletions .github/workflows/osx-nanoclr.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
name: osx-nanoclr

on:
push:
paths:
- "targets/osx/**"
- ".github/workflows/osx-nanoclr.yml"
pull_request:
paths:
- "targets/osx/**"
- ".github/workflows/osx-nanoclr.yml"

jobs:
build-osx-nanoclr:
runs-on: macos-14

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Install Ninja (if missing)
run: |
if ! command -v ninja >/dev/null 2>&1; then
brew install ninja
fi

- name: Configure
run: |
cmake -S targets/osx -B build/osx -G Ninja \
-DNANO_OSX_ARCH=arm64 \
-DNANO_OSX_ENABLE_SMOKE=ON

- name: Build
run: cmake --build build/osx --verbose

- name: Smoke Run
run: |
set -euo pipefail
./build/osx/bin/nanoFramework.nanoCLR --version | tee build/osx/smoke.log
Comment thread
coderabbitai[bot] marked this conversation as resolved.

- name: Upload Artifacts
if: always()
uses: actions/upload-artifact@v4
with:
name: osx-nanoclr
path: |
build/osx/bin/nanoFramework.nanoCLR
build/osx/smoke.log
25 changes: 25 additions & 0 deletions targets/osx/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#
# Copyright (c) .NET Foundation and Contributors
# See LICENSE file in the project root for full license information.
#

cmake_minimum_required(VERSION 3.24)

project(nanoFramework_nanoCLR_osx VERSION 0.1.0 LANGUAGES C CXX)

if(NOT APPLE)
message(FATAL_ERROR "targets/osx can only be built on macOS.")
endif()

set(NANO_OSX_ARCH "arm64" CACHE STRING "Target architecture for macOS host build (arm64 or x86_64)")
set_property(CACHE NANO_OSX_ARCH PROPERTY STRINGS arm64 x86_64)

if(NOT NANO_OSX_ARCH STREQUAL "arm64" AND NOT NANO_OSX_ARCH STREQUAL "x86_64")
message(FATAL_ERROR "Invalid NANO_OSX_ARCH='${NANO_OSX_ARCH}'. Valid values: arm64, x86_64.")
endif()

set(CMAKE_OSX_ARCHITECTURES "${NANO_OSX_ARCH}" CACHE STRING "macOS architecture" FORCE)

option(NANO_OSX_ENABLE_SMOKE "Build smoke behavior (--help/--version/banner)." ON)

add_subdirectory(nanoCLR)
15 changes: 15 additions & 0 deletions targets/osx/Include/TargetHAL_Spi.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
//
// Copyright (c) .NET Foundation and Contributors
// See LICENSE file in the project root for full license information.
//

#ifndef TARGET_HAL_SPI_H
#define TARGET_HAL_SPI_H

// # of buses
#define NUM_SPI_BUSES 0

// Maximum number of devices per SPI bus
#define MAX_SPI_DEVICES 5

#endif // TARGET_HAL_SPI_H
9 changes: 9 additions & 0 deletions targets/osx/Include/nanoHAL_Boot.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
//
// Copyright (c) .NET Foundation and Contributors
// See LICENSE file in the project root for full license information.
//

#ifndef NANOHAL_BOOT_H
#define NANOHAL_BOOT_H

#endif // NANOHAL_BOOT_H
9 changes: 9 additions & 0 deletions targets/osx/Include/nanoHAL_Capabilites.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
//
// Copyright (c) .NET Foundation and Contributors
// See LICENSE file in the project root for full license information.
//

#ifndef NANOHAL_CAPABILITIES_H
#define NANOHAL_CAPABILITIES_H

#endif // NANOHAL_CAPABILITIES_H
Comment thread
asp2286 marked this conversation as resolved.
84 changes: 84 additions & 0 deletions targets/osx/Include/targetHAL.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
//
// Copyright (c) .NET Foundation and Contributors
// See LICENSE file in the project root for full license information.
//

#ifndef TARGET_HAL_H
#define TARGET_HAL_H

#include <chrono>
#include <csignal>
#include <cstdint>
#include <thread>

// Keep the same macro shape used by other targets.
#define PLATFORM_DELAY(milliSecs) std::this_thread::sleep_for(std::chrono::milliseconds((milliSecs)))

// Start with the same minimum socket count used by win32 host.
#define PLATFORM_DEPENDENT__SOCKETS_MAX_COUNT 1

#define NANOCLR_STOP() std::raise(SIGTRAP)

inline bool Target_ConfigUpdateRequiresErase()
{
return true;
}

inline bool Target_HasNanoBooter()
{
return false;
}

inline bool Target_CanChangeMacAddress()
{
return false;
}

inline bool Target_IFUCapable()
{
return false;
}

inline bool Target_HasProprietaryBooter()
{
return false;
}

inline uint32_t GetPlatformCapabilities()
{
return 0;
}

inline uint32_t GetTargetCapabilities()
{
return 0;
}

inline bool RequestToLaunchProprietaryBootloader()
{
return false;
}

inline bool RequestToLaunchNanoBooter(int32_t errorCode)
{
(void)errorCode;
return false;
}

inline uint32_t CPU_TicksPerSecond()
{
// 100ns ticks to align with nanoCLR time usage in virtual-device mode.
return 10000000U;
}

inline uint64_t CPU_MicrosecondsToTicks(uint64_t uSec)
{
return uSec * 10ULL;
}

inline uint64_t CPU_MillisecondsToTicks(uint64_t mSec)
{
return mSec * 10000ULL;
}

#endif // TARGET_HAL_H
21 changes: 21 additions & 0 deletions targets/osx/Include/targetHAL_Power.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
//
// Copyright (c) .NET Foundation and Contributors
// See LICENSE file in the project root for full license information.
//

#ifndef TARGET_HAL_POWER_H
#define TARGET_HAL_POWER_H

#include <cstdlib>

inline void CPU_Reset()
{
std::exit(0);
}

inline bool CPU_IsSoftRebootSupported()
{
return true;
}

#endif // TARGET_HAL_POWER_H
15 changes: 15 additions & 0 deletions targets/osx/Include/targetHAL_Time.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
//
// Copyright (c) .NET Foundation and Contributors
// See LICENSE file in the project root for full license information.
//

#ifndef TARGET_HAL_TIME_H
#define TARGET_HAL_TIME_H

#include <cstdint>

uint64_t HAL_Time_CurrentSysTicks();
void HAL_Time_Sleep_MicroSeconds(unsigned int uSec);
void HAL_Time_Sleep_MicroSeconds_InterruptEnabled(unsigned int uSec);

#endif // TARGET_HAL_TIME_H
9 changes: 9 additions & 0 deletions targets/osx/Include/targetPAL_time.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
//
// Copyright (c) .NET Foundation and Contributors
// See LICENSE file in the project root for full license information.
//

#ifndef TARGET_PAL_TIME_H
#define TARGET_PAL_TIME_H

#endif // TARGET_PAL_TIME_H
12 changes: 12 additions & 0 deletions targets/osx/Include/target_BlockStorage.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
//
// Copyright (c) .NET Foundation and Contributors
// See LICENSE file in the project root for full license information.
//

#ifndef TARGETPAL_BLOCKSTORAGE_H
#define TARGETPAL_BLOCKSTORAGE_H

// Start with the same value as win32 target profile.
#define TARGET_BLOCKSTORAGE_COUNT 1

#endif // TARGETPAL_BLOCKSTORAGE_H
9 changes: 9 additions & 0 deletions targets/osx/Include/target_board.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
//
// Copyright (c) .NET Foundation and Contributors
// See LICENSE file in the project root for full license information.
//

#ifndef TARGET_BOARD_H
#define TARGET_BOARD_H

#endif // TARGET_BOARD_H
14 changes: 14 additions & 0 deletions targets/osx/Include/target_common.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
//
// Copyright (c) .NET Foundation and Contributors
// See LICENSE file in the project root for full license information.
//

#ifndef TARGET_COMMON_H
#define TARGET_COMMON_H

#define TARGETNAMESTRING "Virtual nanoDevice"
#define PLATFORMNAMESTRING "OSX"
#define TARGETINFOSTRING "CLR for OSX"
#define OEMSYSTEMINFOSTRING "nanoCLR running @ OSX"

#endif // TARGET_COMMON_H
11 changes: 11 additions & 0 deletions targets/osx/Include/target_os.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
//
// Copyright (c) .NET Foundation and Contributors
// See LICENSE file in the project root for full license information.
//

#ifndef TARGET_OS_H
#define TARGET_OS_H

#define TARGET_HAS_NANOBOOTER 0

#endif // TARGET_OS_H
9 changes: 9 additions & 0 deletions targets/osx/Include/target_platform.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
//
// Copyright (c) .NET Foundation and Contributors
// See LICENSE file in the project root for full license information.
//

#ifndef TARGET_PLATFORM_H
#define TARGET_PLATFORM_H

#endif // TARGET_PLATFORM_H
Comment thread
coderabbitai[bot] marked this conversation as resolved.
58 changes: 58 additions & 0 deletions targets/osx/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# .NET nanoFramework nanoCLR - macOS Host Target (Scaffold)

This target provides an initial macOS host scaffold at `targets/osx`.

## Status

The target currently provides:

- A CMake + Ninja build entrypoint for macOS.
- A minimal host glue structure aligned with `targets/win32`.
- A smoke executable (`--help`, `--version`, banner output).
- A GitHub Actions workflow that builds and runs smoke on macOS.

This target is intentionally a scaffold baseline.

## Build

Apple Silicon:

```bash
cmake -S targets/osx -B build/osx -G Ninja -DNANO_OSX_ARCH=arm64 -DNANO_OSX_ENABLE_SMOKE=ON
cmake --build build/osx
./build/osx/bin/nanoFramework.nanoCLR --version
```

Intel macOS:

```bash
cmake -S targets/osx -B build/osx -G Ninja -DNANO_OSX_ARCH=x86_64 -DNANO_OSX_ENABLE_SMOKE=ON
cmake --build build/osx
./build/osx/bin/nanoFramework.nanoCLR --version
```

## Configuration Options

`NANO_OSX_ARCH`
- Default: `arm64`
- Accepted values: `arm64`, `x86_64`

`NANO_OSX_ENABLE_SMOKE`
- Default: `ON`
- Enables minimal command-line smoke behavior.

## Current Limitations (Intentional)

This target does not yet include:

- Managed filesystem support.
- Networking support.
- Integration with the shared CLR runtime startup path (`src/CLR/**`).
- Full timer/event behavior (placeholder implementation only).

## Follow-up Roadmap

1. Wire a minimal shared runtime startup path (`src/CLR/**`) behind small host portability shims.
2. Replace placeholder PAL/HAL glue with deterministic POSIX/macOS implementations.
3. Enable optional managed payload smoke execution.
4. Add networking/TLS support in a dedicated follow-up change.
Loading