Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix windows build CI #152

Merged
merged 3 commits into from
Jun 12, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
6 changes: 6 additions & 0 deletions .github/workflows/development.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ jobs:
- name: Install ninja
run: pipx install ninja

- name: Install alsa deps
run: sudo apt-get install libasound2-dev

- name: Build sdist
run: pipx run build --sdist

Expand All @@ -44,6 +47,9 @@ jobs:
with:
submodules: true

- uses: ilammy/msvc-dev-cmd@v1
if: matrix.os == 'windows-latest'

- name: Build wheels
uses: pypa/[email protected]

Expand Down
6 changes: 6 additions & 0 deletions .github/workflows/production.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ jobs:
- name: Install ninja
run: pipx install ninja

- name: Install alsa deps
run: sudo apt-get install libasound2-dev

- name: Build sdist
run: pipx run build --sdist

Expand All @@ -44,6 +47,9 @@ jobs:
with:
submodules: true

- uses: ilammy/msvc-dev-cmd@v1
if: matrix.os == 'windows-latest'

- name: Build wheels
uses: pypa/[email protected]

Expand Down
10 changes: 8 additions & 2 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ name: Build sdist and wheel for testing purposes
on:
push:
branches:
- rtmidi-5.0.0
- improve-build
pull_request:
branches:
- rtmidi-5.0.0
- improve-build
Comment on lines +6 to +9
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Something doesn't seem right here. Does this belong in the master branch?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I used this file to test workflow changes. I guess we can delete it now.


jobs:
build_sdist:
Expand All @@ -21,6 +21,9 @@ jobs:
- name: Install ninja
run: pipx install ninja

- name: Install alsa deps
run: sudo apt-get install libasound2-dev

- name: Build sdist
run: pipx run build --sdist

Expand All @@ -44,6 +47,9 @@ jobs:
with:
submodules: true

- uses: ilammy/msvc-dev-cmd@v1
if: matrix.os == 'windows-latest'

- name: Build wheels
uses: pypa/[email protected]

