Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Split source / output #13

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@
*.hl
*.js
*.bc
.vscode
16 changes: 16 additions & 0 deletions .vscode/c_cpp_properties.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm assuming this file wasn't meant to be in here as you added .vscode to the .gitignore?

Copy link
Author

Choose a reason for hiding this comment

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

Correct.. I should not have pushed that.

"configurations": [
{
"name": "Linux",
"includePath": [
"${workspaceFolder}/**"
],
"defines": [],
"compilerPath": "/usr/bin/clang",
"cStandard": "c11",
"cppStandard": "c++17",
"intelliSenseMode": "clang-x64"
}
],
"version": 4
}
32 changes: 0 additions & 32 deletions sample/Makefile

This file was deleted.

29 changes: 0 additions & 29 deletions sample/SampleModule.hx

This file was deleted.

2 changes: 0 additions & 2 deletions sample/sample.html

This file was deleted.

45 changes: 45 additions & 0 deletions samples/simple/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
all:

OUT = "./webRoot/"

clean:
if [ -f $(OUT)lib_simple.bc ]; then rm $(OUT)lib_simple.bc; fi;
if [ -f $(OUT)lib_simple.cpp ]; then rm $(OUT)lib_simple.cpp; fi;
if [ -f $(OUT)lib_simple.js ]; then rm $(OUT)lib_simple.js; fi;
if [ -f $(OUT)lib_simple.wasm ]; then rm $(OUT)lib_simple.wasm; fi;

if [ -f $(OUT)simple.js ]; then rm $(OUT)simple.js; fi;

if [ -f $(OUT)point.bc ]; then rm $(OUT)point.bc; fi;
if [ -f $(OUT)context.bc ]; then rm $(OUT)context.bc; fi;

lib_simple.cpp:
haxe -lib webidl --macro "SimpleModule.buildLibCpp()"

lib_simple.js: lib_simple.cpp
haxe -lib webidl --macro "SimpleModule.buildLibJS()"

js: lib_simple.js
haxe -js $(OUT)simple.js -lib webidl -main Simple -dce full

# ---- HL PART

ifndef HLPATH
HLPATH = /path/to/hl
endif

lib_simple.hdll: lib_simple.cpp
$(CC) -o lib_simple.hdll -shared -Wall -O0 -I . -I $(HLPATH) lib_simple.cpp -lstdc++ -lhl

lib_simple: lib_simple.cpp
cl /olib_simple.hdll /LD /EHsc /I $(HLPATH) /DYNAMICBASE libhl.lib lib_simple.cpp

hl: lib_simple.hdll
haxe -hl simple.hl -lib webidl -main Simple

.PHONY: lib_simple.cpp lib_simple.js

.SUFFIXES : .cpp .o

.cpp.o:
$CC
1 change: 1 addition & 0 deletions samples/simple/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Simple example
16 changes: 11 additions & 5 deletions sample/Sample.hx → samples/simple/Simple.hx
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
import SampleModule.Point;
import SampleModule.Init as SampleModuleInit;
import SimpleModule.Point;
import SimpleModule.Context;
import SimpleModule.Init as SimpleModuleInit;

class Sample {
class Simple {

public static function main() {
SampleModuleInit.init(startApp);
SimpleModuleInit.init(startApp);
}

public static function startApp() {
/** Point */
var p1 = new Point();
p1.x = 4;
p1.y = 5;
Expand All @@ -17,5 +19,9 @@ class Sample {
p1.delete();
p2.delete();
p.delete();

/** Context */
var context = new Context();
context.test();
}
}
}
28 changes: 28 additions & 0 deletions samples/simple/SimpleModule.hx
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#if !macro
private typedef Import = haxe.macro.MacroType<[SimpleModule.build()]>;
#else

class SimpleModule {

static var json = {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm thinking we can simplify this block like so:

Suggested change
static var json = {
static var json = haxe.Json.parse(sys.io.File.getContent("./webidl.json"));

Copy link
Collaborator

Choose a reason for hiding this comment

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

The GitHub auto-commit thing won't remove the 4 lines below, so we'll need to do that manually.

var cc = sys.io.File.getBytes("./webidl.json");
var obj = haxe.Json.parse(cc.toString());
obj;
}

static var config: webidl.Options = json;

public static function build() {
return webidl.Module.build(config);
}

public static function buildLibCpp() {
webidl.Generate.generateCpp(config);
}

public static function buildLibJS() {
webidl.Generate.generateJs(config);
}
}

#end
6 changes: 6 additions & 0 deletions samples/simple/context.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#include "context.h"
#include "stdio.h"

void Context::test(){
printf("%s\n", "This is Context::test()");
}
13 changes: 13 additions & 0 deletions samples/simple/context.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#include "stdio.h"

#include "emscripten.h"
#include <GLES3/gl3.h>
#include <emscripten/html5.h>

class Context {
public:
Context(){
printf("%s\n", "Context Initialized");
}
void test();
};
9 changes: 9 additions & 0 deletions samples/simple/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<!doctype html>
Copy link
Collaborator

Choose a reason for hiding this comment

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

Do we need this index.html and the one in webRoot?

Copy link
Author

Choose a reason for hiding this comment

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

Well I like to not edit anything in webRoot directly and treat it all as generated.. You'll notice that the new build copies the index.html from the source root (which is still the project root) every time you compile.. so changes should be made in sources not in webRoot (output).

<html>
<head>
<meta charset="utf-8">
<link rel="shortcut icon" href="/favicon.ico?" />
<script src="lib_simple.js"></script>
<script src="simple.js"></script>
</head>
</html>
File renamed without changes.
File renamed without changes.
5 changes: 4 additions & 1 deletion sample/point.idl → samples/simple/simple.idl
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

interface Point {
attribute long x;
attribute long y;
Expand All @@ -8,3 +7,7 @@ interface Point {
double length();
};

interface Context {
void Context();
void test();
};
Binary file added samples/simple/webRoot/favicon.ico
Binary file not shown.
9 changes: 9 additions & 0 deletions samples/simple/webRoot/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<link rel="shortcut icon" href="/favicon.ico?" />
<script src="lib_simple.js"></script>
<script src="simple.js"></script>
</head>
</html>
7 changes: 7 additions & 0 deletions samples/simple/webidl.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"idlFile": "simple.idl",
"nativeLib": "lib_simple",
"sourceFiles": ["point.cpp", "context.cpp"],
zicklag marked this conversation as resolved.
Show resolved Hide resolved
"autoGC": false,
"out": "./webRoot"
}
Loading