| Jens Geyer | bd52f1a | 2014-07-28 01:25:30 +0200 | [diff] [blame] | 1 | Thrift Haxe Software Library |
| 2 | |
| 3 | License |
| 4 | ======= |
| 5 | |
| 6 | Licensed to the Apache Software Foundation (ASF) under one |
| 7 | or more contributor license agreements. See the NOTICE file |
| 8 | distributed with this work for additional information |
| 9 | regarding copyright ownership. The ASF licenses this file |
| 10 | to you under the Apache License, Version 2.0 (the |
| 11 | "License"); you may not use this file except in compliance |
| 12 | with the License. You may obtain a copy of the License at |
| 13 | |
| 14 | http://www.apache.org/licenses/LICENSE-2.0 |
| 15 | |
| 16 | Unless required by applicable law or agreed to in writing, |
| 17 | software distributed under the License is distributed on an |
| 18 | "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 19 | KIND, either express or implied. See the License for the |
| 20 | specific language governing permissions and limitations |
| 21 | under the License. |
| 22 | |
| 23 | Using Thrift with Haxe |
| 24 | ======================== |
| 25 | |
| Jens Geyer | 04488dd | 2015-05-14 17:16:20 +0200 | [diff] [blame] | 26 | Haxe setup |
| 27 | --------------- |
| 28 | |
| Jens Geyer | 662eea9 | 2015-02-01 20:20:34 +0100 | [diff] [blame] | 29 | Thrift requires Haxe 3.1.3. Installers for Windows and OSX |
| 30 | platforms are available at `http://haxe.org/download`. |
| Jens Geyer | bd52f1a | 2014-07-28 01:25:30 +0200 | [diff] [blame] | 31 | |
| Jens Geyer | 04488dd | 2015-05-14 17:16:20 +0200 | [diff] [blame] | 32 | Depending on the desired targets, you may have to install the appropriate HaxeLibs |
| 33 | after installing Haxe itself. For example, if you plan to target C#, Java and C++, |
| 34 | enter the following commands after installing Haxe: |
| 35 | |
| 36 | haxelib install hxcpp |
| 37 | haxelib install hxjava |
| 38 | haxelib install hxcs |
| 39 | |
| 40 | For other targets, please consult the Haxe documentation whether or not any additional |
| 41 | target libraries need to be installed and how to achieve this. |
| 42 | |
| 43 | |
| 44 | Haxe on Linux |
| 45 | --------------- |
| 46 | |
| Jens Geyer | 90b6304 | 2017-04-02 16:01:11 +0200 | [diff] [blame] | 47 | For Linux platforms it is recommended to use the distro-specific package |
| 48 | manager, where possible. More detailed information can be found at the |
| 49 | Haxe Linux download section: http://haxe.org/download/linux |
| Jens Geyer | 662eea9 | 2015-02-01 20:20:34 +0100 | [diff] [blame] | 50 | |
| Jens Geyer | 04488dd | 2015-05-14 17:16:20 +0200 | [diff] [blame] | 51 | If you run into the error message |
| 52 | |
| 53 | Uncaught exception - load.c(237) : Failed to load library : /usr/lib/neko/regexp.ndll |
| 54 | (libpcre.so.3: cannot open shared object file: No such file or directory) |
| 55 | |
| 56 | this can be solved depending on your OSes bitness by either |
| 57 | |
| 58 | sudo ln -sf /usr/lib/libpcre.so.1 /usr/lib/libpcre.so.3 |
| 59 | sudo ldconfig |
| 60 | |
| 61 | or |
| 62 | |
| 63 | sudo ln -sf /usr/lib64/libpcre.so.1 /usr/lib64/libpcre.so.3 |
| 64 | sudo ldconfig |
| 65 | |
| 66 | Thrift Haxe bindings |
| 67 | ------------------- |
| 68 | |
| Jens Geyer | 662eea9 | 2015-02-01 20:20:34 +0100 | [diff] [blame] | 69 | Thrift Haxe bindings can be set up via the `haxelib` tool |
| 70 | either from the official ASF repo, or via the github mirror. |
| Jens Geyer | b029aa8 | 2014-11-15 23:54:16 +0100 | [diff] [blame] | 71 | |
| Jens Geyer | 90b6304 | 2017-04-02 16:01:11 +0200 | [diff] [blame] | 72 | - To set up any **stable version**, choose the appropriate branch (e.g. `0.10.0`): |
| Jens Geyer | b029aa8 | 2014-11-15 23:54:16 +0100 | [diff] [blame] | 73 | |
| Jens Geyer | 90b6304 | 2017-04-02 16:01:11 +0200 | [diff] [blame] | 74 | - `haxelib git thrift https://git.apache.org/thrift.git 0.10.0 lib/haxe` |
| 75 | - `haxelib git thrift https://github.com/apache/thrift.git 0.10.0 lib/haxe` |
| Jens Geyer | b029aa8 | 2014-11-15 23:54:16 +0100 | [diff] [blame] | 76 | |
| 77 | - To set up the current **development version**, use the `master` branch: |
| 78 | |
| Jens Geyer | 04488dd | 2015-05-14 17:16:20 +0200 | [diff] [blame] | 79 | - `haxelib git thrift https://git.apache.org/thrift.git master lib/haxe` |
| Jens Geyer | 662eea9 | 2015-02-01 20:20:34 +0100 | [diff] [blame] | 80 | - `haxelib git thrift https://github.com/apache/thrift.git master lib/haxe` |
| Jens Geyer | b029aa8 | 2014-11-15 23:54:16 +0100 | [diff] [blame] | 81 | |
| 82 | As usual, the installed library can be updated using `haxelib upgrade` |
| 83 | or `haxelib update thrift`. |
| 84 | |
| 85 | In order to work with Thrift, you will need to install the Thrift compiler |
| 86 | or build from source, depending on your operating system. Appropriate |
| 87 | downloads and more information can be found at http://thrift.apache.org |
| 88 | |
| Jens Geyer | bd52f1a | 2014-07-28 01:25:30 +0200 | [diff] [blame] | 89 | To get started, visit the /tutorial/haxe and /test/haxe dirs for examples. |
| Jens Geyer | b029aa8 | 2014-11-15 23:54:16 +0100 | [diff] [blame] | 90 | If you are using HIDE or the FlashDevelop IDE, you'll find appropriate |
| 91 | project files in these folders. |
| Jens Geyer | bd52f1a | 2014-07-28 01:25:30 +0200 | [diff] [blame] | 92 | |
| 93 | |
| 94 | Current status |
| 95 | ======================== |
| 96 | - tested with Haxe C++ target |
| Oleksii Prudkyi | 39a09ac | 2016-05-19 16:55:11 +0300 | [diff] [blame] | 97 | - tested with Haxe PHP target (console/web server, binary protocols) |
| 98 | - transports: Socket, HTTP (servers run inside PHP server/PHP target only), Stream |
| Jens Geyer | 04488dd | 2015-05-14 17:16:20 +0200 | [diff] [blame] | 99 | - protocols: Binary, JSON, Multiplex, Compact |
| Jens Geyer | bd52f1a | 2014-07-28 01:25:30 +0200 | [diff] [blame] | 100 | - tutorial client and server available |
| 101 | - cross-test client and server available |
| 102 | |
| 103 | |
| 104 | Further developments |
| 105 | ======================== |
| Jens Geyer | bd52f1a | 2014-07-28 01:25:30 +0200 | [diff] [blame] | 106 | - improve to work with C#, Java and JavaScript Haxe/OpenFL targets |
| 107 | - improve to work with more (ideally all) Haxe/OpenFL targets |
| Jens Geyer | fea00ac | 2014-10-01 02:22:48 +0200 | [diff] [blame] | 108 | - add HTTP server, update tutorial and tests accordingly |
| Jens Geyer | bd52f1a | 2014-07-28 01:25:30 +0200 | [diff] [blame] | 109 | |
| 110 | |
| Jens Geyer | bd52f1a | 2014-07-28 01:25:30 +0200 | [diff] [blame] | 111 | Known restrictions |
| 112 | ======================== |
| 113 | |
| 114 | Although designed with maximum portability in mind, for technical reasons some platforms |
| 115 | may only support parts of the library, or not be compatible at all. |
| 116 | |
| 117 | Javascript: |
| 118 | - tutorial fails to build because of unsupported Sys.args |
| 119 | |
| Oleksii Prudkyi | 39a09ac | 2016-05-19 16:55:11 +0300 | [diff] [blame] | 120 | PHP HTTP Server notes |
| 121 | ======================== |
| 122 | |
| 123 | - you have to import PHP files generated by haxe into PHP |
| 124 | ```php |
| 125 | require_once dirname(__FILE__) . '/bin/php-web-server/Main-debug.php'; |
| 126 | ``` |
| 127 | |
| 128 | - trace() by default outputs into stdout (http response), so you have to redirect it to stderr or you own logs, something like |
| 129 | ```haxe |
| 130 | //remap trace to error log |
| 131 | haxe.Log.trace = function(v:Dynamic, ?infos:haxe.PosInfos) |
| 132 | { |
| 133 | //simulate normal trace https://github.com/HaxeFoundation/haxe/blob/development/std/haxe/Log.hx |
| 134 | var newValue : Dynamic; |
| 135 | if (infos != null && infos.customParams!=null) { |
| 136 | var extra:String = ""; |
| 137 | for( v in infos.customParams ) |
| 138 | extra += "," + v; |
| 139 | newValue = v + extra; |
| 140 | } |
| 141 | else { |
| 142 | newValue = v; |
| 143 | } |
| 144 | var msg = infos != null ? infos.fileName + ':' + infos.lineNumber + ': ' : ''; |
| 145 | Sys.stderr().writeString('${msg}${newValue}\n'); |
| 146 | } |
| 147 | ``` |
| 148 | |
| 149 | - to allow thrift server to read/write HTTP request/response, it should be pointed out to php streams |
| 150 | ```haxe |
| 151 | transport = new TWrappingServerTransport( |
| 152 | new TStreamTransport( |
| 153 | new TFileStream("php://input", Read), |
| 154 | new TFileStream("php://output", Append) |
| 155 | ) |
| 156 | ); |
| 157 | ``` |
| 158 | |
| 159 | - TSimpleServer doesn't stop after first call, so processor.process() should be called instead, or use runOnce property |
| 160 | ```haxe |
| 161 | var server = new TSimpleServer( processor, transport, transfactory, protfactory); |
| 162 | server.runOnce = true; |
| 163 | ``` |
| 164 | |