github-linguist / linguist

Language Savant. If your repository's language is being reported incorrectly, send us a pull request!
MIT License
12.23k stars 4.23k forks source link

Failed to install the gem (build native extension) on Windows #4132

Closed yantang-msft closed 6 years ago

yantang-msft commented 6 years ago

I'm using ruby 2.4, and I already have charlock_holmes and rugged installed. Here is the error message:

Installing github-linguist 6.1.0 with native extensions Gem::Ext::BuildError: ERROR: Failed to build gem native extension.

current directory: D:/workdir/vendor/gems/github-linguist-6.1.0/ext/linguist C:/Ruby24-x64/bin/ruby.exe -r ./siteconf20180515-46084-zv96bg.rb extconf.rb creating Makefile

current directory: D:/workdir/vendor/gems/github-linguist-6.1.0/ext/linguist make "DESTDIR=" clean

current directory: D:/workdir/vendor/gems/github-linguist-6.1.0/ext/linguist make "DESTDIR=" generating linguist-x64-mingw32.def compiling lex.linguist_yy.c tokenizer.l: In function 'linguist_yylex': tokenizer.l:96:14: warning: implicit declaration of function 'strndup' [-Wimplicit-function-declaration]

[[:alnum:]_]+=\" { feed_token(strndup(yytext, strlen(yytext) - 1), REGULAR_TOKEN); eat_until_unescaped('"'); return 1; } ^ tokenizer.l:6:23: note: in definition of macro 'feed_token' yyextra->token = (tok); \ ^~~ tokenizer.l:96:14: warning: incompatible implicit declaration of built-in function 'strndup' [[:alnum:]_]+=\" { feed_token(strndup(yytext, strlen(yytext) - 1), REGULAR_TOKEN); eat_until_unescaped('"'); return 1; } ^ tokenizer.l:6:23: note: in definition of macro 'feed_token' yyextra->token = (tok); \ ^~~ tokenizer.l:97:14: warning: incompatible implicit declaration of built-in function 'strndup' [[:alnum:]_]+=' { feed_token(strndup(yytext, strlen(yytext) - 1), REGULAR_TOKEN); eat_until_unescaped('\''); return 1; } ^ tokenizer.l:6:23: note: in definition of macro 'feed_token' yyextra->token = (tok); \ ^~~ compiling linguist.c linking shared-object linguist/linguist.so lex.linguist_yy.o:lex.linguist_yy.c:(.text+0xe2d): undefined reference to `strndup' lex.linguist_yy.o:lex.linguist_yy.c:(.text+0x1109): undefined reference to `strndup' collect2.exe: error: ld returned 1 exit status make: *** [Makefile:259: linguist.so] Error 1 make failed, exit code 2 Gem files will remain installed in D:/workdir/vendor/gems/github-linguist-6.1.0 for inspection. Results logged to D:/workdir/vendor/extensions/x64-mingw32/2.4.0/github-linguist-6.1.0/gem_make.out An error occurred while installing github-linguist (6.1.0), and Bundler cannot continue. Make sure that `gem install github-linguist -v '6.1.0'` succeeds before bundling. In Gemfile: copyright-header was resolved to 1.0.22, which depends on github-linguist
lildude commented 6 years ago

/cc @kivikakk as this appears to relate to the tokenizer.

Alhadis commented 6 years ago

While I'm reminded: charlock_holmes is still biting my leg. 😁 Still computer swapping to run tests. :(

kivikakk commented 6 years ago

I'd like to reproduce and fix — the fix itself is quite easy (supply strndup implementation on platforms it's not included) — but I'm unable to get charlock_holmes installed on my Windows VM. I'll try looking into this later when I have more time.

yantang-msft commented 6 years ago

@kivikakk I followed this https://github.com/brianmario/charlock_holmes/issues/84#issuecomment-140239662 and to install charlock_holmes on Windows. Hope this is helpful.

kivikakk commented 6 years ago

@yantang-msft Thanks a lot! I did try that, and ended up with bizarre failures building icu itself. I'll try again shortly.

kivikakk commented 6 years ago

I've spent a bit trying to get this building on Windows, but to no avail. I won't have more time to try to work this out, but if anyone watching has a working Windows build, could you try dropping in an strndup implementation and seeing if it fixes the build? I strongly suspect it will.

yantang-msft commented 6 years ago

@kivikakk I confirm that adding the strndup implementation made it work locally. And it looks like more sophisticated conditions are needed for a real fix (e.g., https://github.com/rougier/freetype-gl/blob/master/platform.h#L16).

kivikakk commented 6 years ago

@yantang-msft Thank you so much for your attempt! Could you try the branch at #4154 to make sure it still works correctly? CI is passing which means it's ✅on Linux, and my local macOS build is good too.

yantang-msft commented 6 years ago

@kivikakk I confirm this fix works. Thanks for the quick response!