Skip to content

Commit

Permalink
Merge branch 'main' of https://github.com/winglang/wing into mark/fix…
Browse files Browse the repository at this point in the history
…-gcp-path
  • Loading branch information
MarkMcCulloh committed Apr 14, 2024
2 parents 2ff9d2b + 952327c commit 7277f30
Show file tree
Hide file tree
Showing 44 changed files with 1,145 additions and 1,040 deletions.
602 changes: 44 additions & 558 deletions Cargo.lock

Large diffs are not rendered by default.

7 changes: 6 additions & 1 deletion apps/wing/src/commands/lsp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,9 +136,14 @@ export async function lsp() {
for (const rd of raw_diagnostics) {
if (rd.span) {
const diagnosticUri = "file://" + rd.span.file_id;
let message = rd.message;
if (rd.hints.length > 0) {
message += `\n${rd.hints.map((hint) => `hint: ${hint}`).join("\n")}`;
}

const diag = Diagnostic.create(
Range.create(rd.span.start.line, rd.span.start.col, rd.span.end.line, rd.span.end.col),
`${rd.message}\n${rd.hints.map((hint) => `hint: ${hint}`).join("\n")}`,
message,
undefined,
undefined,
undefined,
Expand Down
116 changes: 116 additions & 0 deletions docs/contributing/999-rfcs/2024-03-31-wing-secrets-cli.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
---
title: "#6105 Wing Secrets CLI"
description: Creating Wing secrets from the CLI
---

# Wing Secrets CLI
- **Author(s)**: @hasanaburayyan
- **Submission Date**: 2024-03-31
- **Stage**: Draft

Creating secrets through the Wing CLI.

## Background

Wing applications often require secrets to be retrieved during runtime. These secrets are stored in platform specific secret stores, such as AWS Secrets Manager for `tf-aws` or a local `.env` file for the `sim` platform.

Secrets must be configured before the application is run, and now the Wing CLI along with Wing platforms make it easy to configure secrets.

### Out of Scope

In this RFC a few things are out of scope:
- Checking if the secrets exist in the platform's secret store when running `wing compile`
- Reading secret values, for now we will only focus on creating secrets

## Platform Hook

Since secrets creation is platform specific, platforms can now implement a new hook `configureSecrets(secrets: { [key: string]: string }): string` which will be called by the Wing CLI to configure the secrets.

For example the `sim` platform implementation which needs to store secrets in a `.env` file, would look something like this:

```js
public async configureSecrets(secrets: { [key: string]: string }): Promise<string> {
let existingSecretsContent = "";
try {
existingSecretsContent = fs.readFileSync('./.env', 'utf8');
} catch (error) {}

const existingSecrets = existingSecretsContent.split('\n')
.filter(line => line.trim() !== '')
.reduce((s, line) => {
const [key, value] = line.split('=', 2);
s[key] = value;
return s;
}, {} as { [key: string]: string });

for (const key in secrets) {
existingSecrets[key] = secrets[key];
}

const updatedContent = Object.entries(existingSecrets)
.map(([key, value]) => `${key}=${value}`)
.join('\n');

fs.writeFileSync('./.env', updatedContent);

return "Secrets saved to .env file";
}
```

## CLI Command

Introducing a new Wing CLI command `secrets` which will be used for managing secrets in the Wing applications.

Given the following Wing application:

```js
bring cloud;

let slackSigningSecret = new cloud.Secret(name: "SLACK_SIGNING_SECRET");
let slackBotToken = new cloud.Secret(name: "SLACK_BOT_TOKEN");
```

### Creating Secrets

Running `wing secrets main.w` will result in an interactive experience where the user is prompted to enter the values for the secrets:

```bash
wing secrets main.w

2 secrets found in main.w

Enter the value for SLACK_SIGNING_SECRET: ********
Enter the value for SLACK_BOT_TOKEN: ********

Secrets saved to .env file
```

This results in a `.env` file being created with the secrets stored in it.

### specifying the platform

You can specify the platform using the `-t` flag, for example to configure the secrets for the `tf-aws` platform:

```bash
wing secrets main.w -t tf-aws

2 secrets found in main.w

Enter the value for SLACK_SIGNING_SECRET: ********
Enter the value for SLACK_BOT_TOKEN: ********

Secrets saved to AWS Secrets Manager
```

### Listing Secrets

If the user prefers to ignore the interactive experience of creating secrets in favor of creating the secrets themselves, there is an option to list the secrets in the Wing application:

```bash
wing secrets main.w --list

2 secrets found in main.w

- SLACK_SIGNING_SECRET
- SLACK_BOT_TOKEN
```
39 changes: 39 additions & 0 deletions libs/tree-sitter-wing/.editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
root = true

[*]
charset = utf-8
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true

[*.{json,toml,yml,gyp}]
indent_style = space
indent_size = 2

[*.js]
indent_style = space
indent_size = 2

[*.rs]
indent_style = space
indent_size = 4

[*.{c,cc,h}]
indent_style = space
indent_size = 4

[*.{py,pyi}]
indent_style = space
indent_size = 4

[*.swift]
indent_style = space
indent_size = 4

[*.go]
indent_style = tab
indent_size = 8

[Makefile]
indent_style = tab
indent_size = 8
27 changes: 10 additions & 17 deletions libs/tree-sitter-wing/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,31 +1,24 @@
[package]
name = "tree-sitter-wing"
description = "winglang grammar for the tree-sitter parsing library"
description = "Wing grammar for tree-sitter"
version = "0.0.0"
keywords = ["incremental", "parsing", "wing"]
license = "MIT"
readme = "README.md"
keywords = ["incremental", "parsing", "tree-sitter", "wing"]
categories = ["parsing", "text-editors"]
repository = "https://github.com/winglang/wing/tree/main/libs/tree-sitter-wing"
repository = "https://github.com/winglang/tree-sitter-wing"
edition = "2021"
license = "MIT"
autoexamples = false

build = "bindings/rust/build.rs"
include = [
"bindings/rust/*",
"grammar.js",
"queries/*",
"src/*",
]
include = ["bindings/rust/*", "grammar.js", "queries/*", "src/*"]

[lib]
path = "bindings/rust/lib.rs"

[dependencies]
tree-sitter = "0.20.10"

[dev-dependencies]
tree-sitter-cli = "0.20.8"
# Waiting for https://github.com/tree-sitter/tree-sitter/pull/3293 to be released
tree-sitter = { git = "https://github.com/tree-sitter/tree-sitter.git", rev = "a7a47d561d4e64eaf226f93c4d68076afa67fdda" }

[build-dependencies]
cc = "1.0"
tree-sitter-cli = "0.20.8"
tree-sitter = "0.20.10"
cc = "1.0.87"
112 changes: 112 additions & 0 deletions libs/tree-sitter-wing/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
VERSION := 0.0.0

LANGUAGE_NAME := tree-sitter-wing

# repository
SRC_DIR := src

PARSER_REPO_URL := $(shell git -C $(SRC_DIR) remote get-url origin 2>/dev/null)

ifeq ($(PARSER_URL),)
PARSER_URL := $(subst .git,,$(PARSER_REPO_URL))
ifeq ($(shell echo $(PARSER_URL) | grep '^[a-z][-+.0-9a-z]*://'),)
PARSER_URL := $(subst :,/,$(PARSER_URL))
PARSER_URL := $(subst git@,https://,$(PARSER_URL))
endif
endif

TS ?= tree-sitter

# ABI versioning
SONAME_MAJOR := $(word 1,$(subst ., ,$(VERSION)))
SONAME_MINOR := $(word 2,$(subst ., ,$(VERSION)))

# install directory layout
PREFIX ?= /usr/local
INCLUDEDIR ?= $(PREFIX)/include
LIBDIR ?= $(PREFIX)/lib
PCLIBDIR ?= $(LIBDIR)/pkgconfig

# source/object files
PARSER := $(SRC_DIR)/parser.c
EXTRAS := $(filter-out $(PARSER),$(wildcard $(SRC_DIR)/*.c))
OBJS := $(patsubst %.c,%.o,$(PARSER) $(EXTRAS))

# flags
ARFLAGS ?= rcs
override CFLAGS += -I$(SRC_DIR) -std=c11 -fPIC

# OS-specific bits
ifeq ($(OS),Windows_NT)
$(error "Windows is not supported")
else ifeq ($(shell uname),Darwin)
SOEXT = dylib
SOEXTVER_MAJOR = $(SONAME_MAJOR).dylib
SOEXTVER = $(SONAME_MAJOR).$(SONAME_MINOR).dylib
LINKSHARED := $(LINKSHARED)-dynamiclib -Wl,
ifneq ($(ADDITIONAL_LIBS),)
LINKSHARED := $(LINKSHARED)$(ADDITIONAL_LIBS),
endif
LINKSHARED := $(LINKSHARED)-install_name,$(LIBDIR)/lib$(LANGUAGE_NAME).$(SONAME_MAJOR).dylib,-rpath,@executable_path/../Frameworks
else
SOEXT = so
SOEXTVER_MAJOR = so.$(SONAME_MAJOR)
SOEXTVER = so.$(SONAME_MAJOR).$(SONAME_MINOR)
LINKSHARED := $(LINKSHARED)-shared -Wl,
ifneq ($(ADDITIONAL_LIBS),)
LINKSHARED := $(LINKSHARED)$(ADDITIONAL_LIBS)
endif
LINKSHARED := $(LINKSHARED)-soname,lib$(LANGUAGE_NAME).so.$(SONAME_MAJOR)
endif
ifneq ($(filter $(shell uname),FreeBSD NetBSD DragonFly),)
PCLIBDIR := $(PREFIX)/libdata/pkgconfig
endif

all: lib$(LANGUAGE_NAME).a lib$(LANGUAGE_NAME).$(SOEXT) $(LANGUAGE_NAME).pc

lib$(LANGUAGE_NAME).a: $(OBJS)
$(AR) $(ARFLAGS) $@ $^

lib$(LANGUAGE_NAME).$(SOEXT): $(OBJS)
$(CC) $(LDFLAGS) $(LINKSHARED) $^ $(LDLIBS) -o $@
ifneq ($(STRIP),)
$(STRIP) $@
endif

$(LANGUAGE_NAME).pc: bindings/c/$(LANGUAGE_NAME).pc.in
sed -e 's|@URL@|$(PARSER_URL)|' \
-e 's|@VERSION@|$(VERSION)|' \
-e 's|@LIBDIR@|$(LIBDIR)|' \
-e 's|@INCLUDEDIR@|$(INCLUDEDIR)|' \
-e 's|@REQUIRES@|$(REQUIRES)|' \
-e 's|@ADDITIONAL_LIBS@|$(ADDITIONAL_LIBS)|' \
-e 's|=$(PREFIX)|=$${prefix}|' \
-e 's|@PREFIX@|$(PREFIX)|' $< > $@

$(PARSER): $(SRC_DIR)/grammar.json
$(TS) generate --no-bindings $^

install: all
install -d '$(DESTDIR)$(INCLUDEDIR)'/tree_sitter '$(DESTDIR)$(PCLIBDIR)' '$(DESTDIR)$(LIBDIR)'
install -m644 bindings/c/$(LANGUAGE_NAME).h '$(DESTDIR)$(INCLUDEDIR)'/tree_sitter/$(LANGUAGE_NAME).h
install -m644 $(LANGUAGE_NAME).pc '$(DESTDIR)$(PCLIBDIR)'/$(LANGUAGE_NAME).pc
install -m644 lib$(LANGUAGE_NAME).a '$(DESTDIR)$(LIBDIR)'/lib$(LANGUAGE_NAME).a
install -m755 lib$(LANGUAGE_NAME).$(SOEXT) '$(DESTDIR)$(LIBDIR)'/lib$(LANGUAGE_NAME).$(SOEXTVER)
ln -sf lib$(LANGUAGE_NAME).$(SOEXTVER) '$(DESTDIR)$(LIBDIR)'/lib$(LANGUAGE_NAME).$(SOEXTVER_MAJOR)
ln -sf lib$(LANGUAGE_NAME).$(SOEXTVER_MAJOR) '$(DESTDIR)$(LIBDIR)'/lib$(LANGUAGE_NAME).$(SOEXT)

uninstall:
$(RM) '$(DESTDIR)$(LIBDIR)'/lib$(LANGUAGE_NAME).a \
'$(DESTDIR)$(LIBDIR)'/lib$(LANGUAGE_NAME).$(SOEXTVER) \
'$(DESTDIR)$(LIBDIR)'/lib$(LANGUAGE_NAME).$(SOEXTVER_MAJOR) \
'$(DESTDIR)$(LIBDIR)'/lib$(LANGUAGE_NAME).$(SOEXT) \
'$(DESTDIR)$(INCLUDEDIR)'/tree_sitter/$(LANGUAGE_NAME).h \
'$(DESTDIR)$(PCLIBDIR)'/$(LANGUAGE_NAME).pc

clean:
$(RM) $(OBJS) $(LANGUAGE_NAME).pc lib$(LANGUAGE_NAME).a lib$(LANGUAGE_NAME).$(SOEXT)

test:
$(TS) test

.PHONY: all install uninstall clean test
47 changes: 47 additions & 0 deletions libs/tree-sitter-wing/Package.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
// swift-tools-version:5.3
import PackageDescription

let package = Package(
name: "TreeSitterWing",
products: [
.library(name: "TreeSitterWing", targets: ["TreeSitterWing"]),
],
dependencies: [],
targets: [
.target(name: "TreeSitterWing",
path: ".",
exclude: [
"Cargo.toml",
"Makefile",
"binding.gyp",
"bindings/c",
"bindings/go",
"bindings/node",
"bindings/python",
"bindings/rust",
"prebuilds",
"grammar.js",
"package.json",
"package-lock.json",
"pyproject.toml",
"setup.py",
"test",
"examples",
".editorconfig",
".github",
".gitignore",
".gitattributes",
".gitmodules",
],
sources: [
"src/parser.c",
"src/scanner.c",
],
resources: [
.copy("queries")
],
publicHeadersPath: "bindings/swift",
cSettings: [.headerSearchPath("src")])
],
cLanguageStandard: .c11
)
18 changes: 4 additions & 14 deletions libs/tree-sitter-wing/README.md
Original file line number Diff line number Diff line change
@@ -1,19 +1,9 @@
# tree-sitter-wing

TODO
A tree-sitter parser for the Wing language.

## Build
Wing is still heavily in development and this grammar/parser is experimental. It is used directly in the Wing compiler and is not considered a public API. It is available here for use but may have breaking changes at any time and no bindings are published or guaranteed to be work.

```sh
cargo build
```
## Contributing

## Test

```sh
cargo test
```

## License

Licensed under the MIT license.
Issues are tracked as part of the [Wing](https://github.com/winglang/wing) repository.
Loading

0 comments on commit 7277f30

Please sign in to comment.