Skip to content

Commit

Permalink
Defines new arcs_kt_particles build rule (PolymerLabs#4298)
Browse files Browse the repository at this point in the history
* Defines new arcs_kt_particles build rule

This replaces arcs_kt_binary.

There are two main advantages for using this rule instead of
arcs_kt_binary:
1. You can bundles lots of particles together into the one wasm binary
   (technically you could do this before using arcs_kt_binary, but we
   weren't)
2. It will let us do interesting things when compiling particles (e.g.
   generate wasm bindings, etc.)

* Update new tutorial

* Fix test

* lint
  • Loading branch information
csilvestrini authored Dec 17, 2019
1 parent 855ed2f commit 7233f5f
Show file tree
Hide file tree
Showing 24 changed files with 206 additions and 204 deletions.
11 changes: 7 additions & 4 deletions particles/Native/Wasm/BUILD
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
load(
"//third_party/java/arcs/build_defs:build_defs.bzl",
"arcs_cc_schema",
"arcs_kt_binary",
"arcs_kt_particles",
"arcs_kt_schema",
"arcs_manifest",
"arcs_manifest_bundle",
)
load("//third_party/java/arcs/build_defs/emscripten:build_defs.bzl", "cc_wasm_binary")
load(
"//third_party/java/arcs/build_defs/emscripten:build_defs.bzl",
"cc_wasm_binary",
)

licenses(["notice"])

Expand All @@ -28,12 +31,12 @@ arcs_kt_schema(
srcs = ["Harness.arcs"],
)

arcs_kt_binary(
arcs_kt_particles(
name = "service_particle",
srcs = ["source/ServiceParticle.kt"],
)

arcs_kt_binary(
arcs_kt_particles(
name = "test_particle",
srcs = ["source/TestParticle.kt"],
deps = [":wasm_schemas"],
Expand Down
6 changes: 4 additions & 2 deletions particles/Tutorial/Kotlin/1_HelloWorld/BUILD
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
load("//third_party/java/arcs/build_defs:build_defs.bzl", "arcs_kt_binary")
load("//third_party/java/arcs/build_defs:build_defs.bzl", "arcs_kt_particles")

arcs_kt_binary(
licenses(["notice"])

arcs_kt_particles(
name = "HelloWorld",
srcs = ["HelloWorld.kt"],
)
6 changes: 4 additions & 2 deletions particles/Tutorial/Kotlin/2_BasicTemplates/BUILD
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
load("//third_party/java/arcs/build_defs:build_defs.bzl", "arcs_kt_binary")
load("//third_party/java/arcs/build_defs:build_defs.bzl", "arcs_kt_particles")

arcs_kt_binary(
licenses(["notice"])

arcs_kt_particles(
name = "BasicTemplate",
srcs = ["BasicTemplate.kt"],
)
13 changes: 5 additions & 8 deletions particles/Tutorial/Kotlin/3_RenderSlots/BUILD
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
load("//third_party/java/arcs/build_defs:build_defs.bzl", "arcs_kt_binary")
load("//third_party/java/arcs/build_defs:build_defs.bzl", "arcs_kt_particles")

arcs_kt_binary(
name = "ParentParticle",
srcs = ["ParentParticle.kt"],
)
licenses(["notice"])

arcs_kt_binary(
name = "ChildParticle",
srcs = ["ChildParticle.kt"],
arcs_kt_particles(
name = "RenderSlots",
srcs = glob(["*.kt"]),
)
4 changes: 2 additions & 2 deletions particles/Tutorial/Kotlin/3_RenderSlots/RenderSlots.arcs
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@
// Creates two particles, and renders one inside the other using render slots.

// The "parent" particle. It provides a slot for another particle to be rendered inside it.
particle ParentParticle in 'ParentParticle.wasm'
particle ParentParticle in 'RenderSlots.wasm'
// This particle renders to the root slot ("consumes" it), and provides a slot inside it called "mySlot" in which another particle can render
// itself. The child particle will be rendered inside a special div with the identifier "mySlot", which this particle will need to provide in
// its HTML.
root: consumes
mySlot: provides

// The "child" particle. Instead of consuming "root" it consumes "mySlot", which connects it to the slot provided by ParentParticle.
particle ChildParticle in 'ChildParticle.wasm'
particle ChildParticle in 'RenderSlots.wasm'
render: consumes

recipe RenderSlotsRecipe
Expand Down
20 changes: 10 additions & 10 deletions particles/Tutorial/Kotlin/4_Handles/BUILD
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
load("//third_party/java/arcs/build_defs:build_defs.bzl", "arcs_kt_binary", "arcs_kt_schema")
load(
"//third_party/java/arcs/build_defs:build_defs.bzl",
"arcs_kt_particles",
"arcs_kt_schema",
)

licenses(["notice"])

arcs_kt_schema(
name = "handles_schemas",
srcs = ["Handles.arcs"],
package = "arcs.tutorials",
)

arcs_kt_binary(
name = "GetPerson",
srcs = ["GetPerson.kt"],
deps = [":handles_schemas"],
)

arcs_kt_binary(
name = "DisplayGreeting",
srcs = ["DisplayGreeting.kt"],
arcs_kt_particles(
name = "Handles",
srcs = glob(["*.kt"]),
deps = [":handles_schemas"],
)
8 changes: 4 additions & 4 deletions particles/Tutorial/Kotlin/4_Handles/Handles.arcs
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
// Define a schema that allows us to store a person's name
// Define a schema that allows us to store a person's name
schema Person
name: Text

// The GetPerson particle allows the user to input their name, then writes
// the input to the Person handle.
// This particle also provides a slot to display a greeting to the person.
particle GetPerson in 'GetPerson.wasm'
particle GetPerson in 'Handles.wasm'
person: writes Person
root: consumes
greetingSlot: provides

// The DisplayGreeting particle, takes the name passed through the Person
// handle, and displays a greeting.
particle DisplayGreeting in 'DisplayGreeting.wasm'
particle DisplayGreeting in 'Handles.wasm'
person: reads Person
greetingSlot: consumes

recipe HandleRecipe
GetPerson
// Pass the output person to the handle recipePerson.
person: writes recipePerson
person: writes recipePerson
root: consumes
greetingSlot: provides greeting
DisplayGreeting
Expand Down
10 changes: 8 additions & 2 deletions particles/Tutorial/Kotlin/5_Collections/BUILD
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
load("//third_party/java/arcs/build_defs:build_defs.bzl", "arcs_kt_binary", "arcs_kt_schema")
load(
"//third_party/java/arcs/build_defs:build_defs.bzl",
"arcs_kt_particles",
"arcs_kt_schema",
)

licenses(["notice"])

arcs_kt_schema(
name = "collections_schemas",
srcs = ["Collections.arcs"],
)

arcs_kt_binary(
arcs_kt_particles(
name = "Collections",
srcs = ["Collections.kt"],
deps = [":collections_schemas"],
Expand Down
10 changes: 8 additions & 2 deletions particles/Tutorial/Kotlin/6_JsonStore/BUILD
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
load("//third_party/java/arcs/build_defs:build_defs.bzl", "arcs_kt_binary", "arcs_kt_schema")
load(
"//third_party/java/arcs/build_defs:build_defs.bzl",
"arcs_kt_particles",
"arcs_kt_schema",
)

licenses(["notice"])

arcs_kt_schema(
name = "store_schemas",
srcs = ["JsonStore.arcs"],
package = "arcs.tutorials",
)

arcs_kt_binary(
arcs_kt_particles(
name = "JsonStore",
srcs = ["JsonStore.kt"],
deps = [":store_schemas"],
Expand Down
28 changes: 13 additions & 15 deletions particles/Tutorial/Kotlin/Demo/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -316,22 +316,20 @@ fun constructTTTBoard() = TTTBoard().toAddress()

And finally, to build it all we need the BUILD file:
```BUILD
load("//third_party/java/arcs/build_defs:build_defs.bzl", "arcs_kt_binary", "arcs_kt_schema")
load(
"//third_party/java/arcs/build_defs:build_defs.bzl",
"arcs_kt_particles",
"arcs_kt_schema",
)
arcs_kt_schema(
name = "game_schemas",
srcs = ["TTTGame.arcs"],
)
arcs_kt_binary(
name = "TTTBoard",
srcs = ["TTTBoard.kt"],
deps = [":game_schemas"],
)
arcs_kt_binary(
name = "TTTGame",
srcs = ["TTTGame.kt"],
arcs_kt_particles(
name = "particles",
srcs = glob("*.kt"),
deps = [":game_schemas"],
)
```
Expand Down Expand Up @@ -382,25 +380,25 @@ game!

Currently you should have a tic-tac-toe board that does nothing.
Sure, you can click it and see the Events populate, but that is
still rather boring. Let's make it more fun by adding a human
still rather boring. Let's make it more fun by adding a human
player. By now, that original design we made in the first section
is probably not in the forefront of your mind, so we'll start by
looking at our design diagram.

![Tic Tac Toe Design](diagrams/TTT.jpg)
![Tic Tac Toe Design](diagrams/TTT.jpg)

From this, we can see that the Human Player needs a Player and
Move handle, and these handles connect the Game and Human Player.
We also need to populate the information about the player, so
we create a store. This updates our Arcs Manifest File to
we create a store. This updates our Arcs Manifest File to
the one [here](https://github.com/PolymerLabs/arcs/blob/master/particles/Tutorial/Kotlin/Demo/src/pt2/TTTGame.arcs).

Next, we create the human player to take the events stream and
convert it to a move. This can be viewed in TTTHumanPlayer.kt
convert it to a move. This can be viewed in TTTHumanPlayer.kt
[here](https://github.com/PolymerLabs/arcs/blob/master/particles/Tutorial/Kotlin/Demo/src/pt2/TTTHumanPlayer.kt).

Next, we need to update the game particle to update the board
based on the move. This gives us the updated TTTGame file
based on the move. This gives us the updated TTTGame file
[here](https://github.com/PolymerLabs/arcs/blob/master/particles/Tutorial/Kotlin/Demo/src/pt2/TTTGame.kt).

And finally, as always, we need to add the HumanPlayer to the
Expand Down
20 changes: 10 additions & 10 deletions particles/Tutorial/Kotlin/Demo/src/pt1/BUILD
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
load("//third_party/java/arcs/build_defs:build_defs.bzl", "arcs_kt_binary", "arcs_kt_schema")
load(
"//third_party/java/arcs/build_defs:build_defs.bzl",
"arcs_kt_particles",
"arcs_kt_schema",
)

licenses(["notice"])

arcs_kt_schema(
name = "game_schemas",
srcs = ["TTTGame.arcs"],
)

arcs_kt_binary(
name = "TTTBoard",
srcs = ["TTTBoard.kt"],
deps = [":game_schemas"],
)

arcs_kt_binary(
name = "TTTGame",
srcs = ["TTTGame.kt"],
arcs_kt_particles(
name = "particles",
srcs = glob(["*.kt"]),
deps = [":game_schemas"],
)
4 changes: 2 additions & 2 deletions particles/Tutorial/Kotlin/Demo/src/pt1/TTTGame.arcs
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ schema Event
time: Number


particle TTTBoard in 'TTTBoard.wasm'
particle TTTBoard in 'particles.wasm'
events: writes [Event]
gameState: reads GameState
boardSlot: consumes

particle TTTGame in 'TTTGame.wasm'
particle TTTGame in 'particles.wasm'
gameState: reads writes GameState
events: reads writes [Event]
root: consumes
Expand Down
26 changes: 10 additions & 16 deletions particles/Tutorial/Kotlin/Demo/src/pt2/BUILD
Original file line number Diff line number Diff line change
@@ -1,24 +1,18 @@
load("//third_party/java/arcs/build_defs:build_defs.bzl", "arcs_kt_binary", "arcs_kt_schema")
load(
"//third_party/java/arcs/build_defs:build_defs.bzl",
"arcs_kt_particles",
"arcs_kt_schema",
)

licenses(["notice"])

arcs_kt_schema(
name = "game_schemas",
srcs = ["TTTGame.arcs"],
)

arcs_kt_binary(
name = "TTTBoard",
srcs = ["TTTBoard.kt"],
deps = [":game_schemas"],
)

arcs_kt_binary(
name = "TTTGame",
srcs = ["TTTGame.kt"],
deps = [":game_schemas"],
)

arcs_kt_binary(
name = "TTTHumanPlayer",
srcs = ["TTTHumanPlayer.kt"],
arcs_kt_particles(
name = "particles",
srcs = glob(["*.kt"]),
deps = [":game_schemas"],
)
6 changes: 3 additions & 3 deletions particles/Tutorial/Kotlin/Demo/src/pt2/TTTGame.arcs
Original file line number Diff line number Diff line change
Expand Up @@ -24,20 +24,20 @@ resource HumanDefault

store HumanStore of Person in HumanDefault

particle TTTBoard in 'TTTBoard.wasm'
particle TTTBoard in 'particles.wasm'
events: writes [Event]
gameState: reads GameState
boardSlot: consumes

particle TTTGame in 'TTTGame.wasm'
particle TTTGame in 'particles.wasm'
gameState: reads writes GameState
playerOne: reads writes Person
playerOneMove: reads writes Move
events: reads writes [Event]
root: consumes
boardSlot: provides

particle TTTHumanPlayer in 'TTTHumanPlayer.wasm'
particle TTTHumanPlayer in 'particles.wasm'
gameState: reads GameState
events: reads [Event]
player: reads Person
Expand Down
30 changes: 8 additions & 22 deletions particles/Tutorial/Kotlin/Demo/src/pt3/BUILD
Original file line number Diff line number Diff line change
@@ -1,30 +1,16 @@
load("//third_party/java/arcs/build_defs:build_defs.bzl", "arcs_kt_binary", "arcs_kt_schema")
load(
"//third_party/java/arcs/build_defs:build_defs.bzl",
"arcs_kt_particles",
"arcs_kt_schema",
)

arcs_kt_schema(
name = "game_schemas",
srcs = ["TTTGame.arcs"],
)

arcs_kt_binary(
name = "TTTBoard",
srcs = ["TTTBoard.kt"],
deps = [":game_schemas"],
)

arcs_kt_binary(
name = "TTTGame",
srcs = ["TTTGame.kt"],
deps = [":game_schemas"],
)

arcs_kt_binary(
name = "TTTHumanPlayer",
srcs = ["TTTHumanPlayer.kt"],
deps = [":game_schemas"],
)

arcs_kt_binary(
name = "TTTRandomComputer",
srcs = ["TTTRandomComputer.kt"],
arcs_kt_particles(
name = "particles",
srcs = glob(["*.kt"]),
deps = [":game_schemas"],
)
Loading

0 comments on commit 7233f5f

Please sign in to comment.