Skip to content
This repository has been archived by the owner on Jul 23, 2019. It is now read-only.

Linux Build Compatibility #25

Merged
merged 2 commits into from Mar 7, 2018
Merged

Conversation

apcragg
Copy link

@apcragg apcragg commented Mar 7, 2018

I changed the napi build script to work on Linux platforms in addition to MacOS. I am using the built-in Node.js os module to detect the user's system type in order to copy the correct dynamic library file. I also included <string.h> as I was having issues with memcpy not working on Ubuntu 16.04 LTS.

This address comments in #15

Copy link

@daviwil daviwil left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Works for me on Fedora Linux 27!

@daviwil daviwil mentioned this pull request Mar 7, 2018
@daviwil
Copy link

daviwil commented Mar 7, 2018

Getting this error on macOS:

--- stderr
thread 'main' panicked at 'function not loaded: clang_Type_getNumTemplateArguments', /Users/daviwil/.cargo/registry/src/github.com-1ecc6299db9ec823/clang-sys-0.21.1/src/lib.rs:1456:1
note: Run with `RUST_BACKTRACE=1` for a backtrace.

child_process.js:644
    throw err;
    ^

Error: Command failed: cargo rustc  -Clink-args="-undefined -dynamic_lookup -export_dynamic"
    at checkExecSyncError (child_process.js:601:13)
    at Object.execSync (child_process.js:641:13)
    at Object.<anonymous> (/Users/daviwil/Projects/Work/xray/napi/scripts/napi.js:48:8)
    at Module._compile (module.js:652:30)
    at Object.Module._extensions..js (module.js:663:10)
    at Module.load (module.js:565:32)
    at tryModuleLoad (module.js:505:12)
    at Function.Module._load (module.js:497:3)
    at Function.Module.runMain (module.js:693:10)
    at startup (bootstrap_node.js:188:16)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! xray@0.0.1 build: `napi build`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the xray@0.0.1 build script.

I'm on macOS 10.12.6 so I dunno if this is a clang version issue, but I'll keep poking at it.

@apcragg
Copy link
Author

apcragg commented Mar 7, 2018

clang --version
clang version 3.8.0-2ubuntu4 (tags/RELEASE_380/final)
Target: x86_64-pc-linux-gnu

This is the Clang version I am working with. As a quick though, try changing -dynamic_lookup to just dynamic_lookup which is what it was prior to my PR. I assumed the missing "-" was a typo as adding it did not cause issues for me but the "num template arguments" error makes me suspicious.

@daviwil
Copy link

daviwil commented Mar 7, 2018

Nah, didn't make a difference, I get the same error.

@apcragg
Copy link
Author

apcragg commented Mar 7, 2018

Try changing -Clink-args to -- -Clink-args

@daviwil
Copy link

daviwil commented Mar 7, 2018

No change:

Error: Command failed: cargo rustc --release -- -Clink-args="-undefined -dynamic_lookup -export_dynamic"

@daviwil
Copy link

daviwil commented Mar 7, 2018

FWIW I get the same error without the changes you've made, so it's probably an issue with my clang version or the configuration of my machine. Here's my clang --version output:

Apple LLVM version 6.0 (clang-600.0.54) (based on LLVM 3.5svn)
Target: x86_64-apple-darwin16.7.0
Thread model: posix

case 'darwin':
libExt = '.dylib'
break;
case 'linux':

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe add linux as last case and let it fall-through because value is same for linux and default?

@apcragg
Copy link
Author

apcragg commented Mar 7, 2018

I changed the default behavior to exit the build process and warn if the OS isn't recognized. I think this is more helpful than potentially using the wrong dynamic library type only to get cryptic "ELF header" errors later in the build process. I also fixed a hyphen typo I introduced in my previous commit.

@nathansobo
Copy link

Hey @apcragg, could you omit the changes to the lock files? I need to ignore those for the subcomponents and figure out why it's changing on the electron app. If you let me push changes to your branch I could do it too.

