Skip to content

Commit 8245ca1

Browse files
authored
Merge pull request #152 from SpotlightKid/develop
fix windows build CI
2 parents 36452aa + 5dbc954 commit 8245ca1

File tree

10 files changed

+159
-43
lines changed

10 files changed

+159
-43
lines changed

.github/workflows/development.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ jobs:
2121
- name: Install ninja
2222
run: pipx install ninja
2323

24+
- name: Install alsa deps
25+
run: sudo apt-get install libasound2-dev
26+
2427
- name: Build sdist
2528
run: pipx run build --sdist
2629

@@ -44,6 +47,9 @@ jobs:
4447
with:
4548
submodules: true
4649

50+
- uses: ilammy/msvc-dev-cmd@v1
51+
if: matrix.os == 'windows-latest'
52+
4753
- name: Build wheels
4854
uses: pypa/[email protected]
4955

.github/workflows/production.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ jobs:
2222
- name: Install ninja
2323
run: pipx install ninja
2424

25+
- name: Install alsa deps
26+
run: sudo apt-get install libasound2-dev
27+
2528
- name: Build sdist
2629
run: pipx run build --sdist
2730

@@ -44,6 +47,9 @@ jobs:
4447
with:
4548
submodules: true
4649

50+
- uses: ilammy/msvc-dev-cmd@v1
51+
if: matrix.os == 'windows-latest'
52+
4753
- name: Build wheels
4854
uses: pypa/[email protected]
4955

.github/workflows/tests.yml

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@ name: Build sdist and wheel for testing purposes
33
on:
44
push:
55
branches:
6-
- rtmidi-5.0.0
6+
- improve-build
77
pull_request:
88
branches:
9-
- rtmidi-5.0.0
9+
- improve-build
1010

1111
jobs:
1212
build_sdist:
@@ -21,6 +21,9 @@ jobs:
2121
- name: Install ninja
2222
run: pipx install ninja
2323

24+
- name: Install alsa deps
25+
run: sudo apt-get install libasound2-dev
26+
2427
- name: Build sdist
2528
run: pipx run build --sdist
2629

@@ -44,6 +47,9 @@ jobs:
4447
with:
4548
submodules: true
4649

50+
- uses: ilammy/msvc-dev-cmd@v1
51+
if: matrix.os == 'windows-latest'
52+
4753
- name: Build wheels
4854
uses: pypa/[email protected]
4955

meson.build

