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 build for macOS #1

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

puddly
Copy link

@puddly puddly commented Dec 4, 2024

pybind11 doesn't like to compile mixed C/C++ codebases with Clang: C++17 features are used but setting cxx_std=17 causes Clang to fail when compiling C source files, since -std=c++17 isn't valid when building C.

I've worked around this problem by patching the distutils compiler at build time on macOS:

$ python -m build --wheel
...
Successfully built pymicro_features-1.0.0-cp311-cp311-macosx_14_0_arm64.whl

@synesthesiam
Copy link
Contributor

Would it work without the patch if we just renamed the .c files to .cc?

@puddly
Copy link
Author

puddly commented Dec 5, 2024

Converting them to C++ would require some patching:

pymicro-features/tensorflow/lite/experimental/microfrontend/lib/filterbank_util.cc:69:7: error: assigning to 'int16_t *' (aka 'short *') from incompatible type 'void *'
   69 |       malloc(num_channels_plus_1 * sizeof(*state->channel_frequency_starts));
      |       ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
pymicro-features/tensorflow/lite/experimental/microfrontend/lib/filterbank_util.cc:71:7: error: assigning to 'int16_t *' (aka 'short *') from incompatible type 'void *'
   71 |       malloc(num_channels_plus_1 * sizeof(*state->channel_weight_starts));
      |       ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
pymicro-features/tensorflow/lite/experimental/microfrontend/lib/filterbank_util.cc:73:7: error: assigning to 'int16_t *' (aka 'short *') from incompatible type 'void *'
   73 |       malloc(num_channels_plus_1 * sizeof(*state->channel_widths));
      |       ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
pymicro-features/tensorflow/lite/experimental/microfrontend/lib/filterbank_util.cc:74:17: error: assigning to 'uint64_t *' (aka 'unsigned long long *') from incompatible type 'void *'
   74 |   state->work = malloc(num_channels_plus_1 * sizeof(*state->work));
      |                 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
pymicro-features/tensorflow/lite/experimental/microfrontend/lib/filterbank_util.cc:76:10: error: cannot initialize a variable of type 'float *' with an rvalue of type 'void *'
   76 |   float* center_mel_freqs =
      |          ^
   77 |       malloc(num_channels_plus_1 * sizeof(*center_mel_freqs));
      |       ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
pymicro-features/tensorflow/lite/experimental/microfrontend/lib/filterbank_util.cc:78:12: error: cannot initialize a variable of type 'int16_t *' (aka 'short *') with an rvalue of type 'void *'
   78 |   int16_t* actual_channel_starts =
      |            ^
   79 |       malloc(num_channels_plus_1 * sizeof(*actual_channel_starts));
      |       ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
pymicro-features/tensorflow/lite/experimental/microfrontend/lib/filterbank_util.cc:80:12: error: cannot initialize a variable of type 'int16_t *' (aka 'short *') with an rvalue of type 'void *'
   80 |   int16_t* actual_channel_widths =
      |            ^
   81 |       malloc(num_channels_plus_1 * sizeof(*actual_channel_widths));
      |       ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
pymicro-features/tensorflow/lite/experimental/microfrontend/lib/filterbank_util.cc:163:20: error: assigning to 'int16_t *' (aka 'short *') from incompatible type 'void *'
  163 |   state->weights = calloc(weight_index_start, sizeof(*state->weights));
      |                    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
pymicro-features/tensorflow/lite/experimental/microfrontend/lib/filterbank_util.cc:164:22: error: assigning to 'int16_t *' (aka 'short *') from incompatible type 'void *'
  164 |   state->unweights = calloc(weight_index_start, sizeof(*state->unweights));
      |                      ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
9 errors generated.
error: command '/usr/bin/clang++' failed with exit code 1

@domdomegg
Copy link

This fixes the build for me on an Apple Silicon device running macOS 14.6.1 ✅

It'd be great to see either this or #2 merged soon :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants