Skip to content

Commit

Permalink
Build on windows.
Browse files Browse the repository at this point in the history
  • Loading branch information
sobomax committed Jun 20, 2024
1 parent 6c1b1c3 commit 1558903
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 12 deletions.
15 changes: 11 additions & 4 deletions .github/workflows/build_and_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,14 @@ jobs:
python-version: ['3.8', '3.9', '3.10', '3.11', '3.12']
compiler: ['gcc', 'clang']
os: [macos, ubuntu]
include:
- python-version: '3.10'
compiler: microsoft
os: windows

runs-on: ${{ matrix.os }}-latest
env:
COMPILER: ${{ matrix.compiler }}
PYTHON_CMD: "python${{ matrix.python-version }}"

# Steps represent a sequence of tasks that will be executed as part of the job
steps:
Expand All @@ -49,17 +52,21 @@ jobs:
run: |
python -m pip install --upgrade pip
pip install setuptools wheel
shell: bash

- name: build
run: CC=${COMPILER} LDSHARED="${COMPILER} -shared" ${PYTHON_CMD} setup.py build sdist
run: CC=${COMPILER} LDSHARED="${COMPILER} -shared" python setup.py build sdist
shell: bash

- name: install
run: pip install dist/[Rr]tp*.gz
shell: bash

- name: test
run: |
CC=${COMPILER} ${PYTHON_CMD} setup.py runctest
${PYTHON_CMD} tests/test_jbuf.py
CC=${COMPILER} python setup.py runctest
python tests/test_jbuf.py
shell: bash

publish_wheels:
needs: build_and_test_python
Expand Down
14 changes: 10 additions & 4 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,16 @@

rs_srcs = ['src/rtpsynth.c', 'src/rtp.c', 'src/rtpjbuf.c']

extra_compile_args = ['--std=c11', '-Wno-zero-length-array', '-Wall', '-pedantic', '-flto']
extra_link_args = ['-flto']
is_win = get_platform().startswith('win')
is_mac = get_platform().startswith('macosx-')

extra_compile_args = ['--std=c11', '-Wall', '-pedantic']
if not is_win:
extra_compile_args += ['-Wno-zero-length-array', '-flto']
extra_link_args = ['-flto'] if not is_win else []
debug_opts = (('-g3', '-O0'))
if not get_platform().startswith('macosx-'):

if not is_mac and not is_win:
nodebug_opts = (('-march=native', '-O3'))
else:
nodebug_opts = (('-O3',))
Expand All @@ -32,7 +38,7 @@
RunCTest.extra_link_args = extra_link_args.copy()
RunCTest.extra_compile_args = extra_compile_args

if not get_platform().startswith('macosx-'):
if not is_mac and not is_win:
extra_link_args.append('-Wl,--version-script=src/Symbol.map')

def get_ex_mod():
Expand Down
8 changes: 8 additions & 0 deletions src/rtp.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,17 @@
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#if !defined(_WIN32) && !defined(_WIN64)
#include <netinet/in.h>
#else
#include <winsock.h>
#define LITTLE_ENDIAN 1234
#define BIG_ENDIAN 4321
#define BYTE_ORDER LITTLE_ENDIAN
#endif
#include <assert.h>
#include <stddef.h>
#include <stdint.h>

#include "rtp.h"
#include "rtp_info.h"
Expand Down
15 changes: 11 additions & 4 deletions src/rtp.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,17 @@ typedef enum rtp_type rtp_type_t;
# endif
#endif

#ifdef _MSC_VER
# define PACKED_STRUCT(name) \
__pragma(pack(push, 1)) struct name __pragma(pack(pop))
#elif defined(__GNUC__)
# define PACKED_STRUCT(name) struct __attribute__((packed)) name
#endif

/*
* RTP data header
*/
struct rtp_hdr {
PACKED_STRUCT(rtp_hdr) {
#if BYTE_ORDER == BIG_ENDIAN
unsigned int version:2; /* protocol version */
unsigned int p:1; /* padding flag */
Expand All @@ -101,13 +108,13 @@ struct rtp_hdr {
uint32_t ts; /* timestamp */
uint32_t ssrc; /* synchronization source */
uint32_t csrc[0]; /* optional CSRC list */
} __attribute__((__packed__));
};

struct rtp_hdr_ext {
PACKED_STRUCT(rtp_hdr_ext) {
uint16_t profile; /* defined by profile */
uint16_t length; /* length of the following array in 32-byte words */
uint32_t extension[0]; /* actual extension data */
} __attribute__((__packed__));
};

#if !defined(rtp_hdr_t_DEFINED)
typedef struct rtp_hdr rtp_hdr_t;
Expand Down
2 changes: 2 additions & 0 deletions src/rtpjbuf.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#if !defined(_WIN32) && !defined(_WIN64)
#include <arpa/inet.h>
#endif

#include <stdint.h>
#include <stdlib.h>
Expand Down

0 comments on commit 1558903

Please sign in to comment.