Lines changed: 48 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
project(
22
'python-rtmidi',
33
'cpp',
4-
version: '1.5.0',
4+
version: '1.5.1',
55
license: 'MIT',
66
default_options: [
77
'warning_level=2'
@@ -11,40 +11,9 @@ project(
1111

1212
cpp = meson.get_compiler('cpp')
1313

14-
## From https://github.com/numpy/numpy/blob/main/numpy/meson.build
15-
# Platform detection
16-
if host_machine.system() == 'windows' and cpp.get_id() == 'gcc'
17-
# For mingw-w64, link statically against the UCRT.
18-
gcc_link_args = ['-lucrt', '-static']
19-
20-
add_project_link_arguments(gcc_link_args, language: ['c', 'cpp'])
21-
# Force gcc to float64 long doubles for compatibility with MSVC
22-
# builds, for C only.
23-
add_project_arguments('-mlong-double-64', language: 'c')
24-
# Make fprintf("%zd") work (see https://github.com/rgommers/scipy/issues/118)
25-
add_project_arguments('-D__USE_MINGW_ANSI_STDIO=1', language: ['c', 'cpp'])
26-
# Manual add of MS_WIN64 macro when not using MSVC.
27-
# https://bugs.python.org/issue28267
28-
add_project_arguments('-DMS_WIN64', language: ['c', 'cpp'])
29-
endif
30-
##
31-
32-
if host_machine.system() == 'darwin'
33-
# Enable c++11 support
34-
add_project_arguments('-std=c++11', language: ['cpp'])
35-
endif
36-
37-
# Dependencies
14+
# Jack API (portable)
3815
jack2_dep = dependency('jack', version: '>=1.9.11', required: false)
3916
jack1_dep = dependency('jack', version: ['>=0.125.0', '<1.0'], required: false)
40-
alsa_dep = dependency('alsa', required: false)
41-
threads_dep = dependency('threads')
42-
coremidi_dep = dependency(
43-
'appleframeworks',
44-
modules: ['coreaudio', 'coremidi', 'foundation'],
45-
required: false
46-
)
47-
winmm_dep = cpp.find_library('winmm', required: false)
4817

4918
if not jack2_dep.found() and jack1_dep.found()
5019
jack_dep = jack1_dep
@@ -55,6 +24,50 @@ else
5524
jack_dep = disabler()
5625
endif
5726

27+
28+
jack_not_found = jack_dep.found() ? false : true
29+
30+
## From https://github.com/numpy/numpy/blob/main/numpy/meson.build
31+
# Platform dependent config
32+
if host_machine.system() == 'windows'
33+
# WINDOWS
34+
if cpp.get_id() == 'gcc'
35+
# For mingw-w64, link statically against the UCRT.
36+
gcc_link_args = ['-lucrtbase', '-static']
37+
add_project_link_arguments(gcc_link_args, language: ['c', 'cpp'])
38+
# Make fprintf("%zd") work (see https://github.com/rgommers/scipy/issues/118)
39+
add_project_arguments('-D__USE_MINGW_ANSI_STDIO=1', language: ['c', 'cpp'])
40+
# Manual add of MS_WIN64 macro when not using MSVC.
41+
# https://bugs.python.org/issue28267
42+
add_project_arguments('-DMS_WIN64', language: ['c', 'cpp'])
43+
elif cpp.get_id() == 'msvc'
44+
# Force gcc to float64 long doubles for compatibility with MSVC
45+
# builds, for C only.
46+
add_project_arguments('-mlong-double-64', language: 'c')
47+
endif
48+
49+
# API
50+
winmm_dep = cpp.find_library('winmm', required: jack_not_found)
51+
elif host_machine.system() == 'darwin'
52+
# OSX
53+
54+
# Enable c++11 support
55+
add_project_arguments('-std=c++11', language: ['cpp'])
56+
57+
# API
58+
coremidi_dep = dependency(
59+
'appleframeworks',
60+
modules: ['coreaudio', 'coremidi', 'foundation'],
61+
required: jack_not_found
62+
)
63+
else
64+
# LINUX
65+
66+
# API
67+
alsa_dep = dependency('alsa', required: jack_not_found)
68+
threads_dep = dependency('threads')
69+
endif # Platform detection
70+
5871
pymod = import('python')
5972
python = pymod.find_installation(get_option('python'), required: true)
6073

@@ -72,8 +85,9 @@ endif
7285
summary({
7386
'Debug messages (verbose)': get_option('verbose'),
7487
'Build for wheel': get_option('wheel'),
88+
'JACK support': jack_dep.found() and get_option('jack'),
7589
'ALSA support': host_machine.system() == 'linux' and alsa_dep.found() and get_option('alsa'),
7690
'CoreMIDI support': host_machine.system() == 'darwin' and coremidi_dep.found() and get_option('coremidi'),
77-
'JACK support': jack_dep.found() and get_option('jack'),
7891
'Window MM support': host_machine.system() == 'windows' and winmm_dep.found() and get_option('winmm'),
7992
}, section: 'Configuration')
93+

pyproject.toml

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ keywords = [
4444
meson-python-option-name = "python"
4545
meson-options = [
4646
"-Dwheel=true",
47+
"-Dverbose=true",
4748
"--buildtype=plain"
4849
]
4950

@@ -84,6 +85,10 @@ skip = "pp*"
8485
manylinux-x86_64-image = "manylinux_2_28"
8586
manylinux-aarch64-image = "manylinux_2_28"
8687

88+
# Run the package tests using `pytest`
89+
test-command = "pytest {package}/tests/test_basic.py"
90+
test-requires = "pytest"
91+
8792
# Install system library
8893
[tool.cibuildwheel.linux]
8994
build = "cp3{8,9,10,11}-manylinux*"
@@ -110,6 +115,4 @@ before-all = [
110115
[tool.cibuildwheel.windows]
111116
build = "cp3{8,9,10,11}-win*"
112117
archs = ["AMD64"]
113-
before-all = [
114-
"pipx install ninja",
115-
]
118+
build-verbosity = 1

rtmidi/meson.build

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,9 @@ if host_machine.system() == 'linux' and alsa_dep.found() and get_option('alsa')
2525
endif
2626

2727
if host_machine.system() == 'windows' and get_option('winmm')
28+
defines += ['-D__WINDOWS_MM__']
2829
if meson.get_compiler('cpp').get_id() != 'gcc'
29-
defines += ['-D__WINDOWS_MM__', '/EHsc']
30+
defines += ['/EHsc']
3031
endif
3132
dependencies += [winmm_dep]
3233
endif
@@ -36,7 +37,9 @@ if jack_dep.found() and get_option('jack')
3637
dependencies += [jack_dep]
3738
endif
3839

39-
if not get_option('verbose')
40+
if get_option('verbose')
41+
defines += ['-D__RTMIDI_DEBUG__']
42+
else
4043
defines += ['-D__RTMIDI_SILENCE_WARNINGS__']
4144
endif
4245

src/_rtmidi.pyx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,9 @@ used to specify the low-level MIDI backend API to use when creating a
7474
Windows MultiMedia
7575
``API_RTMIDI_DUMMY``
7676
RtMidi Dummy API (used when no suitable API was found)
77+
``API_RWEB_MIDI``
78+
W3C Web MIDI API
79+
7780
7881
7982
Error types
@@ -113,7 +116,7 @@ from libcpp.vector cimport vector
113116

114117
__all__ = (
115118
'API_UNSPECIFIED', 'API_MACOSX_CORE', 'API_LINUX_ALSA', 'API_UNIX_JACK',
116-
'API_WINDOWS_MM', 'API_RTMIDI_DUMMY', 'ERRORTYPE_DEBUG_WARNING',
119+
'API_WINDOWS_MM', 'API_RTMIDI_DUMMY', 'API_WEB_MIDI', 'ERRORTYPE_DEBUG_WARNING',
117120
'ERRORTYPE_DRIVER_ERROR', 'ERRORTYPE_INVALID_DEVICE',
118121
'ERRORTYPE_INVALID_PARAMETER', 'ERRORTYPE_INVALID_USE',
119122
'ERRORTYPE_MEMORY_ERROR', 'ERRORTYPE_NO_DEVICES_FOUND',
@@ -148,6 +151,7 @@ cdef extern from "RtMidi.h":
148151
UNIX_JACK "RtMidi::UNIX_JACK"
149152
WINDOWS_MM "RtMidi::WINDOWS_MM"
150153
RTMIDI_DUMMY "RtMidi::RTMIDI_DUMMY"
154+
WEB_MIDI "RtMidi::WEB_MIDI_API"
151155

152156
cdef enum ErrorType "RtMidiError::Type":
153157
ERR_WARNING "RtMidiError::WARNING"
@@ -244,6 +248,7 @@ API_LINUX_ALSA = LINUX_ALSA
244248
API_UNIX_JACK = UNIX_JACK
245249
API_WINDOWS_MM = WINDOWS_MM
246250
API_RTMIDI_DUMMY = RTMIDI_DUMMY
251+
API_WEB_MIDI = WEB_MIDI
247252

248253
# export error values to Python
249254

src/meson_dist_cython.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
ap.add_argument("mod_source", nargs="*", help="Cython module C++ source target(s) (*.cpp).")
1919
args = ap.parse_args()
2020

21+
2122
if args.verbose:
2223
print("cwd:", getcwd())
2324
print("build root:", build_root)

src/rtmidi

tests/test_basic.py

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
#!/usr/bin/env python
2+
# -*- coding: utf-8 -*-
3+
""" Basic tests that don't need midi ports"""
4+
5+
import unittest
6+
import rtmidi
7+
8+
9+
if bytes is str:
10+
string_types = (str, unicode) # noqa:F821
11+
else:
12+
string_types = (str,)
13+
14+
15+
class BasicTest(unittest.TestCase):
16+
def test_get_api_display_name(self):
17+
self.assertEqual(rtmidi.get_api_display_name(rtmidi.API_LINUX_ALSA), 'ALSA')
18+
self.assertEqual(rtmidi.get_api_display_name(rtmidi.API_MACOSX_CORE), 'CoreMidi')
19+
self.assertEqual(rtmidi.get_api_display_name(rtmidi.API_RTMIDI_DUMMY), 'Dummy')
20+
self.assertEqual(rtmidi.get_api_display_name(rtmidi.API_UNIX_JACK), 'Jack')
21+
self.assertEqual(rtmidi.get_api_display_name(rtmidi.API_UNSPECIFIED), 'Unknown')
22+
self.assertEqual(rtmidi.get_api_display_name(rtmidi.API_WINDOWS_MM), 'Windows MultiMedia')
23+
self.assertEqual(rtmidi.get_api_display_name(rtmidi.API_WEB_MIDI), 'Web MIDI API')
24+
25+
def test_get_api_name(self):
26+
self.assertEqual(rtmidi.get_api_name(rtmidi.API_LINUX_ALSA), 'alsa')
27+
self.assertEqual(rtmidi.get_api_name(rtmidi.API_MACOSX_CORE), 'core')
28+
self.assertEqual(rtmidi.get_api_name(rtmidi.API_RTMIDI_DUMMY), 'dummy')
29+
self.assertEqual(rtmidi.get_api_name(rtmidi.API_UNIX_JACK), 'jack')
30+
self.assertEqual(rtmidi.get_api_name(rtmidi.API_UNSPECIFIED), 'unspecified')
31+
self.assertEqual(rtmidi.get_api_name(rtmidi.API_WINDOWS_MM), 'winmm')
32+
self.assertEqual(rtmidi.get_api_name(rtmidi.API_WEB_MIDI), 'web')
33+
34+
def test_get_compiled_api(self):
35+
apilist = rtmidi.get_compiled_api()
36+
self.assertTrue(isinstance(apilist, list))
37+
self.assertTrue(len(apilist) >= 1)
38+
for api in apilist:
39+
self.assertTrue(api <= rtmidi.API_RTMIDI_DUMMY)
40+
41+
def test_get_compiled_api_by_name(self):
42+
for api, name in (
43+
(rtmidi.API_LINUX_ALSA, 'alsa'),
44+
(rtmidi.API_MACOSX_CORE, 'core'),
45+
(rtmidi.API_RTMIDI_DUMMY, 'dummy'),
46+
(rtmidi.API_UNIX_JACK, 'jack'),
47+
(rtmidi.API_WINDOWS_MM, 'winmm'),
48+
(rtmidi.API_WEB_MIDI, 'web'),):
49+
50+
res = rtmidi.get_compiled_api_by_name(name)
51+
52+
if api in rtmidi.get_compiled_api():
53+
self.assertEqual(res, api)
54+
else:
55+
self.assertEqual(res, rtmidi.API_UNSPECIFIED)
56+
57+
def test_get_rtmidi_version(self):
58+
version = rtmidi.get_rtmidi_version()
59+
self.assertTrue(isinstance(version, string_types))
60+
self.assertEqual(version, '5.0.0')
61+
62+
def test_nondummy_api_present(self):
63+
# Make sure at least one actual API has been compiled
64+
apilist = rtmidi.get_compiled_api()
65+
apiFound = False
66+
for api in apilist:
67+
if api != rtmidi.API_RTMIDI_DUMMY:
68+
apiFound = True
69+
self.assertTrue(apiFound)
70+
71+
if __name__ == '__main__':
72+
unittest.main()

0 commit comments

Comments
 (0)