Expand Down
82 changes: 48 additions & 34 deletions meson.build
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
project(
'python-rtmidi',
'cpp',
version: '1.5.0',
version: '1.5.1',
license: 'MIT',
default_options: [
'warning_level=2'
Expand All @@ -11,40 +11,9 @@ project(

cpp = meson.get_compiler('cpp')

## From https://github.com/numpy/numpy/blob/main/numpy/meson.build
# Platform detection
if host_machine.system() == 'windows' and cpp.get_id() == 'gcc'
# For mingw-w64, link statically against the UCRT.
gcc_link_args = ['-lucrt', '-static']

add_project_link_arguments(gcc_link_args, language: ['c', 'cpp'])
# Force gcc to float64 long doubles for compatibility with MSVC
# builds, for C only.
add_project_arguments('-mlong-double-64', language: 'c')
# Make fprintf("%zd") work (see https://github.com/rgommers/scipy/issues/118)
add_project_arguments('-D__USE_MINGW_ANSI_STDIO=1', language: ['c', 'cpp'])
# Manual add of MS_WIN64 macro when not using MSVC.
# https://bugs.python.org/issue28267
add_project_arguments('-DMS_WIN64', language: ['c', 'cpp'])
endif
##

if host_machine.system() == 'darwin'
# Enable c++11 support
add_project_arguments('-std=c++11', language: ['cpp'])
endif

# Dependencies
# Jack API (portable)
jack2_dep = dependency('jack', version: '>=1.9.11', required: false)
jack1_dep = dependency('jack', version: ['>=0.125.0', '<1.0'], required: false)
alsa_dep = dependency('alsa', required: false)
threads_dep = dependency('threads')
coremidi_dep = dependency(
'appleframeworks',
modules: ['coreaudio', 'coremidi', 'foundation'],
required: false
)
winmm_dep = cpp.find_library('winmm', required: false)

if not jack2_dep.found() and jack1_dep.found()
jack_dep = jack1_dep
Expand All @@ -55,6 +24,50 @@ else
jack_dep = disabler()
endif


jack_not_found = jack_dep.found() ? false : true

## From https://github.com/numpy/numpy/blob/main/numpy/meson.build
# Platform dependent config
if host_machine.system() == 'windows'
# WINDOWS
if cpp.get_id() == 'gcc'
# For mingw-w64, link statically against the UCRT.
gcc_link_args = ['-lucrtbase', '-static']
add_project_link_arguments(gcc_link_args, language: ['c', 'cpp'])
# Make fprintf("%zd") work (see https://github.com/rgommers/scipy/issues/118)
add_project_arguments('-D__USE_MINGW_ANSI_STDIO=1', language: ['c', 'cpp'])
# Manual add of MS_WIN64 macro when not using MSVC.
# https://bugs.python.org/issue28267
add_project_arguments('-DMS_WIN64', language: ['c', 'cpp'])
elif cpp.get_id() == 'msvc'
# Force gcc to float64 long doubles for compatibility with MSVC
# builds, for C only.
add_project_arguments('-mlong-double-64', language: 'c')
endif

# API
winmm_dep = cpp.find_library('winmm', required: jack_not_found)
elif host_machine.system() == 'darwin'
# OSX

# Enable c++11 support
add_project_arguments('-std=c++11', language: ['cpp'])

# API
coremidi_dep = dependency(
'appleframeworks',
modules: ['coreaudio', 'coremidi', 'foundation'],
required: jack_not_found
)
else
# LINUX

# API
alsa_dep = dependency('alsa', required: jack_not_found)
threads_dep = dependency('threads')
endif # Platform detection

pymod = import('python')
python = pymod.find_installation(get_option('python'), required: true)

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

9 changes: 6 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ keywords = [
meson-python-option-name = "python"
meson-options = [
"-Dwheel=true",
"-Dverbose=true",
"--buildtype=plain"
]

Expand Down Expand Up @@ -84,6 +85,10 @@ skip = "pp*"
manylinux-x86_64-image = "manylinux_2_28"
manylinux-aarch64-image = "manylinux_2_28"

# Run the package tests using `pytest`
test-command = "pytest {package}/tests/test_basic.py"
test-requires = "pytest"

# Install system library
[tool.cibuildwheel.linux]
build = "cp3{8,9,10,11}-manylinux*"
Expand All @@ -110,6 +115,4 @@ before-all = [
[tool.cibuildwheel.windows]
build = "cp3{8,9,10,11}-win*"
archs = ["AMD64"]
before-all = [
"pipx install ninja",
]
build-verbosity = 1
7 changes: 5 additions & 2 deletions rtmidi/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,9 @@ if host_machine.system() == 'linux' and alsa_dep.found() and get_option('alsa')
endif

if host_machine.system() == 'windows' and get_option('winmm')
defines += ['-D__WINDOWS_MM__']
if meson.get_compiler('cpp').get_id() != 'gcc'
defines += ['-D__WINDOWS_MM__', '/EHsc']
defines += ['/EHsc']
endif
dependencies += [winmm_dep]
endif
Expand All @@ -36,7 +37,9 @@ if jack_dep.found() and get_option('jack')
dependencies += [jack_dep]
endif

if not get_option('verbose')
if get_option('verbose')
defines += ['-D__RTMIDI_DEBUG__']
else
defines += ['-D__RTMIDI_SILENCE_WARNINGS__']
endif

Expand Down
7 changes: 6 additions & 1 deletion src/_rtmidi.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,9 @@ used to specify the low-level MIDI backend API to use when creating a
Windows MultiMedia
``API_RTMIDI_DUMMY``
RtMidi Dummy API (used when no suitable API was found)
``API_RWEB_MIDI``
W3C Web MIDI API



Error types
Expand Down Expand Up @@ -113,7 +116,7 @@ from libcpp.vector cimport vector

__all__ = (
'API_UNSPECIFIED', 'API_MACOSX_CORE', 'API_LINUX_ALSA', 'API_UNIX_JACK',
'API_WINDOWS_MM', 'API_RTMIDI_DUMMY', 'ERRORTYPE_DEBUG_WARNING',
'API_WINDOWS_MM', 'API_RTMIDI_DUMMY', 'API_WEB_MIDI', 'ERRORTYPE_DEBUG_WARNING',
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this change should warrant a minor version number increase.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure it's actually usable 'tho

'ERRORTYPE_DRIVER_ERROR', 'ERRORTYPE_INVALID_DEVICE',
'ERRORTYPE_INVALID_PARAMETER', 'ERRORTYPE_INVALID_USE',
'ERRORTYPE_MEMORY_ERROR', 'ERRORTYPE_NO_DEVICES_FOUND',
Expand Down Expand Up @@ -148,6 +151,7 @@ cdef extern from "RtMidi.h":
UNIX_JACK "RtMidi::UNIX_JACK"
WINDOWS_MM "RtMidi::WINDOWS_MM"
RTMIDI_DUMMY "RtMidi::RTMIDI_DUMMY"
WEB_MIDI "RtMidi::WEB_MIDI_API"

cdef enum ErrorType "RtMidiError::Type":
ERR_WARNING "RtMidiError::WARNING"
Expand Down Expand Up @@ -244,6 +248,7 @@ API_LINUX_ALSA = LINUX_ALSA
API_UNIX_JACK = UNIX_JACK
API_WINDOWS_MM = WINDOWS_MM
API_RTMIDI_DUMMY = RTMIDI_DUMMY
API_WEB_MIDI = WEB_MIDI

# export error values to Python

Expand Down
1 change: 1 addition & 0 deletions src/meson_dist_cython.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
ap.add_argument("mod_source", nargs="*", help="Cython module C++ source target(s) (*.cpp).")
args = ap.parse_args()


if args.verbose:
print("cwd:", getcwd())
print("build root:", build_root)
Expand Down
2 changes: 1 addition & 1 deletion src/rtmidi
Submodule rtmidi updated 3 files
+1 −1 RtMidi.cpp
+1 −0 rtmidi_c.cpp
+3 −2 rtmidi_c.h
72 changes: 72 additions & 0 deletions tests/test_basic.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
""" Basic tests that don't need midi ports"""

import unittest
import rtmidi


if bytes is str:
string_types = (str, unicode) # noqa:F821
else:
string_types = (str,)


class BasicTest(unittest.TestCase):
def test_get_api_display_name(self):
self.assertEqual(rtmidi.get_api_display_name(rtmidi.API_LINUX_ALSA), 'ALSA')
self.assertEqual(rtmidi.get_api_display_name(rtmidi.API_MACOSX_CORE), 'CoreMidi')
self.assertEqual(rtmidi.get_api_display_name(rtmidi.API_RTMIDI_DUMMY), 'Dummy')
self.assertEqual(rtmidi.get_api_display_name(rtmidi.API_UNIX_JACK), 'Jack')
self.assertEqual(rtmidi.get_api_display_name(rtmidi.API_UNSPECIFIED), 'Unknown')
self.assertEqual(rtmidi.get_api_display_name(rtmidi.API_WINDOWS_MM), 'Windows MultiMedia')
self.assertEqual(rtmidi.get_api_display_name(rtmidi.API_WEB_MIDI), 'Web MIDI API')

def test_get_api_name(self):
self.assertEqual(rtmidi.get_api_name(rtmidi.API_LINUX_ALSA), 'alsa')
self.assertEqual(rtmidi.get_api_name(rtmidi.API_MACOSX_CORE), 'core')
self.assertEqual(rtmidi.get_api_name(rtmidi.API_RTMIDI_DUMMY), 'dummy')
self.assertEqual(rtmidi.get_api_name(rtmidi.API_UNIX_JACK), 'jack')
self.assertEqual(rtmidi.get_api_name(rtmidi.API_UNSPECIFIED), 'unspecified')
self.assertEqual(rtmidi.get_api_name(rtmidi.API_WINDOWS_MM), 'winmm')
self.assertEqual(rtmidi.get_api_name(rtmidi.API_WEB_MIDI), 'web')

def test_get_compiled_api(self):
apilist = rtmidi.get_compiled_api()
self.assertTrue(isinstance(apilist, list))
self.assertTrue(len(apilist) >= 1)
for api in apilist:
self.assertTrue(api <= rtmidi.API_RTMIDI_DUMMY)

def test_get_compiled_api_by_name(self):
for api, name in (
(rtmidi.API_LINUX_ALSA, 'alsa'),
(rtmidi.API_MACOSX_CORE, 'core'),
(rtmidi.API_RTMIDI_DUMMY, 'dummy'),
(rtmidi.API_UNIX_JACK, 'jack'),
(rtmidi.API_WINDOWS_MM, 'winmm'),
(rtmidi.API_WEB_MIDI, 'web'),):

res = rtmidi.get_compiled_api_by_name(name)

if api in rtmidi.get_compiled_api():
self.assertEqual(res, api)
else:
self.assertEqual(res, rtmidi.API_UNSPECIFIED)

def test_get_rtmidi_version(self):
version = rtmidi.get_rtmidi_version()
self.assertTrue(isinstance(version, string_types))
self.assertEqual(version, '5.0.0')

def test_nondummy_api_present(self):
# Make sure at least one actual API has been compiled
apilist = rtmidi.get_compiled_api()
apiFound = False
for api in apilist:
if api != rtmidi.API_RTMIDI_DUMMY:
apiFound = True
self.assertTrue(apiFound)

if __name__ == '__main__':
unittest.main()