NatWeiss / RapidGame

A commandline tool for Windows, Mac and Linux that prebuilds cocos2d-x static libraries. Also a cross-platform game templating system.
https://github.com/NatWeiss/RapidGame
MIT License
139 stars 22 forks source link

pre-building on windows targeting wrong MSBuild version #6

Closed adamyocum closed 9 years ago

adamyocum commented 9 years ago

I ran into an issue with the pre-build not targeting my most recent version of .net's MSBuild.

it was picking the lowest version available always. here is the verbose log, (with a couple extra console outputs)

Recursively copying src\cocos2d-js\frameworks\js-bindings\**\*.mk to 0.9.4\cocos2d\x\java\mk
Recursively copying src\cocos2d-js\frameworks\js-bindings\**\*.a to 0.9.4\cocos2d\x\java\mk
key (inside func)=4.0
Potential MSBuildToolsPath: C:\Windows\Microsoft.NET\Framework64\v2.0.50727\
checking version = 4 against highest 0
key (inside func)=4.0
Potential MSBuildToolsPath: C:\Windows\Microsoft.NET\Framework64\v3.5\
checking version = 4 against highest 4
key (inside func)=4.0
Potential MSBuildToolsPath: C:\Windows\Microsoft.NET\Framework64\v4.0.30319\
checking version = 4 against highest 4
Final MSBuildToolsPath: C:\Windows\Microsoft.NET\Framework64\v2.0.50727\
Building Windows Debug cocos2d-win32.vc2012.sln...
C:\Windows\Microsoft.NET\Framework64\v2.0.50727\MSBuild.exe C:\Users\xps420\AppData\Roaming\npm\node_modules\rapidgame\src\cocos2d-js\frameworks\js-bindings\cocos2d-x\build\cocos2d-win32.vc2012.sln /nologo /maxcpucount:4 /p:configuration=Debug
Current dir: C:\Users\xps420\AppData\Roaming\npm\node_modules\rapidgame
util.print: Use console.log instead
MSBUILD : error MSB1001: Unknown switch.
Switch: /maxcpucount:4

For switch syntax, type "MSBuild /help"

As you can see in my checking version = n against highest n the function was receiving the highest version number in each iteration. I fixed it by wrapping in an anonymous function and passing the 'key' variable in. I'd do a pull request, but don't have that all set up. here's the relevant function with the fix.. from line 826 in rapidgame.js...

// find path to MSBuildToolsPath
        for (i = 0; i < items.length; i += 1) {
            // try to get the value of MSBuildToolsPath
            key = path.basename(items[i].key);
            regKey = new Winreg({key: root + '\\' + key});  
            (function(key){
                regKey.get("MSBuildToolsPath", function(err, item) {
                    console.log("key (inside func)="+key);
                    count += 1;
                    if (err) {
                        console.log(err);
                    } else if (typeof item === "object" && typeof item.value === "string" && item.value.length) {
                        if (cmd.verbose) {
                            console.log("Potential MSBuildToolsPath: " + item.value);
                        }
                        console.log("checking version = "+ parseFloat(key) +" against highest " +highest);
                        if (parseFloat(key) > highest) {
                            buildPath = item.value;
                            highest = parseFloat(key);
                        }
                    }
                    if (count === items.length) {
                        if (buildPath.length) {
                            console.log("Final MSBuildToolsPath: " + buildPath);
                            callback(buildPath);
                        } else {
                            console.log("Unable to find MSBuild path");
                        }
                    }
                });
            })(key);
        }
NatWeiss commented 9 years ago

Ahh. Interesting solution and thanks for sharing!! Will merge this into the next release.

BTW, are you getting an error with /maxcpucount:4 ? I can remove that as well...

adamyocum commented 9 years ago

I don't get the maxcpucount error once it find a recent version of MSBuild, I read that apparently the older 2.0 version didn't support that option. On Mar 14, 2015 10:13 PM, "Nathanael Weiss" notifications@github.com wrote:

Ahh. Interesting solution and thanks for sharing!! Will merge this into the next release.

BTW, are you getting an error with /maxcpucount:4 ? I can remove that as well...

— Reply to this email directly or view it on GitHub https://github.com/NatWeiss/RapidGame/issues/6#issuecomment-80798316.

NatWeiss commented 9 years ago

Good. Will leave that in then, thanks again!

