kjdev / php-ext-brotli

Brotli Extension for PHP
MIT License
168 stars 29 forks source link

fatal error U1073: don't know how to make 'brotli\c\common\constants.c' #33

Closed harryqt closed 1 year ago

harryqt commented 3 years ago
configure --disable-all --enable-cli --enable-brotli=shared

Error:

C:\php-sdk\phpmaster\vs16\x64\php-8.0.0-src
$ nmake

Microsoft (R) Program Maintenance Utility Version 14.28.29334.0
Copyright (C) Microsoft Corporation.  All rights reserved.

Recreating build dirs
Recreating build dirs
Recreating build dirs
Recreating build dirs
Recreating build dirs
        type ext\pcre\php_pcre.def > C:\php-sdk\phpmaster\vs16\x64\php-8.0.0-src\x64\Release_TS\php8ts.dll.def
NMAKE : fatal error U1073: don't know how to make 'brotli\c\common\constants.c'
Stop.
kjdev commented 3 years ago

Do you have a source of brotli?

The brotli directory is a submodule.

.
|-- php_brotli.h
|-- brotli.c
|-- brotli  (submodule)
    |-- c
        |-- common
        |   |-- constants.c
        |   ...
        |-- dec
        |   |-- bit_reader.c
        |   ...
        |-- enc
        |   |-- backward_references.c
        |   ...
harryqt commented 3 years ago

Do you have a source of brotli?

Yes. I do.

git clone --recursive --depth=1 https://github.com/kjdev/php-ext-brotli.git

I used this command to clone repo. Built previously for 7.4, maybe something has changed for 8.0

kjdev commented 3 years ago

If the brotli library is not found, the extesion source will be included in the build.

https://github.com/kjdev/php-ext-brotli/blob/master/config.w32

  if (CHECK_LIB("brotlicommon.lib;libbrotlicommon.lib", "brotli", PHP_BROTLI) &&
      CHECK_LIB("brotlidec.lib;libbrotlidec.lib", "brotli", PHP_BROTLI) &&
      CHECK_LIB("brotlienc.lib;libbrotlienc.lib", "brotli", PHP_BROTLI) &&
      CHECK_HEADER_ADD_INCLUDE("brotli/encode.h", "CFLAGS_BROTLI", PHP_BROTLI)) {
    EXTENSION("brotli", "brotli.c", PHP_BROTLI_SHARED, "/DZEND_ENABLE_STATIC_TSRMLS_CACHE=1");
  } else {
    EXTENSION("brotli", "brotli.c", PHP_BROTLI_SHARED, "/DZEND_ENABLE_STATIC_TSRMLS_CACHE=1");
    ADD_SOURCES("brotli/c/common", "constants.c context.c dictionary.c platform.c transform.c", "brotli");
    ADD_SOURCES("brotli/c/enc", "backward_references.c backward_references_hq.c bit_cost.c block_splitter.c brotli_bit_stream.c cluster.c command.c compress_fragment.c compress_fragment_two_pass.c dictionary_hash.c encode.c encoder_dict.c entropy_encode.c fast_log.c histogram.c literal_cost.c memory.c metablock.c static_dict.c utf8_util.c", "brotli");
    ADD_SOURCES("brotli/c/dec", "bit_reader.c decode.c huffman.c state.c", "brotli");

    ADD_FLAG("CFLAGS_BROTLI", " /I" + configure_module_dirname + " /I" + configure_module_dirname + "/brotli/c/include");
  }

ADD_SOURCES assumes that the brotoli sources are not included in the build, or that the source path is wrong.

Maybe I should try adding cofngiture_module_dirname to ADD_SORUCES.

ADD_SOURCES(configure_module_dirname + "/brotli/c/common", ...
harryqt commented 3 years ago

Maybe I should try adding cofngiture_module_dirname to ADD_SORUCES.

Did not work. I even tried with full path. Guess I will have to make peace with gzcompress

LoLFactor commented 1 year ago

Don't know if anybody's still interested, but after encountering this very issue, I managed to make it work for PHP 8.1, but it'll probably works for others as well.

The overall guide to how to set up the build environment for Windows can be found here.

Side-note, I used the latest version of the brotli source (as of today), so there were some missing files from the config, but I added those as well.

These are the three relevant lines in config.w32.

    ADD_SOURCES("ext/brotli/brotli/c/common", "constants.c context.c dictionary.c platform.c shared_dictionary.c transform.c", "brotli");
    ADD_SOURCES("ext/brotli/brotli/c/enc", "backward_references.c backward_references_hq.c bit_cost.c block_splitter.c brotli_bit_stream.c cluster.c command.c compress_fragment.c compress_fragment_two_pass.c compound_dictionary.c dictionary_hash.c encode.c encoder_dict.c entropy_encode.c fast_log.c histogram.c literal_cost.c memory.c metablock.c static_dict.c utf8_util.c", "brotli");
    ADD_SOURCES("ext/brotli/brotli/c/dec", "bit_reader.c decode.c huffman.c state.c", "brotli");

Looking around at other extension, I saw they rooted their ADD_SOURCES() call to the ext folder, so I tried that. Just make sure if you encounter this error to run buildconf --force and configure ... again after making the changes, or else you'll get the same error. @Dibbyo456, this is probably what happened to you. The configure_module_dirname change could have possibly worked. Maybe, I didn't try it.

Don't know if this breaks the Linux build (which works like a charm, BTW), but if it doesn't, it might be worthwhile to make it a permanent change.

As for the missing files, the linker complained about some missing symbols, and after some digging I found where those were defined in the brotli sources and added the files. They are:

After making these changes and runnning throught the whole buildconf, configure and nmake chain again, it worked.

Hope this helps!

Also, thanks to the extension author for the good work. Really appreciate you bringing this to the PHP extension ecosystem.