TooTallNate/node-time

Installation not working on FreeBSD

byWulf opened this issue · 5 comments

Hi,
when trying to install node-time with npm install time on FreeBSD (8.3-RELEASE-p4), I get an error because the time.h on FreeBSD is kindly different in the following points:

  • no declaration for daylight
  • different type for timezone (char *timezone(int, int);)

(See time.h for FreeBSD here: https://github.com/freebsd/freebsd/blob/master/include/time.h)

I get the following error when trying to install it:

npm WARN package.json sleep@1.1.0 'repositories' (plural) Not supported.
npm WARN package.json Please pick one as the 'repository' field
npm http GET https://registry.npmjs.org/time
npm http 304 https://registry.npmjs.org/time
npm http GET https://registry.npmjs.org/debug
npm http GET https://registry.npmjs.org/bindings
npm http 304 https://registry.npmjs.org/debug
npm http 304 https://registry.npmjs.org/bindings

> time@0.9.2 install /root/node_modules/time
> node-gyp rebuild

gmake: Entering directory `/root/node_modules/time/build'
  CXX(target) Release/obj.target/time/src/time.o
../src/time.cc: In static member function 'static v8::Handle<v8::Value> Time::Tzset(const v8::Arguments&)':
../src/time.cc:53: error: no matching function for call to 'v8::Number::New(char* (&)(int, int))'
/root/.node-gyp/0.10.17/deps/v8/include/v8.h:1377: note: candidates are: static v8::Local<v8::Number> v8::Number::New(double)
../src/time.cc:57: error: 'daylight' was not declared in this scope
gmake: *** [Release/obj.target/time/src/time.o] Error 1
gmake: Leaving directory `/root/node_modules/time/build'
gyp ERR! build error
gyp ERR! stack Error: `gmake` failed with exit code: 2
gyp ERR! stack     at ChildProcess.onExit (/root/node_modules/node-gyp/lib/build.js:256:23)
gyp ERR! stack     at ChildProcess.EventEmitter.emit (events.js:98:17)
gyp ERR! stack     at Process.ChildProcess._handle.onexit (child_process.js:789:12)
gyp ERR! System FreeBSD 8.3-RELEASE-p4
gyp ERR! command "node" "/root/node_modules/.bin/node-gyp" "rebuild"
gyp ERR! cwd /root/node_modules/time
gyp ERR! node -v v0.10.17
gyp ERR! node-gyp -v v0.9.2
gyp ERR! not ok
npm ERR! weird error 1
npm ERR! not ok code 0

When trying to fix it manually (adding an external int daylight; and changing the type of timezone to double timezone;) in the systems time.h, the installation over npm works, but then I get a runtime error in my node script:

Error: /root/node_modules/time/build/Release/time.node: Undefined symbol "daylight"

Thank you for looking into this problem!

Does not work on FreeBSD-9.1 either. Did you find a workaround?

Sadly not. Switching to Ubuntu now in a few days...

sbat commented

👍

Hi,

I am using cozy.io under FreeBSD and their sync app use node-time.
Your node module is very important.
Do you plan to port node-time under FreeBSD ?

Regards, Frédéric.

I spent longer on this than I probably should have, and I don't know the full correct fix. But maybe others will find this useful.

  1. time.cc:74 and time.cc:78 make no sense on FreeBSD. timezone is a function from time.h, not a data type. And daylight is just straight up undefined. In order to make them do what the MSC block before it does, I changed mine to this:
66 #else
67     for (int i=0; i < tznameLength; i++) {
68       Nan::Set(tznameArray, i, Nan::New<v8::String>(tzname[i]).ToLocalChecked());
69     }
70
71     Nan::Set(obj, Nan::New("tzname").ToLocalChecked(), tznameArray);
72
73     time_t rawtime = 0;
74     time(&rawtime);
75     struct tm *timeinfo = localtime( &rawtime );
76     // The 'timezone' long is the "seconds West of UTC"
77     Nan::Set(obj, Nan::New("timezone").ToLocalChecked(), Nan::New<v8::Number>( timeinfo->tm_gmtoff ));
78
79     // The 'daylight' int is obselete actually, but I'll include it here for
80     // curiosity's sake. See the "Notes" section of "man tzset"
81     Nan::Set(obj, Nan::New("daylight").ToLocalChecked(), Nan::New<v8::Number>( timeinfo->tm_isdst ));
82 #endif
83     info.GetReturnValue().Set(scope.Escape(obj));
  1. By now it compiles, but gives back NaN for timezones. That's because of time.cc:104. It checks for HAVE_TM_GMTOFF and that doesn't pass. I don't know why, because FreeBSD's struct tm definitely has gmtoff. So, for my purposes, I just hacked that in...
107 #define HAVE_TM_GMTOFF
108
109 #if defined HAVE_TM_GMTOFF
110       // Only available with glibc's "tm" struct. Most Linuxes, Mac OS X...
111       Nan::Set(obj, Nan::New("gmtOffset").ToLocalChecked(), Nan::New<v8::Number>(timeinfo->tm_gmtoff) );
112       Nan::Set(obj, Nan::New("timezone").ToLocalChecked(), Nan::New(timeinfo->tm_zone).ToLocalChecked() );

And then it worked properly for me.