adamyocum commented 9 years ago

No prob, happy to help, I really like the approach your tool is taking with cocos2dx. I am working on my first game in the framework and just ran into an android audio bug that made me want to update to the most recent cocos version. Luckily while looking into the best way to do that I came across rapidgame. Hoping to move my project into it asap. I spent quite a bit of time today trying to get it fully working in windows. After fixing that MSBuild bug it now will prebuild the win32 libs, but I found that it was not letting me prebuild the android libs on windows. Running 'rapidgame prebuild android' just would rebuild the win32 libs again :'( I tracked it down and realized you have that disabled for now for windows. After 'enabling' it I found that when the android build is called on windows the nodejs 'spawn' call to the build.sh was failing due to a problem running 'ndk-which ar'. Turns out ndk-which required make to be installed. So I installed that with cygwin. But still now I got an error since it turns out even with make ndk-which doesn't play nice on windoz (facepalm) source ( https://groups.google.com/forum/#!topic/android-ndk/kjA63AYsZjM ) . Sooo, I hardcoded the paths for ar and strip (I know.) and got a little farther. Now the ndk build attempts but fails with another error message. I'm running the build.sh directly on the command line but it also fails if I let rapidgame run it for me, just not with as great of error messages.

$ ./build.sh armeabi Debug
PLATFORM=android-18
ARCH=armeabi
CONFIG=Debug
CORES=4
CC_ROOT=/cygdrive/c/Users/xps420/AppData/Roaming/npm/node_modules/rapidgame/src/cocos2d-js/frameworks/js-bindings
NDK_MODULE_PATH=/cygdrive/c/Users/xps420/AppData/Roaming/npm/node_modules/rapidgame/src/cocos2d-js/frameworks/js-bindings/cocos2d-x;/cygdrive/c/Users/xps420/AppData/Roaming/npm/node_modules/rapidgame/src/cocos2d-js/frameworks/js-bindings/cocos2d-x/external;/cygdrive/c/Users/xps420/AppData/Roaming/npm/node_modules/rapidgame/src/cocos2d-js/frameworks/js-bindings/cocos2d-x/cocos;/cygdrive/c/Users/xps420/AppData/Roaming/npm/node_modules/rapidgame/src/cocos2d-js/frameworks/js-bindings;/cygdrive/c/Users/xps420/AppData/Roaming/npm/node_modules/rapidgame/src
NDK_TOOLCHAIN_VERSION=4.8
AR=C:\AYall\SWD\tools\IDEs\Android\android-ndk-r10/toolchains/arm-linux-androideabi-4.8/prebuilt/windows-x86_64/bin/arm-linux-androideabi-ar.exe
STRIP=C:\AYall\SWD\tools\IDEs\Android\android-ndk-r10/toolchains/arm-linux-androideabi-4.8/prebuilt/windows-x86_64/bin/arm-linux-androideabi-strip.exe
CMD=C:\AYall\SWD\tools\IDEs\Android\android-ndk-r10/ndk-build --jobs=4 -C
/cygdrive/c/Users/xps420/AppData/Roaming/npm/node_modules/rapidgame/src/proj.android
NDK_MODULE_PATH=/cygdrive/c/Users/xps420/AppData/Roaming/npm/node_modules/rapidgame/src/cocos2d-js/frameworks/js-bindings/cocos2d-x;/cygdrive/c/Users/xps420/AppData/Roaming/npm/node_modules/rapidgame/src/cocos2d-js/frameworks/js-bindings/cocos2d-x/external;/cygdrive/c/Users/xps420/AppData/Roaming/npm/node_modules/rapidgame/src/cocos2d-js/frameworks/js-bindings/cocos2d-x/cocos;/cygdrive/c/Users/xps420/AppData/Roaming/npm/node_modules/rapidgame/src/cocos2d-js/frameworks/js-bindings;/cygdrive/c/Users/xps420/AppData/Roaming/npm/node_modules/rapidgame/src
APP_PLATFORM=android-18 APP_ABI=armeabi

Building android-18 armeabi Debug...
make: Entering directory
'/cygdrive/c/Users/xps420/AppData/Roaming/npm/node_modules/rapidgame/src/proj.android'
Android NDK: WARNING: Ignoring unknown import directory:
/cygdrive/c/Users/xps420/AppData/Roaming/npm/node_modules/rapidgame/src/cocos2d-js/frameworks/js-bindings/cocos2d-x;/cygdrive/c/Users/xps420/AppData/Roaming/npm/node_modules/rapidgame/src/cocos2d-js/frameworks/js-bindings/cocos2d-x/external;/cygdrive/c/Users/xps420/AppData/Roaming/npm/node_modules/rapidgame/src/cocos2d-js/frameworks/js-bindings/cocos2d-x/cocos;/cygdrive/c/Users/xps420/AppData/Roaming/npm/node_modules/rapidgame/src/cocos2d-js/frameworks/js-bindings;/cygdrive/c/Users/xps420/AppData/Roaming/npm/node_modules/rapidgame/src
APP_PLATFORM=android-18
APP_ABI=armeabi
APP_OPTIM=debug
APP_CPPFLAGS=-frtti -DCC_ENABLE_CHIPMUNK_INTEGRATION=1 -std=c++11
-fsigned-char -DCOCOS2D_JAVASCRIPT -DCOCOS2D_DEBUG=1
Android NDK: jni/Android.mk: Cannot find module with tag 'bindings' in
import path
Android NDK: Are you sure your NDK_MODULE_PATH variable is properly defined
?
Android NDK: The following directories were searched:
Android NDK:
jni/Android.mk:21: *** Android NDK: Aborting.    .  Stop.
make: Leaving directory
'/cygdrive/c/Users/xps420/AppData/Roaming/npm/node_modules/rapidgame/src/proj.android'
ndk-build failed.

I feel like I must be close at this point, but I'm getting stuck, why can't it find this 'bindings' module? any clues you could give me? Have you ever got this completely working in windows? TBH I'm thinking of getting a mac mini for game dev, but also I'd like to help get this working on windows also if possible.

Thanks, Adam

adamyocum commented 9 years ago

sorry for the spam, had to re-post my reply, email replies no likey markdown

adamyocum commented 9 years ago

I'm thinking my problem with the android build may be related to this line in the build output...

Android NDK: WARNING: Ignoring unknown import directory:

but not sure why as those directories listed after the warning all exist.

NatWeiss commented 9 years ago

Wow. I'm surprised the Android build even can work that well on Windows, as I've never ever tried it. (It's a lot of testing, upgrading and maintenance work just to keep RapidGame current on Mac let alone all the problems that come with Windows!)

So kudos for getting this far.

The module it's looking for is the cocos2d-x bindings. And boy do I know what you mean about Android build output being unhelpful!

You can do this to identify all the .mk files that Android might use:

find . -name *.mk

The particular one it is looking for is in src/cocos2d-js/frameworks/js-bindings/bindings/Android.mk. It looks like the problem is related to this error:

Android NDK: WARNING: Ignoring unknown import directory: /cygdrive/c/Users/xps420/AppData/Roaming/npm/node_modules/rapidgame/src/cocos2d-js/frameworks/js-bindings/cocos2d-x;/cygdrive/c/Users/xps420/AppData/Roaming/npm/node_modules/rapidgame/src/cocos2d-js/frameworks/js-bindings/cocos2d-x/external;/cygdrive/c/Users/xps420/AppData/Roaming/npm/node_modules/rapidgame/src/cocos2d-js/frameworks/js-bindings/cocos2d-x/cocos;/cygdrive/c/Users/xps420/AppData/Roaming/npm/node_modules/rapidgame/src/cocos2d-js/frameworks/js-bindings;/cygdrive/c/Users/xps420/AppData/Roaming/npm/node_modules/rapidgame/src

It's ignoring the most vital paths of all.

Maybe try colons instead of semi-colons? Or wrapping each or all in single or double quotes??

If not that, are those paths correct?

When it can successfully reference this path /cygdrive/c/Users/xps420/AppData/Roaming/npm/node_modules/rapidgame/src/cocos2d-js/frameworks/js-bindings...

Then this line in src/proj.android/jni/Android.mk ought to succeed:

$(call import-module,bindings)

There's also a chance that it might need to be referencing this path instead /cygdrive/c/Users/xps420/AppData/Roaming/npm/node_modules/rapidgame/latest/cocos2d/x/java. I can't remember how it's supposed to work on Windows right now...

Sorry that this is all the help I can be at this point!

adamyocum commented 9 years ago

Ha! I just came back here to post that it was the path separators needing to be colon instead of semi-colons and I see you've beaten me to the punch! Good intuition on that one! So it is now prebuilding the android libraries... Although my first run it finished with some missing file or directory messages when it tried to run the ar and strip commands. I see the \rapidgame\src\proj.android\obj\local\armeabi gets populated with lots of stuffs and the \rapidgame\src\proj.android\libs\armeabi gets one file named 'libcocos2djs.so' created. However nothing gets populated in \rapidgame\0.9.4\cocos2d\x\lib\Debug-Android\armeabi, this folder remains empty.

I'm sure it's possible as I build my Cocos2d-JS project for Android using the Cocos2d-IDE in windows all the time, but I'm still struggling to get rapidgame fully working on windows. Maybe I'll keep picking at it, but not sure how much time I'm really saving at this point. The IDE builds the android project pretty fast and allows debugging the html5 version very easily. I just hate that my games project folder is currently 901mb!! Was hoping this rapidgame tool was the answer, but maybe not for windows users yet. I may have to convert to Mac, watching you code in Xcode I was feeling like I am missing out.

Thanks for your help and keep up the good work!

NatWeiss commented 9 years ago

So it looks like it compiles everything fine (you got libcocos2djs.so), but it fails to archive all the .a files down into libcocos2dx-prebuilt.a.

Anyway, thanks for trying so hard! I agree, you're probably not saving time here and that's one of the purposes of RG. Cheers and feel free to keep in touch.

adamyocum commented 9 years ago

yep, it is really close, when it runs the ar command it complains that the target file is missing. Knowing how things go I tried some on the command line and came up with a solution that works, it's ugly, but this generates the libhcocos2dx-prebuilt.a file with just a single piece archived into it....

/cygdrive/c/AYall/SWD/tools/IDEs/Android/android-ndk-r10/toolchains/arm-linux-androideabi-4.8/prebuilt/windows-x86_64/bin/arm-linux-androideabi-ar rs C:\\Users\\xps420\\AppData\\Roaming\\npm\\node_modules\\rapidgame\\latest\\cocos2d\\x\\lib\\Debug-Android\\armeabi\\libcocos2dx-prebuilt.a C:\\Users\\xps420\\AppData\\Roaming\\npm\\node_modules\\rapidgame\\src\\proj.android\\obj\\local\\armeabi\\objs-debug\\cocos_localstorage_static\\LocalStorage-android.o

It seems that the arm-linux-androideabi-ar tool doesn't like the cygwin style paths to the files. So with some fudging I think I could get it working on windows if I can get it to use the right path style for the files.

I'll definitely be continuing to look into your stuff, including the awesome vids. I'm a long time developer, but kind of a noob to cocos and game development in general. Plus my c++ skills need brushing up :)

Have a good night.

-peace

NatWeiss commented 9 years ago

Nice job! :+1: Have a good night yourself.

NatWeiss commented 9 years ago

Latest release has Android building successfully on Windows. Thanks for your efforts here, Adam!

adamyocum commented 9 years ago

Awesome! I'll give it a try this weekend if I get the time. Thanks!

On Thu, Jun 4, 2015, 2:16 AM Nathanael Weiss notifications@github.com wrote:

Closed #6 https://github.com/NatWeiss/RapidGame/issues/6.

— Reply to this email directly or view it on GitHub https://github.com/NatWeiss/RapidGame/issues/6#event-322123045.

samoersnaes commented 9 years ago

Nice! I ran a full test with a fresh install today and everything should work for you as well as long as you follow the README. And just to let you know, when rapidgame builds the Android libraries, it will say "Building Android undefined..." Everything is working fine, it's just the output string was not constructed properly. It's already been fixed but won't come out until the next version.

On Fri, Jun 5, 2015 at 9:24 PM, Adam Yocum notifications@github.com wrote:

Awesome! I'll give it a try this weekend if I get the time. Thanks!

On Thu, Jun 4, 2015, 2:16 AM Nathanael Weiss notifications@github.com wrote:

Closed #6 https://github.com/NatWeiss/RapidGame/issues/6.

— Reply to this email directly or view it on GitHub https://github.com/NatWeiss/RapidGame/issues/6#event-322123045.

— Reply to this email directly or view it on GitHub https://github.com/NatWeiss/RapidGame/issues/6#issuecomment-109412696.