google / cql

An experimental Clinical Quality Language execution engine for analyzing FHIR healthcare data at scale.
Apache License 2.0
57 stars 6 forks source link

Explore WebAssembly Build (WASM) #38

Open suyashkumar opened 1 month ago

suyashkumar commented 1 month ago

Overview

The Go tool is able to build WebAsssembly binaries which can be run inside browsers. This capability may allow our CQL evaluation library to run locally within a browser (and rely on static serving instead of a custom server like cqlplay currently does).

That said, complex programs seem to run into various issues compiling to WebAssembly. This issue will be a lower-priority tracker for explorations on this front. Help is welcome!

Progress

Blindly trying to build the CLI with a WASM target results in the following errors:

@suyashkumar ➜ /workspaces/cql/cmd/cli (main) $  GOOS=js GOARCH=wasm go1.21.11 build -o main.wasm
# github.com/google/cql/cmd/cli
type:*github.com/google/fhir/go/jsonformat/internal/protopath.Path: non-pc-relative relocation address for github.com/google/fhir/go/jsonformat/internal/protopath.(*Path).Append is too big: 0x12c360000
type:*github.com/google/fhir/go/jsonformat/internal/protopath.Path: non-pc-relative relocation address for github.com/google/fhir/go/jsonformat/internal/protopath.(*Path).Append is too big: 0x12c360000
type:*github.com/google/fhir/go/jsonformat/internal/protopath.Path: non-pc-relative relocation address for github.com/google/fhir/go/jsonformat/internal/protopath.(*Path).IsValid is too big: 0x12c370000
type:*github.com/google/fhir/go/jsonformat/internal/protopath.Path: non-pc-relative relocation address for github.com/google/fhir/go/jsonformat/internal/protopath.(*Path).IsValid is too big: 0x12c370000
type:*github.com/google/fhir/go/jsonformat/internal/protopath.Path: non-pc-relative relocation address for github.com/google/fhir/go/jsonformat/internal/protopath.(*Path).Parent is too big: 0x12c380000
type:*github.com/google/fhir/go/jsonformat/internal/protopath.Path: non-pc-relative relocation address for github.com/google/fhir/go/jsonformat/internal/protopath.(*Path).Parent is too big: 0x12c380000
type:*github.com/google/fhir/go/jsonformat/internal/protopath.Path: non-pc-relative relocation address for github.com/google/fhir/go/jsonformat/internal/protopath.(*Path).String is too big: 0x12c390000
type:*github.com/google/fhir/go/jsonformat/internal/protopath.Path: non-pc-relative relocation address for github.com/google/fhir/go/jsonformat/internal/protopath.(*Path).String is too big: 0x12c390000
type:*github.com/google/cql/retriever/local.Retriever: non-pc-relative relocation address for github.com/google/cql/retriever/local.(*Retriever).Retrieve is too big: 0x12cb40000
type:*github.com/google/cql/retriever/local.Retriever: non-pc-relative relocation address for github.com/google/cql/retriever/local.(*Retriever).Retrieve is too big: 0x12cb40000
type:*github.com/google/fhir/go/jsonformat/internal/jsonpbhelper.UnmarshalErrorList: non-pc-relative relocation address for github.com/google/fhir/go/jsonformat/internal/jsonpbhelper.(*UnmarshalErrorList).Error is too big: 0x12c210000
type:*github.com/google/fhir/go/jsonformat/internal/jsonpbhelper.UnmarshalErrorList: non-pc-relative relocation address for github.com/google/fhir/go/jsonformat/internal/jsonpbhelper.(*UnmarshalErrorList).Error is too big: 0x12c210000
type:github.com/google/fhir/go/jsonformat/internal/jsonpbhelper.UnmarshalErrorList: non-pc-relative relocation address for github.com/google/fhir/go/jsonformat/internal/jsonpbhelper.(*UnmarshalErrorList).Error is too big: 0x12c210000
type:github.com/google/fhir/go/jsonformat/internal/jsonpbhelper.UnmarshalErrorList: non-pc-relative relocation address for github.com/google/fhir/go/jsonformat/internal/jsonpbhelper.UnmarshalErrorList.Error is too big: 0x12c020000
type:*github.com/google/fhir/go/proto/google/fhir/proto/stu3/metadatatypes_go_proto.DataRequirement_CodeFilter_ValueSet: non-pc-relative relocation address for github.com/google/fhir/go/proto/google/fhir/proto/stu3/metadatatypes_go_proto.(*DataRequirement_CodeFilter_ValueSet).Descriptor is too big: 0x1068d0000
type:*github.com/google/fhir/go/proto/google/fhir/proto/stu3/metadatatypes_go_proto.DataRequirement_CodeFilter_ValueSet: non-pc-relative relocation address for github.com/google/fhir/go/proto/google/fhir/proto/stu3/metadatatypes_go_proto.(*DataRequirement_CodeFilter_ValueSet).Descriptor is too big: 0x1068d0000
type:*github.com/google/fhir/go/proto/google/fhir/proto/stu3/metadatatypes_go_proto.DataRequirement_CodeFilter_ValueSet: non-pc-relative relocation address for github.com/google/fhir/go/proto/google/fhir/proto/stu3/metadatatypes_go_proto.(*DataRequirement_CodeFilter_ValueSet).GetReference is too big: 0x106900000
type:*github.com/google/fhir/go/proto/google/fhir/proto/stu3/metadatatypes_go_proto.DataRequirement_CodeFilter_ValueSet: non-pc-relative relocation address for github.com/google/fhir/go/proto/google/fhir/proto/stu3/metadatatypes_go_proto.(*DataRequirement_CodeFilter_ValueSet).GetReference is too big: 0x106900000
type:*github.com/google/fhir/go/proto/google/fhir/proto/stu3/metadatatypes_go_proto.DataRequirement_CodeFilter_ValueSet: non-pc-relative relocation address for github.com/google/fhir/go/proto/google/fhir/proto/stu3/metadatatypes_go_proto.(*DataRequirement_CodeFilter_ValueSet).GetStringValue is too big: 0x1068f0000
type:*github.com/google/fhir/go/proto/google/fhir/proto/stu3/metadatatypes_go_proto.DataRequirement_CodeFilter_ValueSet: non-pc-relative relocation address for github.com/google/fhir/go/proto/google/fhir/proto/stu3/metadatatypes_go_proto.(*DataRequirement_CodeFilter_ValueSet).GetStringValue is too big: 0x1068f0000
type:*github.com/google/fhir/go/proto/google/fhir/proto/stu3/metadatatypes_go_proto.DataRequirement_CodeFilter_ValueSet: non-pc-relative relocation address for github.com/google/fhir/go/proto/google/fhir/proto/stu3/metadatatypes_go_proto.(*DataRequirement_CodeFilter_ValueSet).GetValueSet is too big: 0x1068e0000
/home/codespace/sdk/go1.21.11/pkg/tool/linux_amd64/link: too many errors
type:*github.com/google/fhir/go/proto/google/fhir/proto/stu3/resources_go_proto.ClaimResponse_AddedItem: non-pc-relative relocation address for github.com/google/fhir/go/proto/google/fhir/proto/stu3/resources_go_proto.(*ClaimResponse_AddedItem).Descriptor is too big: 0x118a50000
/home/codespace/sdk/go1.21.11/pkg/tool/linux_amd64/link: too many errors

Both go1.21.11 and go1.22.3 returned similar errors. I think this issue is related: https://github.com/golang/go/issues/64856 and indicated go1.21 worked for their build, so I tried that to no avail. Need to look more into the issue details to see what might be going on.

At a high-level, many of these seem to be problems related to FHIR proto libraries and the protos themselves, which doesn't surprise me.