Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
51 commits
Select commit Hold shift + click to select a range
d11a15f
Merge pull request #20 from Micron-TPG/upstream-sync-into-mingw
jimmunn Jan 8, 2026
a6e3969
Initial Windows cross-platform support for libnvme (#21)
bbusacker Jan 13, 2026
58a4ac2
Add Micron build file.
jimmunn Jan 13, 2026
8fdf969
Update name.
jimmunn Jan 13, 2026
936802b
Trigger CI after enabling Actions
jimmunn Jan 14, 2026
67ec4ac
Change steps to use verified actions.
jimmunn Jan 14, 2026
a0464ff
A Micron happy version of checkpatch workflow.
jimmunn Jan 15, 2026
1eff461
Remove trailing whitespace.
jimmunn Jan 15, 2026
eae9ebd
Add support for build system to read git tag on windows
bcapener Jan 22, 2026
51e533e
Merge pull request #24 from Micron-TPG/add-micron-build.yml
jimmunn Jan 26, 2026
832fb96
Add libnvme tests kdoc and UUID (#26)
bcapener Jan 26, 2026
a2b0d09
update windows-stubs.c to match actual signatures (#27)
bcapener Jan 30, 2026
a2dc5b2
Merge origin/master into mingw (#37)
bcapener Jan 30, 2026
368f262
Fix circular dependency in platform_linux.h causing build failures (#38)
Copilot Jan 31, 2026
599f9e7
feat: Add Windows support for nvme-cli (#29)
bbusacker Feb 2, 2026
2417c93
More updates to windows-stubs.c function signatures (#42)
bcapener Feb 5, 2026
aad5f1f
Add workflow to auto-merge master into mingw
jimmunn Feb 5, 2026
83f78b1
Remove trailing whitespace.
jimmunn Feb 5, 2026
0b42682
Merge pull request #44 from Micron-TPG/add-auto-merge-workflow
jimmunn Feb 5, 2026
471c705
Merge remote-tracking branch 'origin/master' into merge-in-master
bcapener Feb 6, 2026
fa78ed7
Merge pull request #46 from Micron-TPG/merge-in-master
bcapener Feb 6, 2026
a72bc91
Use personal access token (PAT) so workflow can push the merge.
jimmunn Feb 6, 2026
9f95c88
Merge pull request #48 from Micron-TPG/usePATInMergeWorkflow
jimmunn Feb 6, 2026
b579b6a
Use Github app instead of PAT.
jimmunn Feb 6, 2026
0e4d3dd
Merge branch 'usePATInMergeWorkflow' into mingw
jimmunn Feb 6, 2026
80748e9
More tweaks to file
jimmunn Feb 6, 2026
a2cb46f
Merge pull request #51 from Micron-TPG/merge-master-to-mingw-tweaks
jimmunn Feb 6, 2026
d5bfc87
Remove --strict from call to checkpatch.pl to match upstream behavior.
jimmunn Feb 9, 2026
de9449e
Update nvme transport handle file descriptor type (#45)
bcapener Feb 9, 2026
85295dd
Merge pull request #53 from Micron-TPG/checkpath-tweak
jimmunn Feb 9, 2026
385211e
Auto-merge master into mingw
github-actions[bot] Feb 10, 2026
6c4f8f8
Auto-merge master into mingw
github-actions[bot] Feb 11, 2026
e0939af
feat: Implemented admin commands supported on Windows using Windows I…
bgoing-micron-oss Feb 11, 2026
41af409
Auto-merge master into mingw
github-actions[bot] Feb 12, 2026
5f5ccd5
windows nvme: Updated BufferSize and Offset to use byte counts. (#55)
bgoing-micron-oss Feb 12, 2026
97a3936
Merge master into mingw
bgoing-micron-oss Feb 13, 2026
60612b1
Fix windows build issues from last merge.
bgoing-micron-oss Feb 13, 2026
ee064b9
Merge master into mingw
bgoing-micron-oss Feb 13, 2026
0d07d4d
Merge remote-tracking branch 'origin/master' into mingw
bgoing-micron-oss Feb 17, 2026
a6fc178
Updated stub for nvme_dump_config.
bgoing-micron-oss Feb 17, 2026
45baea1
Merge master into mingw
bgoing-micron-oss Feb 17, 2026
5382071
Merge 'origin/master' into mingw
jimmunn Feb 18, 2026
2818fb4
Merge branch 'master' into mingw
jimmunn Feb 19, 2026
d2730a6
Enable id-ctrl command (#54)
bcapener Feb 19, 2026
297fba6
Cleanup of includes and some formatting. (#59)
bgoing-micron-oss Feb 21, 2026
12d5218
Removed BUILD.md and updated ENVIRONMENT.md. (#60)
bgoing-micron-oss Feb 21, 2026
e6e7f38
Added readme describing the Windows port design choices and strategie…
bgoing-micron-oss Feb 21, 2026
c3963ab
Auto-merge master into mingw
github-actions[bot] Feb 21, 2026
162f404
Auto-merge master into mingw
github-actions[bot] Feb 23, 2026
11885e4
Merge remote-tracking branch 'origin/mingw' into windows-initial-review
jimmunn Feb 23, 2026
537f9b2
Remove Micron-only file for upstream PR
jimmunn Feb 23, 2026
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
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,6 @@ tests/*.pyc

# Ignore PyPI build artifacts
dist/

.vscode/
.github
298 changes: 298 additions & 0 deletions ENVIRONMENT.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,298 @@
# Environment Setup for nvme-cli

This guide covers how to set up your development environment for building nvme-cli and libnvme on Linux and Windows platforms.

## Dependencies Overview

### Core Build Tools

**Both Platforms:**
- Meson >= 0.62.0 (build system)
- Ninja (build backend) or Samurai (minimal alternative)
- C compiler (GCC or Clang on Linux, MinGW with GCC on Windows)

### Platform-Specific Dependencies

#### Linux Dependencies

**Required:**
- gcc or clang
- meson
- ninja-build or samurai

**Optional (recommended):**
- json-c >= 0.13 (for JSON output and plugins)
- OpenSSL >= 3.0.0 (for security features)
- libkeyutils (for key management)
- liburing >= 2.2 (for io_uring support)
- dbus-1 (for MCTP dbus scan support)

**Documentation (optional):**
- asciidoc or asciidoctor
- xmlto

**Testing (optional):**
- Python 3 with pytest (for tests)
- SWIG (for Python bindings)

#### Windows Dependencies

**Required:**
- MinGW-w64
- Meson
- Ninja
- Python 3.8+

**Optional:**
- OpenSSL >= 3.0.0 (for security features)
- Perl (for documentation generation scripts)

**Note:** On Windows, Linux-specific dependencies (json-c, liburing, keyutils, libdbus) are automatically disabled.

## Linux Environment Setup

### Ubuntu/Debian

```bash
# Install core build tools
sudo apt update
sudo apt install -y build-essential meson ninja-build pkg-config

# Install optional dependencies
sudo apt install -y \
libjson-c-dev \
libssl-dev \
libkeyutils-dev \
libdbus-1-dev

# For io_uring support (optional)
sudo apt install -y liburing-dev

# For documentation generation (optional)
sudo apt install -y asciidoc xmlto

# For Python bindings (optional)
sudo apt install -y python3-dev swig
```

### Fedora/RHEL/CentOS

```bash
# Install core build tools
sudo dnf install -y gcc meson ninja-build pkgconfig

# Install optional dependencies
sudo dnf install -y \
json-c-devel \
openssl-devel \
keyutils-libs-devel \
dbus-devel

# For io_uring support (optional)
sudo dnf install -y liburing-devel

# For documentation generation (optional)
sudo dnf install -y asciidoc xmlto

# For Python bindings (optional)
sudo dnf install -y python3-devel swig
```

### Arch Linux

```bash
# Install core build tools
sudo pacman -S base-devel meson ninja pkg-config

# Install optional dependencies
sudo pacman -S json-c openssl keyutils dbus

# For io_uring support (optional)
sudo pacman -S liburing

# For documentation generation (optional)
sudo pacman -S asciidoc xmlto

# For Python bindings (optional)
sudo pacman -S python swig
```

## Windows Environment Setup

### Using WinGet (Windows 10/11)

WinGet provides the easiest way to set up the build environment on Windows:

#### Installation

```powershell
# Install MinGW-w64 (GCC compiler toolchain)
winget install BrechtSanders.WinLibs.POSIX.UCRT

# Install Python (required for meson)
winget install Python.Python.3.12

# Install Perl (required for documentation generation scripts)
winget install StrawberryPerl.StrawberryPerl

# Install Meson build system (after Python is installed)
pip install meson

# Install OpenSSL (optional, for security features)
winget install ShiningLight.OpenSSL
```

#### Setting Up PATH

After installation, you need to add the tools to your PATH:

**Temporary PATH setup (for current PowerShell session):**

```powershell
# Set PATH to include MinGW, Python, and Meson
$env:PATH = "C:\Users\$env:USERNAME\AppData\Local\Microsoft\WinGet\Packages\BrechtSanders.WinLibs.POSIX.UCRT_Microsoft.Winget.Source_8wekyb3d8bbwe\mingw64\bin;C:\Users\$env:USERNAME\AppData\Local\Programs\Python\Python312\Scripts;C:\Users\$env:USERNAME\AppData\Local\Programs\Python\Python312;$env:PATH"
```

**Note:** The exact path for MinGW may vary depending on your WinGet installation. Use this command to locate it:
```powershell
Get-ChildItem -Path "$env:LOCALAPPDATA\Microsoft\WinGet\Packages" -Filter "BrechtSanders.WinLibs*" -Directory
```

**Permanent PATH setup:**

To avoid setting PATH every time:

1. Open System Properties:
- Press `Win + X` → System → Advanced system settings
- Or search for "Environment Variables" in Start Menu

2. Click "Environment Variables"

3. Under "User variables", select "Path" and click "Edit"

4. Click "New" and add these paths (adjust the username and exact paths as needed):
- `C:\Users\YourUsername\AppData\Local\Microsoft\WinGet\Packages\BrechtSanders.WinLibs.POSIX.UCRT_Microsoft.Winget.Source_8wekyb3d8bbwe\mingw64\bin`
- `C:\Users\YourUsername\AppData\Local\Programs\Python\Python312`
- `C:\Users\YourUsername\AppData\Local\Programs\Python\Python312\Scripts`

5. Click OK on all dialogs

6. Restart PowerShell or any open terminals

#### Verification

Verify the installation by checking versions:

```powershell
gcc --version
python --version
meson --version
ninja --version
```

Expected output should show:
- GCC 15.x or later
- Python 3.12.x or later
- Meson 1.x or later
- Ninja 1.x or later

## Troubleshooting Environment Setup

### Windows: Finding Installation Paths

If you need to locate where WinGet installed tools:

**Find Python:**
```powershell
Get-ChildItem -Path "$env:LOCALAPPDATA\Programs\Python" -Recurse -Filter "python.exe" -ErrorAction SilentlyContinue | Select-Object -First 1 -ExpandProperty FullName
```

**Find Meson:**
```powershell
Get-ChildItem -Path "$env:LOCALAPPDATA" -Recurse -Filter "meson.exe" -ErrorAction SilentlyContinue | Select-Object -First 1 -ExpandProperty FullName
```

**Find GCC (MinGW):**
```powershell
Get-ChildItem -Path "$env:LOCALAPPDATA" -Recurse -Filter "gcc.exe" -ErrorAction SilentlyContinue | Select-Object -First 1 -ExpandProperty FullName
```

### Windows: Command Not Found Errors

**"meson: command not found"**

Solution: Add Python Scripts directory to PATH:
```powershell
$env:PATH = "C:\Users\$env:USERNAME\AppData\Local\Programs\Python\Python312\Scripts;$env:PATH"
```

**"gcc: command not found"**

Solution: Add MinGW bin directory to PATH:
```powershell
$env:PATH = "C:\Users\$env:USERNAME\AppData\Local\Microsoft\WinGet\Packages\BrechtSanders.WinLibs.POSIX.UCRT_Microsoft.Winget.Source_8wekyb3d8bbwe\mingw64\bin;$env:PATH"
```

**"python: command not found"**

Solution: Add Python to PATH:
```powershell
$env:PATH = "C:\Users\$env:USERNAME\AppData\Local\Programs\Python\Python312;$env:PATH"
```

### Linux: Missing Dependencies

**json-c not found:**
```bash
# Ubuntu/Debian
sudo apt install libjson-c-dev

# Fedora/RHEL
sudo dnf install json-c-devel

# Arch
sudo pacman -S json-c
```

**OpenSSL not found:**
```bash
# Ubuntu/Debian
sudo apt install libssl-dev

# Fedora/RHEL
sudo dnf install openssl-devel

# Arch
sudo pacman -S openssl
```

**Meson too old:**
```bash
# Install newer version via pip
pip3 install --user meson

# Add to PATH if needed
export PATH="$HOME/.local/bin:$PATH"
```

### Verifying Your Environment

After setup, verify all required tools are available:

**Linux:**
```bash
gcc --version
meson --version
ninja --version
pkg-config --version
```

**Windows:**
```powershell
gcc --version
python --version
meson --version
ninja --version
```

If any command fails, review the PATH setup instructions above.
43 changes: 43 additions & 0 deletions WINDOWS-PORT-README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# Windows Port README

This document outlines some of the design choices and strategies used during the development of Windows support.

## Windows support strategy using MinGW

The mingw-w64 libraries and tools were chosen for the design to provide a more straightforward port to Windows, taking advantage of its headers and libraries and the GNU toolchain, including the gcc compiler. Benefits from this approach include faster turnaround, toolchain compatibility, and fewer code changes, which will help the code be more maintainable.

Installation and configuration of mingw and other tools such as meson, python, perl, and OpenSSL is described in [ENVIRONMENT.md](ENVIRONMENT.md). Meson build configuration is the same on Windows as on Linux.

## Windows build configuration support

The Meson build configuration files have been updated to detect the platform, and configure the build accordingly. Configuration options remain unchanged. On Windows builds, some features are flagged as not supported, and some files are not yet included in the build.

## Platform-specific includes

To reduce preprocessor checks for `_WIN32` throughout the codebase, common platform-specific includes, type definitions, and utility functions are centralized in `platform/linux.h` and `platform/windows.h` under libnvme. Code can include `platform/include.h`, which includes the appropriate platform header based on the target platform.

Some methods, macros, and types used throughout the code lack direct Windows equivalents. Windows-specific implementations and definitions have been added to `platform/windows.h` and `platform/windows.c`.

For types defined by `linux/types.h` on Linux, a new `platform/types.h` was created to define equivalent types for Windows. On Linux, `platform/types.h` simply includes `linux/types.h`. All project includes of `linux/types.h` have been replaced with `platform/types.h`.

## Stubs for currently unsupported methods

To allow compilation while some features remain unsupported on Windows, `windows-stubs.c` files contain stubbed implementations of unsupported methods. As support is added, these stubs are removed. These stub files are temporary and will be phased out as development progresses.

The Meson build configurations determine whether to build using the windows-stub.c files or the standard implementation files based on the target platform.

## Platform-specific method implementation

Many existing implementations work for both Linux and Windows. When platform-specific implementations are needed, we follow this pattern:

- **Header files (.h)**: Method declarations remain unchanged and platform-agnostic.
- **Windows implementations (filename-windows.c)**: Platform-specific implementations for Windows are placed in files following the naming convention `filename-windows.c` (for example, `ioctl-windows.c`).
- **Platform-agnostic implementations**: Code that works on both Linux and Windows remains in the existing `.c` file.
- **Linux-specific implementations**: Linux-only code remains in the existing `.c` file within `#ifndef _WIN32` guards. Eventually, we plan to extract these into separate `filename-linux.c` files. For now, keeping them inline simplifies upstream merging and ensures we don't miss method updates from the main project.
- **Build configuration**: The Meson build configuration determines which implementation files to include in the build based on the target platform.

Some Windows methods behave differently than their Linux counterparts and require project-specific implementations. Examples include `fstat` and `free`. We created wrapper methods such as `nvme_fstat` and `nvme_free` with platform-specific implementations to provide platform-agnostic interfaces throughout the codebase.

### The linux.h / linux.c exception

The files `nvme/linux.h` and `nvme/linux.c` present a problem for the pattern described above. Although the file names suggests that the methods they implement are Linux-specific, they are actually utility methods that are needed for both Linux and Windows implementations, and many of the existing implementations are compitible with Windows using MinGW. For now, a new file named `nvme/windows.c` contains the Windows-specific implementations of methods declared in `nvme/linux.h`, breaking with the pattern. Re-evaluation of the linux.h / linux.c names is needed.
4 changes: 4 additions & 0 deletions ccan/ccan/minmax/minmax.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@
do { } while (0)
#endif

/* Undefine any existing min/max macros. */
#undef min
#undef max

#define min(a, b) \
({ \
typeof(a) _a = (a); \
Expand Down
5 changes: 5 additions & 0 deletions common.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,13 @@

#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))

/* On Windows, min/max may be provided by libnvme but ensure they exist */
#ifndef min
#define min(x, y) ((x) > (y) ? (y) : (x))
#endif
#ifndef max
#define max(x, y) ((x) > (y) ? (x) : (y))
#endif

#ifdef __packed
#else /* __packed */
Expand Down
2 changes: 1 addition & 1 deletion fabrics.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
#include <time.h>

#include <sys/types.h>
#include <linux/types.h>
#include <platform/types.h>

#include <libnvme.h>

Expand Down
2 changes: 2 additions & 0 deletions libnvme-wrap.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
* Copyright (c) 2022 Daniel Wagner, SUSE
*/

#ifndef _WIN32
#include <dlfcn.h>
#endif
#include <errno.h>
#include <stdlib.h>

Expand Down
Loading