Skip to content

Commit

Permalink
Seed edition feature defaults (#619)
Browse files Browse the repository at this point in the history
  • Loading branch information
timostamm authored Nov 17, 2023
1 parent 9777c0b commit 4bf739e
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 12 deletions.
13 changes: 7 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,10 @@ help: ## Describe useful make targets
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "%-30s %s\n", $$1, $$2}'

.PHONY: all
all: build test format lint bench bootstrapwkt ## build, test, format, lint, bench, and bootstrapwkt (default)
all: build test format lint bench bootstrap ## build, test, format, lint, bench, and bootstrap (default)

.PHONY: ci
ci: build test-protobuf test-protoplugin test-conformance format lint bench bootstrapwkt #
ci: build test-protobuf test-protoplugin test-conformance format lint bench bootstrap #
$(MAKE) checkdiff

.PHONY: clean
Expand Down Expand Up @@ -155,11 +155,12 @@ bench: node_modules $(GEN)/protobuf-bench $(BUILD)/protobuf ## Benchmark code si
perf: $(BUILD)/protobuf-test
npm run -w packages/protobuf-test perf

.PHONY: bootstrapwkt
bootstrapwkt: $(BUILD)/upstream-protobuf $(BUILD)/protoc-gen-es node_modules ## Generate the well-known types in @bufbuild/protobuf
npm run -w packages/protobuf bootstrap
.PHONY: bootstrap
bootstrap: $(BUILD)/upstream-protobuf $(BUILD)/protoc-gen-es node_modules ## Bootstrap well-known types and edition features-set defaults in @bufbuild/protobuf from upstream protobuf
npm run -w packages/protobuf bootstrap:wkt
npm run -w packages/protobuf bootstrap:featureset-defaults
@# If the generated code differs, use it, and run tests again
npm run -w packages/protobuf bootstrap-diff || $(MAKE) build test format lint
#npm run -w packages/protobuf bootstrap-diff || $(MAKE) build test format lint

.PHONY: setversion
setversion: ## Set a new version in for the project, i.e. make setversion SET_VERSION=1.2.3
Expand Down
8 changes: 4 additions & 4 deletions packages/protobuf/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@
"build:cjs": "../../node_modules/typescript/bin/tsc --project tsconfig.json --module commonjs --outDir ./dist/cjs --declaration --declarationDir ./dist/cjs && echo >./dist/cjs/package.json '{\"type\":\"commonjs\"}'",
"build:esm": "../../node_modules/typescript/bin/tsc --project tsconfig.json --module ES2015 --verbatimModuleSyntax --outDir ./dist/esm --declaration --declarationDir ./dist/esm",
"build:proxy": "node ../../scripts/gen-esm-proxy.mjs .",
"prebootstrap": "rm -rf .tmp && mkdir -p .tmp/google/protobuf && cp -rp src/google/protobuf/* .tmp/google/protobuf",
"bootstrap": "protoc --es_out=src --es_opt=bootstrap_wkt=true,ts_nocheck=false,target=ts --proto_path $(upstream-include wkt) $(upstream-files wkt)",
"postbootstrap": "license-header src/google/protobuf",
"bootstrap-diff": "diff >/dev/null -r .tmp/google/protobuf src/google/protobuf && cp -rp .tmp/google/protobuf/* src/google/protobuf",
"bootstrap:featureset-defaults": "upstream-inject-feature-defaults src/private/feature-set-defaults.ts",
"prebootstrap:wkt": "rm -rf .tmp && mkdir -p .tmp/google/protobuf && cp -rp src/google/protobuf/* .tmp/google/protobuf",
"bootstrap:wkt": "protoc --es_out=src --es_opt=bootstrap_wkt=true,ts_nocheck=false,target=ts --proto_path $(upstream-include wkt) $(upstream-files wkt) && license-header src/google/protobuf",
"postbootstrap:wkt": "diff >/dev/null -r .tmp/google/protobuf src/google/protobuf && cp -rp .tmp/google/protobuf/* src/google/protobuf || true",
"attw": "attw --pack"
},
"type": "module",
Expand Down
22 changes: 22 additions & 0 deletions packages/protobuf/src/private/feature-set-defaults.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// Copyright 2021-2023 Buf Technologies, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

import { FeatureSetDefaults } from "../google/protobuf/descriptor_pb.js";
import { protoBase64 } from "../proto-base64.js";

export const featureSetDefaults = FeatureSetDefaults.fromBinary(
protoBase64.dec(
/*upstream-inject-feature-defaults-start*/"ChESDAgBEAIYAiABKAEwAhjmBwoREgwIAhABGAEgAigBMAEY5wcKERIMCAEQARgBIAIoATABGOgHIOYHKOgH"/*upstream-inject-feature-defaults-end*/,
),
);
6 changes: 5 additions & 1 deletion packages/protobuf/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
{
"files": ["src/index.ts", "src/private/options-map.ts"],
"files": [
"src/index.ts",
"src/private/options-map.ts", // not yet exported, added here to satisfy the linter
"src/private/feature-set-defaults.ts" // not yet exported, added here to satisfy the linter
],
"extends": "../../tsconfig.base.json",
"compilerOptions": {
"lib": [
Expand Down
5 changes: 4 additions & 1 deletion packages/upstream-protobuf/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,7 @@ and feature-set defaults for editions via npm "binaries", and via an exported
class.

To update this project to use a new version, update the version number in
version.txt and run `make`.
version.txt and run `make bootstrap`. This will re-generate the well-known types
from the upstream definitions, and seed the edition feature-set defaults. As a
result, `@bufbuild/protobuf` may be modified. Run `make` to run all tests with
the updated code.

0 comments on commit 4bf739e

Please sign in to comment.