Winglang

repository·main·Indexed 11 days ago

https://github.com/winglang/wing

A cloud-oriented programming language designed to unify infrastructure definition and application logic. Winglang treats cloud services as first-class citizens, providing a simulator for local testing and automatic generation of cloud mechanics like IAM policies. It includes a compiler, a cloud-agnostic SDK, and support for targets such as AWS CDK and Terraform.

Tokens
158.6K
Snippets
659
Records
857
Agent score
89%

What's inside Winglang

  1. What is Wing and how does it work?

    main

    Wing is a cloud-oriented programming language designed to treat the cloud as a single computer. Instead of managing individual machines, developers use high-level cloud primitives to build distributed systems.

    When you compile Wing code, the compiler generates two main components:

    1. Infrastructure Artifacts: (e.g., Terraform files) that define the required cloud resources.
    2. Runtime Code: (e.g., JavaScript) that runs on cloud compute resources.

    Key features include:

    • Cloud Portability: High-level primitives can target different cloud providers (e.g., mapping a cloud.Queue to Amazon SQS when targeting AWS).
    • Local Cloud Simulator: Allows for rapid iteration, end-to-end unit testing of architectures, and local debugging without deploying to a real cloud provider.
    • Wing Console: A visual management console used to interact with the local cloud simulator, view logs, and inspect resources.
    bring cloud;
    
    let queue = new cloud.Queue(timeout: 2m);
    let bucket = new cloud.Bucket();
    let counter = new cloud.Counter(initial: 100);
    
    queue.setConsumer(inflight (body: str) => {
      let next = counter.inc();
      let key = "myfile-{next}.txt";
      bucket.put(key, body);
    });
  2. What is wingii?

    main
    wingii is the Wing Interoperability Interface. It is a Rust crate designed to generate typed Rust structs from the latest JSII JsonSchema specification. Its primary purpose is to provide an API for interacting with JSII modules that are outside the reach of the Wing compiler. Currently, its functionality is limited to basic JSII reflection.
  3. Core features that make Wing suitable for cloud development

    main

    Wing is designed specifically for cloud application development through several key architectural features:

    • First-class Cloud Services: Cloud services are integrated into the language, utilizing preflight and inflight phase modifiers to distinguish between configuration-time and runtime settings.
    • Cloud Abstraction: A dedicated cloud library provides APIs that enable writing cloud-portable code.
    • Custom Platforms: Developers can define custom infrastructure and run policy checks via the Platforms concept.
    • Terraform Integration: Any resource within the Terraform ecosystem can be used as a first-class citizen in a Wing application.
    • Distributed Computing: Built-in primitives support distributed computing models (e.g., inflights).
    • Automated Cloud Mechanics: Wing automatically generates IAM policies and other necessary cloud configurations based on the developer's intent.
    • JavaScript Interoperability: Seamlessly interact with the JavaScript ecosystem.
    • Language Design: Features include native JSON support with schema validation, default immutability, and an implicit asynchronous model with explicit defer.
  4. Features of Wing for VSCode

    main

    The Wing VSCode extension provides the following development features:

    • Syntax highlighting: Visual coloring of Wing code.
    • Compiler diagnostics: Real-time error and warning reporting.
    • Code completion: Intelligent suggestions while typing.
    • Snippets: Reusable code templates.
    • Hover information: View types and documentation by hovering over symbols.
    • Embedded Wing Console: Integrated access to the Wing Console tool.
  5. Key features of Winglang

    main

    Winglang is designed specifically for cloud-oriented development with the following core features:

    • Cloud Services as First-Class Citizens: Use preflight and inflight phase modifiers to describe infrastructure and runtime code.
    • Wing Cloud Library: A standard set of portable cloud resources.
    • Automatic IAM Generation: Wing automatically generates IAM policies and other cloud mechanics based on your source code.
    • JavaScript Interoperability: Seamlessly use JavaScript within your Wing programs.
    • Local Simulator: Test and debug your distributed systems locally in milliseconds without needing an internet connection.
    • JSON Support: JSON is a primitive data type with built-in schema validation for conversions to/from structs.
    • Safety Features: Immutability by default, implicit async code, and safety from null and undefined via optionality.
  6. Understand the structure of the Wing SDK

    main

    The Wing SDK is organized into several functional modules that separate abstract cloud resource definitions from their specific infrastructure provider implementations.

    • cloud: Contains the abstract APIs for Wing's built-in resources. These are the primary interfaces used by developers via the bring cloud statement.
    • std: Provides APIs for built-in types such as Array, str, and others.
    • util: Contains utility functions available to developers via the bring util statement.
    • core: Contains the underlying logic for application construction, preflight-to-inflight code translation, and plugin APIs.
    • target-* modules: These contain the actual implementations of the cloud module resources for specific deployment targets (e.g., target-awscdk for AWS CDK, target-tf-aws for Terraform AWS, target-sim for simulation, etc.).
    • .gen: Contains generated code for CDKTF classes used to synthesize Terraform resource configurations.
  7. Understanding the problems Wing solves

    main

    Wing is designed to address specific friction points in cloud development by treating the cloud as a target computer, similar to how a compiler treats hardware.

    For Developers

    • Faster Iteration: Reduces long deployment times and improves testing/debugging workflows to maintain creative flow.
    • Tooling Consolidation: Replaces fragmented tools with a unified approach to cloud development.
    • Local Development: Provides solutions for full simulation, visualization, and fast reloading in local environments.
    • Abstraction of Cloud Mechanics: Reduces the need for developers to manually manage low-level details like IAM policies and networking, allowing them to focus on business logic.

    For Organizations

    • Reduced Dev/Ops Friction: Minimizes the interdependence and miscommunication between development and operations teams by synchronizing workflows.
    • Automated Security and Observability: Reduces errors caused by manually writing IAM policies and observability dashboards by integrating them into the development process.
    • Multi-cloud and Vendor Flexibility: Helps mitigate cloud vendor lock-in and supports the requirement to deploy across multiple cloud providers.

    To see these concepts in action, you can use the Wing Playground.

  8. What is the Wing SDK and how does it work?

    main

    The Wing SDK is a cloud-agnostic library containing core cloud resources.

    Key Concepts:

    • Cloud Agnostic: Resources like cloud.Queue or cloud.Bucket are polymorphic. They represent a concept rather than a specific implementation.
    • Target Determination: The actual provider (AWS, local simulator, etc.) is determined at synth time by selecting a target or a synthesizer.
    • The sim Target: One supported target is sim, which allows you to run cloud applications locally without an internet connection. This is useful for fast iteration and testing cloud resources without mocks.
  9. What is the Wing Simulator?

    main

    The simulator is a built-in platform provider included in Wing that allows you to execute Wing applications locally on your machine for development and testing. It does not require deployment to any cloud providers.

    While it does not provide the same guarantees as a real cloud provider, it is useful for:

    • Running inflight unit tests using the wing test command.
    • Interacting with the simulated application through the Wing Console.
    • Programmatic interaction via the @winglang/sdk npm package (experimental).
  10. How to use sim.State for lazy simulator values

    main

    The sim.State is an in-memory key/value store used in the Wing simulator to handle attributes that are only known during service initialization (e.g., a container's exposed port).

    It works using a two-step process:

    1. Preflight: Use state.token(key) to obtain a token. This token can be assigned to properties or passed to other resources. It acts as a placeholder that represents the value to be resolved later.
    2. Inflight: During simulator app initialization (e.g., inside cloud.OnDeploy or cloud.Service startup), call state.set(key, value) to assign the actual runtime value.

    When a resource uses a token, the Wing compiler creates an implicit dependency. The dependent resource will only be initialized once the state key has been set.

    bring cloud;
    bring sim;
    
    class MyService {
      startTime: str;
    
      new() {
        let state = new sim.State();
    
        new cloud.Service(inflight () => {
          state.set("start", std.Datetime.utcNow().toIso());
        });
    
        this.startTime = state.token("start");
      }
    }
    
    let s = new MyService();
    
    new cloud.Function(inflight () => {
      log("service start time is {s}");
    });