{"action":"created","issue":{"url":"https://api.github.com/repos/kripken/emscripten/issues/2427","repository_url":"https://api.github.com/repos/kripken/emscripten","labels_url":"https://api.github.com/repos/kripken/emscripten/issues/2427/labels{/name}","comments_url":"https://api.github.com/repos/kripken/emscripten/issues/2427/comments","events_url":"https://api.github.com/repos/kripken/emscripten/issues/2427/events","html_url":"https://github.com/kripken/emscripten/issues/2427","id":35724447,"number":2427,"title":"Unable to compile a simple Swift file (maybe not possible?)","user":{"login":"geelen","id":23264,"avatar_url":"https://avatars.githubusercontent.com/u/23264?v=3","gravatar_id":"","url":"https://api.github.com/users/geelen","html_url":"https://github.com/geelen","followers_url":"https://api.github.com/users/geelen/followers","following_url":"https://api.github.com/users/geelen/following{/other_user}","gists_url":"https://api.github.com/users/geelen/gists{/gist_id}","starred_url":"https://api.github.com/users/geelen/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/geelen/subscriptions","organizations_url":"https://api.github.com/users/geelen/orgs","repos_url":"https://api.github.com/users/geelen/repos","events_url":"https://api.github.com/users/geelen/events{/privacy}","received_events_url":"https://api.github.com/users/geelen/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":48,"created_at":"2014-06-14T09:11:45Z","updated_at":"2016-05-06T11:14:12Z","closed_at":null,"body":"Hi team, playing around with Emscripten in earnest for the first time, not my usual area of work so apologies if this is clearly never going to work. What I'd like to do is compile a simple Swift program to JS:\r\n\r\n```swift\r\nprintln(\"Hello, world!\")\r\n```\r\n\r\nSo far what I've tried is:\r\n\r\n```sh\r\nxcrun swift hello_world.swift -emit-bc -o hello_world.bc\r\nemcc hello_world.bc\r\n```\r\n\r\nbut that fails because it can't find certain symbols (looks like the standard library isn't present):\r\n\r\n```sh\r\nValue:   %1 = call { i8*, i64, i64 } @_TFSS37_convertFromBuiltinUTF16StringLiteralfMSSFTBp17numberOfCodeUnitsBw_SS(i8* bitcast ([14 x i16]* @0 to i8*), i64 13)\r\nLLVM ERROR: Unrecognized struct value\r\nTraceback (most recent call last):\r\n  File \"/Users/glen/Downloads/emsdk_portable/emscripten/1.16.0/emcc\", line 1540, in <module>\r\n    shared.Building.llvm_opt(final, link_opts)\r\n  File \"/Users/glen/Downloads/emsdk_portable/emscripten/1.16.0/tools/shared.py\", line 1267, in llvm_opt\r\n    assert os.path.exists(target), 'Failed to run llvm optimizations: ' + output\r\nAssertionError: Failed to run llvm optimizations:\r\n```\r\n\r\nDrilling a bit further, and looking at how `xcrun swift -v hello_world.swift` actually works, I'm able to use this linking command to compile the bitcode to an executable using normal `ld`.\r\n\r\n```sh\r\ncp /Applications/Xcode6-Beta.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/macosx/libswift_stdlib_core.dylib .\r\n/usr/bin/ld hello_world.bc \\\r\n              -lSystem -arch x86_64 \\\r\n              -L . -rpath . \\\r\n              -o hello_world\r\n./hello_world\r\n=> Hello, world!\r\n```\r\n\r\nSo, it seems like `libswift_stdlib_core.dylib` is the only dependency for `hello_world.bc` to be properly linked to an executable.\r\n\r\nBut I'm stuck - is there some equivalent between the `-L` and `-rpath` flags on `ld` that I should be passing to `emcc`? Or is a dylib like that not possible to be used in emscripten? The final command I tried was:\r\n\r\n```sh\r\n> emcc libswift_stdlib_core.dylib hello_world.bc                                 ~/src/experiments/swift.js • 2.1.0p0\r\nWARNING  root: emcc: cannot find library \"swift_stdlib_core\"\r\nValue:   %1 = call { i8*, i64, i64 } @_TFSS37_convertFromBuiltinUTF16StringLiteralfMSSFTBp17numberOfCodeUnitsBw_SS(i8* bitcast ([14 x i16]* @0 to i8*), i64 13)\r\nLLVM ERROR: Unrecognized struct value\r\nTraceback (most recent call last):\r\n  File \"/Users/glen/Downloads/emsdk_portable/emscripten/1.16.0/emcc\", line 1540, in <module>\r\n    shared.Building.llvm_opt(final, link_opts)\r\n  File \"/Users/glen/Downloads/emsdk_portable/emscripten/1.16.0/tools/shared.py\", line 1267, in llvm_opt\r\n    assert os.path.exists(target), 'Failed to run llvm optimizations: ' + output\r\nAssertionError: Failed to run llvm optimizations:\r\n```\r\n\r\nHopefully something's possible from here - Swift is a neat high-level language with a nice type system and no garbage collector, which makes me think it's a good fit for compiling to JS."},"comment":{"url":"https://api.github.com/repos/kripken/emscripten/issues/comments/217413633","html_url":"https://github.com/kripken/emscripten/issues/2427#issuecomment-217413633","issue_url":"https://api.github.com/repos/kripken/emscripten/issues/2427","id":217413633,"user":{"login":"ephemer","id":5485935,"avatar_url":"https://avatars.githubusercontent.com/u/5485935?v=3","gravatar_id":"","url":"https://api.github.com/users/ephemer","html_url":"https://github.com/ephemer","followers_url":"https://api.github.com/users/ephemer/followers","following_url":"https://api.github.com/users/ephemer/following{/other_user}","gists_url":"https://api.github.com/users/ephemer/gists{/gist_id}","starred_url":"https://api.github.com/users/ephemer/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ephemer/subscriptions","organizations_url":"https://api.github.com/users/ephemer/orgs","repos_url":"https://api.github.com/users/ephemer/repos","events_url":"https://api.github.com/users/ephemer/events{/privacy}","received_events_url":"https://api.github.com/users/ephemer/received_events","type":"User","site_admin":false},"created_at":"2016-05-06T11:14:12Z","updated_at":"2016-05-06T11:14:12Z","body":"@kripken Thanks for the link to the IRC channel.\r\n\r\nThe bit about 'compiled in' is what I don't really understand yet. Do users depend on a static `libc++` that gets compiled into the LLVM IR before emscripten has anything to do with it? Or do they link against a dylib that is somehow later provided automatically by emscripten?"}}