diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 76ccdc5ec7..a7dc8bcf57 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -225,3 +225,36 @@ jobs: - name: build run: | scripts/build.sh distro + + build-windows: + name: build windows + runs-on: windows-latest + defaults: + run: + shell: msys2 {0} + steps: + - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 + - name: Setup MSYS2 + uses: msys2/setup-msys2@cafece8e6baf9247cf9b1bf95097b0b983cc558d # v2.31.0 + with: + msystem: MINGW64 + update: true + install: > + git + mingw-w64-x86_64-gcc + mingw-w64-x86_64-meson + mingw-w64-x86_64-ninja + mingw-w64-x86_64-pkg-config + mingw-w64-x86_64-json-c + - name: Configure (Meson) + run: | + meson setup .build-ci \ + --prefix=/mingw64 \ + -Dversion-tag=master \ + -Ddefault_library=static + - name: Build + run: | + meson compile -C .build-ci + - name: Run tests (optional) + run: | + meson test -C .build-ci || true diff --git a/.gitignore b/.gitignore index 3a4b1930a8..63a971b053 100644 --- a/.gitignore +++ b/.gitignore @@ -23,3 +23,5 @@ tests/*.pyc # Ignore PyPI build artifacts dist/ + +.vscode/ diff --git a/libnvme/examples/telemetry-listen.c b/libnvme/examples/telemetry-listen.c index 931d95d99d..7fb8f2b15b 100644 --- a/libnvme/examples/telemetry-listen.c +++ b/libnvme/examples/telemetry-listen.c @@ -19,6 +19,7 @@ #include #include +#include #include #include diff --git a/libnvme/meson.build b/libnvme/meson.build index 52a76d248d..8635e8ca04 100644 --- a/libnvme/meson.build +++ b/libnvme/meson.build @@ -34,10 +34,10 @@ if want_libnvme subdir('tools/generator') # generate code needed by src below subdir('src') # declares: libnvme_dep subdir('libnvme') - if get_option('tests') + if want_tests subdir('test') endif - if get_option('examples') + if want_examples subdir('examples') endif diff --git a/libnvme/src/meson.build b/libnvme/src/meson.build index 53732077f5..15f08f1a84 100644 --- a/libnvme/src/meson.build +++ b/libnvme/src/meson.build @@ -5,22 +5,27 @@ # # Authors: Martin Belanger # -sources = [ - 'nvme/accessors.c', - 'nvme/base64.c', - 'nvme/cmds.c', - 'nvme/crc32.c', - 'nvme/filters.c', - 'nvme/ioctl.c', - 'nvme/lib.c', - 'nvme/linux.c', - 'nvme/log.c', - 'nvme/mi-mctp.c', - 'nvme/mi.c', - 'nvme/sysfs.c', - 'nvme/tree.c', - 'nvme/util.c', -] +sources = [] +if host_system == 'windows' + sources += [] +else + sources += [ + 'nvme/accessors.c', + 'nvme/base64.c', + 'nvme/cmds.c', + 'nvme/crc32.c', + 'nvme/filters.c', + 'nvme/ioctl.c', + 'nvme/lib.c', + 'nvme/linux.c', + 'nvme/log.c', + 'nvme/mi-mctp.c', + 'nvme/mi.c', + 'nvme/sysfs.c', + 'nvme/tree.c', + 'nvme/util.c', + ] +endif headers = [ 'nvme/accessors.h', 'nvme/cmds.h', @@ -50,10 +55,12 @@ if liburing_dep.found() sources += 'nvme/uring.c' endif -if json_c_dep.found() - sources += 'nvme/json.c' -else - sources += 'nvme/no-json.c' +if host_system != 'windows' + if json_c_dep.found() + sources += 'nvme/json.c' + else + sources += 'nvme/no-json.c' + endif endif deps = [ @@ -61,10 +68,18 @@ deps = [ ccan_dep, json_c_dep, keyutils_dep, - libdbus_dep, - liburing_dep, openssl_dep, ] +if host_system == 'windows' + deps += [ + kernel32_dep + ] +else + deps += [ + libdbus_dep, + liburing_dep, + ] +endif nvme_ld = meson.current_source_dir() / 'libnvme.ld' nvmf_ld = meson.current_source_dir() / 'libnvmf.ld' diff --git a/meson.build b/meson.build index f15cbe6cba..c5d9878f8b 100644 --- a/meson.build +++ b/meson.build @@ -34,6 +34,7 @@ fs = import('fs') cc = meson.get_compiler('c') cxx_available = add_languages('cpp', required: false, native: false) +host_system = host_machine.system() ################################################################################ # Determine which features we need to build: The nvme executable, the libnvme @@ -51,10 +52,15 @@ cxx_available = add_languages('cpp', required: false, native: false) # dependencies are present. Also, -Dpython=enabled forces -Dlibnvme=enabled. want_nvme = get_option('nvme').disabled() == false want_libnvme = get_option('libnvme').disabled() == false -want_fabrics = get_option('fabrics').disabled() == false +want_fabrics = get_option('fabrics').disabled() == false and host_system != 'windows' +want_json_c = get_option('json-c').disabled() == false and host_system != 'windows' +want_tests = get_option('tests') and host_system != 'windows' +want_examples = get_option('examples') and host_system != 'windows' want_docs = get_option('docs') want_docs_build = get_option('docs-build') +is_static = get_option('default_library') == 'static' and host_system != 'windows' + feature_python = get_option('python') if not want_fabrics or feature_python.disabled() py3_dep = dependency('', required: false) # Needed for muon @@ -131,8 +137,12 @@ conf.set('RUNDIR', '"@0@"'.format(rundir)) conf.set('CONFIG_FABRICS', want_fabrics, description: 'Is fabrics enabled') +if host_system == 'windows' + kernel32_dep = cc.find_library('kernel32', required: true) +endif + # Check for libjson-c availability -if get_option('json-c').disabled() +if not want_json_c json_c_dep = dependency('', required: false) else json_c_dep = dependency( @@ -363,7 +373,6 @@ conf.set10( description: 'Is linux/mctp.h include-able?' ) -is_static = get_option('default_library') == 'static' have_netdb = false if not is_static have_netdb = cc.links( @@ -473,45 +482,67 @@ if want_nvme subdir('plugins') # declares: plugin_sources subdir('util') # declares: util_sources - sources = [ - 'libnvme-wrap.c', - 'logging.c', - 'nvme-cmds.c', - 'nvme-models.c', - 'nvme-print-binary.c', - 'nvme-print-stdout.c', - 'nvme-print.c', - 'nvme-rpmb.c', - 'nvme.c', - 'plugin.c', - ] + sources = [] + if host_system == 'windows' + sources += [ + 'nvme-dummy.c', # Dummy source file for Windows port bring up. + ] + else + sources += [ + 'libnvme-wrap.c', + 'logging.c', + 'nvme-cmds.c', + 'nvme-models.c', + 'nvme-print-binary.c', + 'nvme-print-stdout.c', + 'nvme-print.c', + 'nvme-rpmb.c', + 'nvme.c', + 'plugin.c', + ] + + if json_c_dep.found() + sources += [ + 'nvme-print-json.c', + ] + endif + endif + if want_fabrics sources += 'fabrics.c' endif - if json_c_dep.found() - sources += [ - 'nvme-print-json.c', - ] - endif sources += plugin_sources sources += util_sources + link_args_list = [] + link_deps = [ + config_dep, + ccan_dep, + libnvme_dep, + json_c_dep, + ] + + if host_system == 'windows' + link_deps += [ + kernel32_dep, + ] + else + link_args_list = ['-ldl'] + endif + executable( 'nvme', sources, - dependencies: [ - config_dep, - ccan_dep, - libnvme_dep, - json_c_dep, - ], - link_args: '-ldl', + dependencies: link_deps, + link_args: link_args_list, install: true, install_dir: sbindir, ) - subdir('unit') + if host_system != 'windows' + subdir('unit') + endif if get_option('nvme-tests') subdir('tests') endif @@ -645,6 +676,11 @@ dep_dict = { 'python3': py3_dep.found(), 'liburing': liburing_dep.found(), } +if host_system == 'windows' + dep_dict += { + 'kernel32': kernel32_dep.found(), + } +endif summary(dep_dict, section: 'Dependencies', bool_yn: true) wanted_dict = { @@ -661,4 +697,3 @@ conf_dict = { 'pdc enabled': get_option('pdc-enabled'), } summary(conf_dict, section: 'Configuration', bool_yn: true) - diff --git a/nvme-dummy.c b/nvme-dummy.c new file mode 100644 index 0000000000..15cf908226 --- /dev/null +++ b/nvme-dummy.c @@ -0,0 +1,9 @@ +// SPDX-License-Identifier: GPL-2.0-or-later + +#include + +int main(int argc, char **argv) +{ + printf("This is a dummy executable for windows port bring up.\n"); + return 0; +} diff --git a/plugins/meson.build b/plugins/meson.build index 0702954376..92b0c7cc16 100644 --- a/plugins/meson.build +++ b/plugins/meson.build @@ -31,7 +31,11 @@ all_plugins = { } # Get the list of plugins to build -selected_plugins = get_option('plugins') +if host_system != 'windows' + selected_plugins = get_option('plugins') +else + selected_plugins = [] +endif # Build the plugin_sources list from simple plugins plugin_sources = [] diff --git a/util/meson.build b/util/meson.build index 9f8bdf2a6b..42412705d2 100644 --- a/util/meson.build +++ b/util/meson.build @@ -1,19 +1,25 @@ # SPDX-License-Identifier: GPL-2.0-or-later -util_sources = [ - 'util/argconfig.c', - 'util/base64.c', - 'util/crc32.c', - 'util/mem.c', - 'util/sighdl.c', - 'util/suffix.c', - 'util/types.c', - 'util/utils.c', - 'util/table.c' -] +util_sources = [] -if json_c_dep.found() +if host_system == 'windows' + util_sources += [] +else util_sources += [ - 'util/json.c', + 'util/argconfig.c', + 'util/base64.c', + 'util/crc32.c', + 'util/mem.c', + 'util/sighdl.c', + 'util/suffix.c', + 'util/types.c', + 'util/utils.c', + 'util/table.c' ] + + if json_c_dep.found() + util_sources += [ + 'util/json.c', + ] + endif endif