| 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 | 2dcefad | 2021-02-25 09:42:52 +0100 | [diff] [blame] | 29 | Thrift requires Haxe 4.2.1. Installers for Windows and OSX |
| Jens Geyer | 662eea9 | 2015-02-01 20:20:34 +0100 | [diff] [blame] | 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 |
| Jens Geyer | 2dcefad | 2021-02-25 09:42:52 +0100 | [diff] [blame] | 33 | after installing Haxe itself. For example, if you plan to target C++, enter the |
| 34 | following command after installing Haxe: |
| Jens Geyer | 04488dd | 2015-05-14 17:16:20 +0200 | [diff] [blame] | 35 | |
| 36 | haxelib install hxcpp |
| Jens Geyer | 04488dd | 2015-05-14 17:16:20 +0200 | [diff] [blame] | 37 | |
| 38 | For other targets, please consult the Haxe documentation whether or not any additional |
| 39 | target libraries need to be installed and how to achieve this. |
| 40 | |
| 41 | |
| 42 | Haxe on Linux |
| 43 | --------------- |
| 44 | |
| Jens Geyer | 90b6304 | 2017-04-02 16:01:11 +0200 | [diff] [blame] | 45 | For Linux platforms it is recommended to use the distro-specific package |
| 46 | manager, where possible. More detailed information can be found at the |
| 47 | Haxe Linux download section: http://haxe.org/download/linux |
| Jens Geyer | 662eea9 | 2015-02-01 20:20:34 +0100 | [diff] [blame] | 48 | |
| Jens Geyer | 04488dd | 2015-05-14 17:16:20 +0200 | [diff] [blame] | 49 | If you run into the error message |
| 50 | |
| 51 | Uncaught exception - load.c(237) : Failed to load library : /usr/lib/neko/regexp.ndll |
| 52 | (libpcre.so.3: cannot open shared object file: No such file or directory) |
| 53 | |
| 54 | this can be solved depending on your OSes bitness by either |
| 55 | |
| 56 | sudo ln -sf /usr/lib/libpcre.so.1 /usr/lib/libpcre.so.3 |
| 57 | sudo ldconfig |
| 58 | |
| 59 | or |
| 60 | |
| 61 | sudo ln -sf /usr/lib64/libpcre.so.1 /usr/lib64/libpcre.so.3 |
| 62 | sudo ldconfig |
| 63 | |
| 64 | Thrift Haxe bindings |
| 65 | ------------------- |
| 66 | |
| Jens Geyer | 2dcefad | 2021-02-25 09:42:52 +0100 | [diff] [blame] | 67 | Thrift Haxe bindings can be set up via the `haxelib` tool as usual. |
| 68 | Alternatively, the "github" method can be used. |
| Jens Geyer | b029aa8 | 2014-11-15 23:54:16 +0100 | [diff] [blame] | 69 | |
| Jens Geyer | 2dcefad | 2021-02-25 09:42:52 +0100 | [diff] [blame] | 70 | - To set up any **stable version**, choose the appropriate branch (e.g. `0.14.1`): |
| Jens Geyer | b029aa8 | 2014-11-15 23:54:16 +0100 | [diff] [blame] | 71 | |
| Jens Geyer | 2dcefad | 2021-02-25 09:42:52 +0100 | [diff] [blame] | 72 | - `haxelib git thrift https://github.com/apache/thrift.git 0.14.1 lib/haxe` |
| Jens Geyer | b029aa8 | 2014-11-15 23:54:16 +0100 | [diff] [blame] | 73 | |
| 74 | - To set up the current **development version**, use the `master` branch: |
| 75 | |
| Jens Geyer | 662eea9 | 2015-02-01 20:20:34 +0100 | [diff] [blame] | 76 | - `haxelib git thrift https://github.com/apache/thrift.git master lib/haxe` |
| Jens Geyer | b029aa8 | 2014-11-15 23:54:16 +0100 | [diff] [blame] | 77 | |
| 78 | As usual, the installed library can be updated using `haxelib upgrade` |
| 79 | or `haxelib update thrift`. |
| 80 | |
| 81 | In order to work with Thrift, you will need to install the Thrift compiler |
| 82 | or build from source, depending on your operating system. Appropriate |
| 83 | downloads and more information can be found at http://thrift.apache.org |
| 84 | |
| Jens Geyer | bd52f1a | 2014-07-28 01:25:30 +0200 | [diff] [blame] | 85 | To get started, visit the /tutorial/haxe and /test/haxe dirs for examples. |
| Jens Geyer | 2dcefad | 2021-02-25 09:42:52 +0100 | [diff] [blame] | 86 | If you are using the HaxeDevelop IDE, you'll find appropriate project files |
| 87 | in these folders. |
| Jens Geyer | bd52f1a | 2014-07-28 01:25:30 +0200 | [diff] [blame] | 88 | |
| 89 | |
| Jens Geyer | 2dcefad | 2021-02-25 09:42:52 +0100 | [diff] [blame] | 90 | Breaking changes |
| Jens Geyer | bd52f1a | 2014-07-28 01:25:30 +0200 | [diff] [blame] | 91 | ======================== |
| Jens Geyer | 2dcefad | 2021-02-25 09:42:52 +0100 | [diff] [blame] | 92 | This version requires Haxe 4 and cannot be used with earlier versions. |
| Jens Geyer | bd52f1a | 2014-07-28 01:25:30 +0200 | [diff] [blame] | 93 | |
| Jens Geyer | 2dcefad | 2021-02-25 09:42:52 +0100 | [diff] [blame] | 94 | It is recommended to clear out all gen-haxe contents once before switching |
| 95 | to the new version. Otherwise you may run into troubles with leftovers from |
| 96 | previous versions. |
| Jens Geyer | bd52f1a | 2014-07-28 01:25:30 +0200 | [diff] [blame] | 97 | |
| Jens Geyer | 2dcefad | 2021-02-25 09:42:52 +0100 | [diff] [blame] | 98 | The compiler option ```callbacks``` is now obsolete. The compiler will always |
| 99 | generate a dual interface (i.e. with optional callback style) for use on the |
| 100 | client side, plus a new ```_service``` interface to be used for server |
| 101 | implementations. Consequentially, your client and server implementations will |
| 102 | need some manual intervention. |
| Jens Geyer | bd52f1a | 2014-07-28 01:25:30 +0200 | [diff] [blame] | 103 | |
| 104 | |
| Oleksii Prudkyi | 39a09ac | 2016-05-19 16:55:11 +0300 | [diff] [blame] | 105 | PHP HTTP Server notes |
| 106 | ======================== |
| 107 | |
| 108 | - you have to import PHP files generated by haxe into PHP |
| 109 | ```php |
| 110 | require_once dirname(__FILE__) . '/bin/php-web-server/Main-debug.php'; |
| 111 | ``` |
| 112 | |
| 113 | - trace() by default outputs into stdout (http response), so you have to redirect it to stderr or you own logs, something like |
| 114 | ```haxe |
| 115 | //remap trace to error log |
| 116 | haxe.Log.trace = function(v:Dynamic, ?infos:haxe.PosInfos) |
| 117 | { |
| 118 | //simulate normal trace https://github.com/HaxeFoundation/haxe/blob/development/std/haxe/Log.hx |
| 119 | var newValue : Dynamic; |
| 120 | if (infos != null && infos.customParams!=null) { |
| 121 | var extra:String = ""; |
| 122 | for( v in infos.customParams ) |
| 123 | extra += "," + v; |
| 124 | newValue = v + extra; |
| 125 | } |
| 126 | else { |
| 127 | newValue = v; |
| 128 | } |
| 129 | var msg = infos != null ? infos.fileName + ':' + infos.lineNumber + ': ' : ''; |
| 130 | Sys.stderr().writeString('${msg}${newValue}\n'); |
| 131 | } |
| 132 | ``` |
| 133 | |
| 134 | - to allow thrift server to read/write HTTP request/response, it should be pointed out to php streams |
| 135 | ```haxe |
| 136 | transport = new TWrappingServerTransport( |
| 137 | new TStreamTransport( |
| 138 | new TFileStream("php://input", Read), |
| 139 | new TFileStream("php://output", Append) |
| 140 | ) |
| 141 | ); |
| 142 | ``` |
| 143 | |
| 144 | - TSimpleServer doesn't stop after first call, so processor.process() should be called instead, or use runOnce property |
| 145 | ```haxe |
| 146 | var server = new TSimpleServer( processor, transport, transfactory, protfactory); |
| 147 | server.runOnce = true; |
| 148 | ``` |
| 149 | |