switch (subcommand) {
case 'build':
const releaseFlag = argv.release ? '--release' : ''
const targetDir = argv.release ? 'release' : 'debug'
cp.execSync(`cargo rustc ${releaseFlag} -- -Clink-args=\"-undefined dynamic_lookup -export_dynamic\"`, {stdio: 'inherit'})
cp.execSync(`cp target/${targetDir}/{lib${moduleName}.dylib,${moduleName}.node}`, {stdio: 'inherit'})
cp.execSync(`cargo rustc ${releaseFlag} -- -Clink-args=\"-undefined=dynamic_lookup -export_dynamic\"`, {stdio: 'inherit'})

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For me, the = sign in -undefined=dynamic_lookup is causing an error. It only works when we go back to replacing = with a space.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That must be a mac/linux thing because I can only compile using Clang 3.9 on Ubuntu 16.04 LTS with the '=' sign. I will remove the package lock changes and add the '=' sign to the os case statement.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does it work for you with -undefined,dynamic_lookup as that also works with Linux.

Copy link
Author

@apcragg apcragg Mar 7, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The problem seems to be that on MacOS, linker -flag <arg> is valid but on Linux it is being seen as linker -flag [linker-file-target]. Since dynamic_lookup isn't a valid file or directory for the clang linker, it throws an error. If `linker -flag,' (no space) works for MacOS then this seems like a cross-platform fix. If anyone has more insight on the discrepancy please let me know.

@nathansobo
Copy link

@daviwil Could you try to tweak the script to see the stderr output associated with the cargo invocation failure?

Copy link

@nathansobo nathansobo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to get the following issues ironed out before we can merge this:

  • Confirm that we can build on Linux
  • Continue to build correctly on macOS (the = in -undefined=dynamic_lookup is currently breaking for me)
  • Omit changes to lock files
  • Rebase into 1 or 2 commits to keep the history clean

@daviwil
Copy link

daviwil commented Mar 7, 2018

Apparently I had removed Xcode from my machine a while back and clang wasn't getting updated anymore. Reinstalled Xcode and now my clang is up to date:

Apple LLVM version 9.0.0 (clang-900.0.39.2)
Target: x86_64-apple-darwin17.4.0
Thread model: posix

Building against master works fine now but building against this PR fails due to the argument changes to clang, as Nathan noted.

@apcragg
Copy link
Author

apcragg commented Mar 7, 2018

@daviwil Could you take a look at my earlier comment and try replacing the = with ,?

@apcragg
Copy link
Author

apcragg commented Mar 7, 2018

I cleaned up the pull request to meet the requested changes. I still need confirmation that these changes work on MacOS.

  • Confirm that we can build on Linux
  • Continue to build correctly on macOS (the = in -undefined=dynamic_lookup is currently breaking for me)
  • Omit changes to lock files
  • Rebase into 1 or 2 commits to keep the history clean

@daviwil
Copy link

daviwil commented Mar 7, 2018

Sorry for the delay, just tried your suggestion and it didn't work, but this does:

cp.execSync(`cargo rustc ${releaseFlag} -- -Clink-args=\"-undefined dynamic_lookup -export_dynamic\"`, {stdio: 'inherit'})

However, when I use these arguments with clang 5.0.1 on Fedora, they don't work. Using -undefined=dynamic_lookup -export_dynamic is the only thing that works. Looks like we need to massage the args per platform?

@apcragg
Copy link
Author

apcragg commented Mar 7, 2018

I added per-platform args. It should maintain the previous working behavior on MacOS and allow building on Linux systems

@daviwil
Copy link

daviwil commented Mar 7, 2018

Works perfectly for me now on both Linux and macOS!

@nathansobo
Copy link

Thanks for figuring this out @apcragg and thanks @daviwil for test driving it. I'm going to apply some small style tweaks on master, but otherwise this looks great. Thanks!

Now we just have to understand these mysterious build failures some people are getting on macOS and hopefully our build story will be golden.

Thanks again! ⚡️

@nathansobo nathansobo merged commit 8c67a8e into atom-archive:master Mar 7, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants